View Javadoc
1   package net.florianschoppmann.java.reflect;
2   
3   import javax.annotation.Nullable;
4   import javax.lang.model.type.ArrayType;
5   import javax.lang.model.type.TypeKind;
6   import javax.lang.model.type.TypeVisitor;
7   import java.util.Objects;
8   
9   final class ArrayTypeImpl extends AnnotatedConstructImpl implements ReflectionTypeMirror, ArrayType {
10      private final ReflectionTypeMirror componentType;
11  
12      ArrayTypeImpl(ReflectionTypeMirror componentType) {
13          Objects.requireNonNull(componentType);
14  
15          this.componentType = componentType;
16      }
17  
18      @Override
19      public boolean equals(@Nullable Object otherObject) {
20          if (this == otherObject) {
21              return true;
22          } else if (otherObject == null || getClass() != otherObject.getClass()) {
23              return false;
24          }
25  
26          return componentType.equals(((ArrayTypeImpl) otherObject).componentType);
27      }
28  
29      @Override
30      public int hashCode() {
31          // Do not return just componentType.hashCode() because both this instance and componentType are of type
32          // ReflectionTypeMirror.
33          return Objects.hash(getClass(), componentType.hashCode());
34      }
35  
36      @Override
37      public String toString() {
38          return ReflectionTypes.getInstance().toString(this);
39      }
40  
41      @Override
42      public <R, P> R accept(TypeVisitor<R, P> visitor, @Nullable P parameter) {
43          return visitor.visitArray(this, parameter);
44      }
45  
46      @Override
47      public ReflectionTypeMirror getComponentType() {
48          return componentType;
49      }
50  
51      @Override
52      public TypeKind getKind() {
53          return TypeKind.ARRAY;
54      }
55  }