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