Fixing the method getGenericParameterTypes to recognize the GenericArrayTypeImpl...
[jpf-core.git] / src / classes / sun / reflect / generics / reflectiveObjects / GenericArrayTypeImpl.java
1 package sun.reflect.generics.reflectiveObjects;
2
3 import java.lang.reflect.GenericArrayType;
4 import java.lang.reflect.Type;
5 import java.util.Objects;
6
7 /**
8  * MJI model class for sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
9  *
10  * This is a JPF specific version of a system class because we can't use the real,
11  * platform VM specific version (it's native all over the place, its field
12  * structure isn't documented, most of its methods are private, hence we can't
13  * even instantiate it properly).
14  *
15  * Note that this class never gets seen by the real VM - it's for JPF's eyes only.
16  *
17  * For now this only supports a few basic methods.
18  */
19 public class GenericArrayTypeImpl
20         implements GenericArrayType {
21     private final Type genericComponentType;
22
23     // private constructor enforces use of static factory
24     private GenericArrayTypeImpl(Type ct) {
25         genericComponentType = ct;
26     }
27
28     public static GenericArrayTypeImpl make(Type ct) {
29         return new GenericArrayTypeImpl(ct);
30     }
31
32     public Type getGenericComponentType() {
33         return genericComponentType; // return cached component type
34     }
35
36     public String toString() {
37         Type componentType = getGenericComponentType();
38         StringBuilder sb = new StringBuilder();
39
40         if (componentType instanceof Class)
41             sb.append(((Class)componentType).getName() );
42         else
43             sb.append(componentType.toString());
44         sb.append("[]");
45         return sb.toString();
46     }
47
48     @Override
49     public boolean equals(Object o) {
50         if (o instanceof GenericArrayType) {
51             GenericArrayType that = (GenericArrayType) o;
52
53             return Objects.equals(genericComponentType, that.getGenericComponentType());
54         } else
55             return false;
56     }
57
58     @Override
59     public int hashCode() {
60         return Objects.hashCode(genericComponentType);
61     }
62 }