fcb0521e2c8bb6436c9599cb154de9a8ecf57153
[jpf-core.git] / src / classes / sun / reflect / generics / reflectiveObjects / TypeVariableImpl.java
1 package sun.reflect.generics.reflectiveObjects;
2
3 import java.lang.annotation.*;
4 import java.lang.reflect.AnnotatedType;
5 import java.lang.reflect.Constructor;
6 import java.lang.reflect.GenericDeclaration;
7 import java.lang.reflect.Method;
8 import java.lang.reflect.Type;
9 import java.lang.reflect.TypeVariable;
10 import java.util.Objects;
11 import sun.reflect.generics.factory.GenericsFactory;
12 import sun.reflect.generics.tree.FieldTypeSignature;
13
14 /**
15  * MJI model class for sun.reflect.generics.reflectiveObjects.TypeVariableImpl
16  *
17  * This is a JPF specific version of a system class because we can't use the real,
18  * platform VM specific version (it's native all over the place, its field
19  * structure isn't documented, most of its methods are private, hence we can't
20  * even instantiate it properly).
21  *
22  * Note that this class never gets seen by the real VM - it's for JPF's eyes only.
23  *
24  * For now this only supports a few basic methods.
25  */
26 public class TypeVariableImpl<D extends GenericDeclaration>
27     extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
28
29     D genericDeclaration;
30     private String name;
31
32     // constructor is private to enforce access through static factory
33     private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
34                              GenericsFactory f) {
35         super(f);
36         genericDeclaration = decl;
37         name = n;
38     }
39
40     // Accessors
41     private FieldTypeSignature[] getBoundASTs() {
42         throw new UnsupportedOperationException();
43     }
44
45     /**
46      * Factory method.
47      */
48     public static <T extends GenericDeclaration>
49                              TypeVariableImpl<T> make(T decl, String name,
50                                                       FieldTypeSignature[] bs,
51                                                       GenericsFactory f) {
52
53         if (!((decl instanceof Class) ||
54                 //(decl instanceof Method) ||
55                 (decl instanceof Constructor))) {
56             throw new AssertionError("Unexpected kind of GenericDeclaration" +
57                     decl.getClass().toString());
58         }
59         return new TypeVariableImpl<T>(decl, name, bs, f);
60     }
61
62
63     public Type[] getBounds() {
64         throw new UnsupportedOperationException();
65     }
66
67     public D getGenericDeclaration(){
68         throw new UnsupportedOperationException();
69     }
70
71     public String getName()   { return name; }
72
73     public String toString() {return getName();}
74
75     @Override
76     public boolean equals(Object o) {
77         if (o instanceof TypeVariable &&
78                 o.getClass() == TypeVariableImpl.class) {
79             TypeVariable<?> that = (TypeVariable<?>) o;
80
81             GenericDeclaration thatDecl = that.getGenericDeclaration();
82             String thatName = that.getName();
83
84             return Objects.equals(genericDeclaration, thatDecl) &&
85                 Objects.equals(name, thatName);
86
87         } else
88             return false;
89     }
90
91     @Override
92     public int hashCode() {
93         return genericDeclaration.hashCode() ^ name.hashCode();
94     }
95
96     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
97         throw new UnsupportedOperationException();
98     }
99
100     public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
101         throw new UnsupportedOperationException();
102     }
103
104     @Override
105     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
106         throw new UnsupportedOperationException();
107     }
108
109     @Override
110     public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
111         throw new UnsupportedOperationException();
112     }
113
114     public Annotation[] getAnnotations() {
115         throw new UnsupportedOperationException();
116     }
117
118     public Annotation[] getDeclaredAnnotations() {
119         throw new UnsupportedOperationException();
120     }
121
122     public AnnotatedType[] getAnnotatedBounds() {
123         throw new UnsupportedOperationException();
124     }
125
126 }