1 package sun.reflect.generics.reflectiveObjects;
4 import java.lang.reflect.Type;
5 import java.lang.reflect.WildcardType;
6 import sun.reflect.generics.factory.GenericsFactory;
7 import sun.reflect.generics.tree.FieldTypeSignature;
8 import sun.reflect.generics.visitor.Reifier;
9 import java.util.Arrays;
13 * MJI model class for sun.reflect.generics.reflectiveObjects.WildcardTypeImpl
15 * This is a JPF specific version of a system class because we can't use the real,
16 * platform VM specific version (it's native all over the place, its field
17 * structure isn't documented, most of its methods are private, hence we can't
18 * even instantiate it properly).
20 * Note that this class never gets seen by the real VM - it's for JPF's eyes only.
23 public class WildcardTypeImpl extends LazyReflectiveObjectGenerator
24 implements WildcardType {
26 private Type[] upperBounds;
27 private Type[] lowerBounds;
28 private FieldTypeSignature[] upperBoundASTs;
29 private FieldTypeSignature[] lowerBoundASTs;
31 // constructor is private to enforce access through static factory
32 private WildcardTypeImpl(FieldTypeSignature[] ubs,
33 FieldTypeSignature[] lbs,
40 public static WildcardTypeImpl make(FieldTypeSignature[] ubs,
41 FieldTypeSignature[] lbs,
43 return new WildcardTypeImpl(ubs, lbs, f);
47 private FieldTypeSignature[] getUpperBoundASTs() {
48 throw new UnsupportedOperationException();
51 private FieldTypeSignature[] getLowerBoundASTs() {
52 throw new UnsupportedOperationException();
55 public Type[] getUpperBounds() {
59 public Type[] getLowerBounds() {
63 public String toString() {
64 Type[] lowerBounds = getLowerBounds();
65 Type[] bounds = lowerBounds;
66 StringBuilder sb = new StringBuilder();
68 if (lowerBounds.length > 0)
69 sb.append("? super ");
71 Type[] upperBounds = getUpperBounds();
72 if (upperBounds.length > 0 && !upperBounds[0].equals(Object.class) ) {
74 sb.append("? extends ");
79 // TODO: Commented out since it's producing <clinit> that blocks us from getting a new object without
80 // TODO: initializing it through the constructor.
81 //assert bounds.length > 0;
84 for(Type bound: bounds) {
89 sb.append(bound.getTypeName());
95 public boolean equals(Object o) {
96 if (o instanceof WildcardType) {
97 WildcardType that = (WildcardType) o;
99 Arrays.equals(this.getLowerBounds(),
100 that.getLowerBounds()) &&
101 Arrays.equals(this.getUpperBounds(),
102 that.getUpperBounds());
108 public int hashCode() {
109 Type [] lowerBounds = getLowerBounds();
110 Type [] upperBounds = getUpperBounds();
112 return Arrays.hashCode(lowerBounds) ^ Arrays.hashCode(upperBounds);