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