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> {
30 private Type[] bounds;
31 private FieldTypeSignature[] boundASTs;
32 private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
34 // constructor is private to enforce access through static factory
35 private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
38 genericDeclaration = decl;
44 private FieldTypeSignature[] getBoundASTs() {
45 throw new UnsupportedOperationException();
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
60 public static <T extends GenericDeclaration>
61 TypeVariableImpl<T> make(T decl, String name,
62 FieldTypeSignature[] bs,
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());
71 return new TypeVariableImpl<T>(decl, name, bs, f);
75 public Type[] getBounds() {
76 throw new UnsupportedOperationException();
79 public D getGenericDeclaration(){
80 throw new UnsupportedOperationException();
85 * Returns the name of this type variable, as it occurs in the source code.
87 * @return the name of this type variable, as it appears in the source code
89 public String getName() { return name; }
91 public String toString() {return getName();}
94 public boolean equals(Object o) {
95 if (o instanceof TypeVariable &&
96 o.getClass() == TypeVariableImpl.class) {
97 TypeVariable<?> that = (TypeVariable<?>) o;
99 GenericDeclaration thatDecl = that.getGenericDeclaration();
100 String thatName = that.getName();
102 return Objects.equals(genericDeclaration, thatDecl) &&
103 Objects.equals(name, thatName);
110 public int hashCode() {
111 return genericDeclaration.hashCode() ^ name.hashCode();
114 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
115 throw new UnsupportedOperationException();
118 public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
119 throw new UnsupportedOperationException();
123 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
124 throw new UnsupportedOperationException();
128 public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
129 throw new UnsupportedOperationException();
132 public Annotation[] getAnnotations() {
133 throw new UnsupportedOperationException();
136 public Annotation[] getDeclaredAnnotations() {
137 throw new UnsupportedOperationException();
140 public AnnotatedType[] getAnnotatedBounds() {
141 throw new UnsupportedOperationException();