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> {
32 // constructor is private to enforce access through static factory
33 private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs,
36 genericDeclaration = decl;
41 private FieldTypeSignature[] getBoundASTs() {
42 throw new UnsupportedOperationException();
47 * @param decl - the reflective object that declared the type variable
48 * that this method should create
49 * @param name - the name of the type variable to be returned
50 * @param bs - an array of ASTs representing the bounds for the type
51 * variable to be created
52 * @param f - a factory that can be used to manufacture reflective
53 * objects that represent the bounds of this type variable
54 * @return A type variable with name, bounds, declaration and factory
57 public static <T extends GenericDeclaration>
58 TypeVariableImpl<T> make(T decl, String name,
59 FieldTypeSignature[] bs,
62 if (!((decl instanceof Class) ||
63 //(decl instanceof Method) ||
64 (decl instanceof Constructor))) {
65 throw new AssertionError("Unexpected kind of GenericDeclaration" +
66 decl.getClass().toString());
68 return new TypeVariableImpl<T>(decl, name, bs, f);
72 public Type[] getBounds() {
73 throw new UnsupportedOperationException();
76 public D getGenericDeclaration(){
77 throw new UnsupportedOperationException();
82 * Returns the name of this type variable, as it occurs in the source code.
84 * @return the name of this type variable, as it appears in the source code
86 public String getName() { return name; }
88 public String toString() {return getName();}
91 public boolean equals(Object o) {
92 if (o instanceof TypeVariable &&
93 o.getClass() == TypeVariableImpl.class) {
94 TypeVariable<?> that = (TypeVariable<?>) o;
96 GenericDeclaration thatDecl = that.getGenericDeclaration();
97 String thatName = that.getName();
99 return Objects.equals(genericDeclaration, thatDecl) &&
100 Objects.equals(name, thatName);
107 public int hashCode() {
108 return genericDeclaration.hashCode() ^ name.hashCode();
111 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
112 throw new UnsupportedOperationException();
115 public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
116 throw new UnsupportedOperationException();
120 public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
121 throw new UnsupportedOperationException();
125 public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
126 throw new UnsupportedOperationException();
129 public Annotation[] getAnnotations() {
130 throw new UnsupportedOperationException();
133 public Annotation[] getDeclaredAnnotations() {
134 throw new UnsupportedOperationException();
137 public AnnotatedType[] getAnnotatedBounds() {
138 throw new UnsupportedOperationException();