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