From: rtrimana Date: Mon, 17 Jun 2019 18:50:27 +0000 (-0700) Subject: Adding the TypeVariableImpl.java class for generics; minimum implementation for now. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=jpf-core.git;a=commitdiff_plain;h=438676bb7cf5351a272696fd152c7f222a1b76fd Adding the TypeVariableImpl.java class for generics; minimum implementation for now. --- diff --git a/src/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java b/src/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java new file mode 100644 index 0000000..bb1a3d3 --- /dev/null +++ b/src/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java @@ -0,0 +1,144 @@ +package sun.reflect.generics.reflectiveObjects; + +import java.lang.annotation.*; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Constructor; +import java.lang.reflect.GenericDeclaration; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.lang.reflect.TypeVariable; +import java.util.Objects; +import sun.reflect.generics.factory.GenericsFactory; +import sun.reflect.generics.tree.FieldTypeSignature; + +/** + * MJI model class for sun.reflect.generics.reflectiveObjects.TypeVariableImple + * + * This is a JPF specific version of a system class because we can't use the real, + * platform VM specific version (it's native all over the place, its field + * structure isn't documented, most of its methods are private, hence we can't + * even instantiate it properly). + * + * Note that this class never gets seen by the real VM - it's for JPF's eyes only. + * + * For now this only supports a few basic methods. + */ +public class TypeVariableImpl + extends LazyReflectiveObjectGenerator implements TypeVariable { + D genericDeclaration; + private String name; + private Type[] bounds; + private FieldTypeSignature[] boundASTs; + private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; + + // constructor is private to enforce access through static factory + private TypeVariableImpl(D decl, String n, FieldTypeSignature[] bs, + GenericsFactory f) { + super(f); + genericDeclaration = decl; + name = n; + boundASTs = bs; + } + + // Accessors + private FieldTypeSignature[] getBoundASTs() { + throw new UnsupportedOperationException(); + } + + /** + * Factory method. + * @param decl - the reflective object that declared the type variable + * that this method should create + * @param name - the name of the type variable to be returned + * @param bs - an array of ASTs representing the bounds for the type + * variable to be created + * @param f - a factory that can be used to manufacture reflective + * objects that represent the bounds of this type variable + * @return A type variable with name, bounds, declaration and factory + * specified + */ + public static + TypeVariableImpl make(T decl, String name, + FieldTypeSignature[] bs, + GenericsFactory f) { + + if (!((decl instanceof Class) || + (decl instanceof Method) || + (decl instanceof Constructor))) { + throw new AssertionError("Unexpected kind of GenericDeclaration" + + decl.getClass().toString()); + } + return new TypeVariableImpl(decl, name, bs, f); + } + + + public Type[] getBounds() { + throw new UnsupportedOperationException(); + } + + public D getGenericDeclaration(){ + throw new UnsupportedOperationException(); + } + + + /** + * Returns the name of this type variable, as it occurs in the source code. + * + * @return the name of this type variable, as it appears in the source code + */ + public String getName() { return name; } + + public String toString() {return getName();} + + @Override + public boolean equals(Object o) { + if (o instanceof TypeVariable && + o.getClass() == TypeVariableImpl.class) { + TypeVariable that = (TypeVariable) o; + + GenericDeclaration thatDecl = that.getGenericDeclaration(); + String thatName = that.getName(); + + return Objects.equals(genericDeclaration, thatDecl) && + Objects.equals(name, thatName); + + } else + return false; + } + + @Override + public int hashCode() { + return genericDeclaration.hashCode() ^ name.hashCode(); + } + + public T getAnnotation(Class annotationClass) { + throw new UnsupportedOperationException(); + } + + public T getDeclaredAnnotation(Class annotationClass) { + throw new UnsupportedOperationException(); + } + + @Override + public T[] getAnnotationsByType(Class annotationClass) { + throw new UnsupportedOperationException(); + } + + @Override + public T[] getDeclaredAnnotationsByType(Class annotationClass) { + throw new UnsupportedOperationException(); + } + + public Annotation[] getAnnotations() { + throw new UnsupportedOperationException(); + } + + public Annotation[] getDeclaredAnnotations() { + throw new UnsupportedOperationException(); + } + + public AnnotatedType[] getAnnotatedBounds() { + throw new UnsupportedOperationException(); + } + +}