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