1 package sun.reflect.generics.reflectiveObjects;
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;
15 * MJI model class for sun.reflect.generics.reflectiveObjects.TypeVariableImple
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).
22 * Note that this class never gets seen by the real VM - it's for JPF's eyes only.
24 * For now this only supports a few basic methods.
26 public class TypeVariableImpl<D extends GenericDeclaration>
27 extends LazyReflectiveObjectGenerator implements TypeVariable<D> {
28 //public class TypeVariableImpl {
31 private Type[] bounds;
32 private FieldTypeSignature[] boundASTs;
33 //private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
35 // constructor is private to enforce access through static factory
36 private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
39 genericDeclaration = decl;
45 private FieldTypeSignature[] getBoundASTs() {
46 throw new UnsupportedOperationException();
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
61 public static <T extends GenericDeclaration>
62 TypeVariableImpl<T> make(T decl, String name,
63 FieldTypeSignature[] bs,
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());
72 return new TypeVariableImpl<T>(decl, name, bs, f);
76 public Type[] getBounds() {
77 throw new UnsupportedOperationException();
80 public D getGenericDeclaration(){
81 throw new UnsupportedOperationException();
86 * Returns the name of this type variable, as it occurs in the source code.
88 * @return the name of this type variable, as it appears in the source code
90 public String getName() { return name; }
92 public String toString() {return getName();}
95 public boolean equals(Object o) {
96 if (o instanceof TypeVariable &&
97 o.getClass() == TypeVariableImpl.class) {
98 TypeVariable<?> that = (TypeVariable<?>) o;
100 GenericDeclaration thatDecl = that.getGenericDeclaration();
101 String thatName = that.getName();
103 return Objects.equals(genericDeclaration, thatDecl) &&
104 Objects.equals(name, thatName);
111 public int hashCode() {
112 return genericDeclaration.hashCode() ^ name.hashCode();
115 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
116 throw new UnsupportedOperationException();
119 public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
120 throw new UnsupportedOperationException();
124 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
125 throw new UnsupportedOperationException();
129 public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
130 throw new UnsupportedOperationException();
133 public Annotation[] getAnnotations() {
134 throw new UnsupportedOperationException();
137 public Annotation[] getDeclaredAnnotations() {
138 throw new UnsupportedOperationException();
141 public AnnotatedType[] getAnnotatedBounds() {
142 throw new UnsupportedOperationException();