c77a3a516323003565c5b07e88c8a9594c372d62
[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     public Type[] getBounds() {
63
64         throw new UnsupportedOperationException();
65         //return new Type[0];
66     }
67
68     public D getGenericDeclaration(){
69         throw new UnsupportedOperationException();
70     }
71
72     public String getName()   { return name; }
73
74     public String toString() {return getName();}
75
76     @Override
77     public boolean equals(Object o) {
78         if (o instanceof TypeVariable &&
79                 o.getClass() == TypeVariableImpl.class) {
80             TypeVariable<?> that = (TypeVariable<?>) o;
81
82             GenericDeclaration thatDecl = that.getGenericDeclaration();
83             String thatName = that.getName();
84
85             return Objects.equals(genericDeclaration, thatDecl) &&
86                 Objects.equals(name, thatName);
87
88         } else
89             return false;
90     }
91
92     @Override
93     public int hashCode() {
94         return genericDeclaration.hashCode() ^ name.hashCode();
95     }
96
97     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
98         throw new UnsupportedOperationException();
99     }
100
101     public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
102         throw new UnsupportedOperationException();
103     }
104
105     @Override
106     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
107         throw new UnsupportedOperationException();
108     }
109
110     @Override
111     public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
112         throw new UnsupportedOperationException();
113     }
114
115     public Annotation[] getAnnotations() {
116         throw new UnsupportedOperationException();
117     }
118
119     public Annotation[] getDeclaredAnnotations() {
120         throw new UnsupportedOperationException();
121     }
122
123     public AnnotatedType[] getAnnotatedBounds() {
124         throw new UnsupportedOperationException();
125     }
126
127 }