50392ca4793b2b3adba13cdd5c3d327b0e80898a
[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.TypeVariableImple
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      * @param decl - the reflective object that declared the type variable
48      * that this method should create
49      * @param name - the name of the type variable to be returned
50      * @param bs - an array of ASTs representing the bounds for the type
51      * variable to be created
52      * @param f - a factory that can be used to manufacture reflective
53      * objects that represent the bounds of this type variable
54      * @return A type variable with name, bounds, declaration and factory
55      * specified
56      */
57     public static <T extends GenericDeclaration>
58                              TypeVariableImpl<T> make(T decl, String name,
59                                                       FieldTypeSignature[] bs,
60                                                       GenericsFactory f) {
61
62         if (!((decl instanceof Class) ||
63                 //(decl instanceof Method) ||
64                 (decl instanceof Constructor))) {
65             throw new AssertionError("Unexpected kind of GenericDeclaration" +
66                     decl.getClass().toString());
67         }
68         return new TypeVariableImpl<T>(decl, name, bs, f);
69     }
70
71
72     public Type[] getBounds() {
73         throw new UnsupportedOperationException();
74     }
75
76     public D getGenericDeclaration(){
77         throw new UnsupportedOperationException();
78     }
79
80
81     /**
82      * Returns the name of this type variable, as it occurs in the source code.
83      *
84      * @return the name of this type variable, as it appears in the source code
85      */
86     public String getName()   { return name; }
87
88     public String toString() {return getName();}
89
90     @Override
91     public boolean equals(Object o) {
92         if (o instanceof TypeVariable &&
93                 o.getClass() == TypeVariableImpl.class) {
94             TypeVariable<?> that = (TypeVariable<?>) o;
95
96             GenericDeclaration thatDecl = that.getGenericDeclaration();
97             String thatName = that.getName();
98
99             return Objects.equals(genericDeclaration, thatDecl) &&
100                 Objects.equals(name, thatName);
101
102         } else
103             return false;
104     }
105
106     @Override
107     public int hashCode() {
108         return genericDeclaration.hashCode() ^ name.hashCode();
109     }
110
111     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
112         throw new UnsupportedOperationException();
113     }
114
115     public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
116         throw new UnsupportedOperationException();
117     }
118
119     @Override
120     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
121         throw new UnsupportedOperationException();
122     }
123
124     @Override
125     public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
126         throw new UnsupportedOperationException();
127     }
128
129     public Annotation[] getAnnotations() {
130         throw new UnsupportedOperationException();
131     }
132
133     public Annotation[] getDeclaredAnnotations() {
134         throw new UnsupportedOperationException();
135     }
136
137     public AnnotatedType[] getAnnotatedBounds() {
138         throw new UnsupportedOperationException();
139     }
140
141 }