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