-
- /** Returns the Java descriptor string for this object ("I", or "Ljava/lang/String", "[[J", etc */
- public final String getDescriptor() { return descriptor; }
- public int hashCode() { return descriptor.hashCode(); }
- public boolean equals(java.lang.Object o) { return o instanceof Type && ((Type)o).descriptor.equals(descriptor); }
-
- /** Returns a one dimensional array type for the base type <i>base</i>
- @param base The base type
- @return A one dimensional array of the base type
- */
- public static Type arrayType(Type base) { return arrayType(base,1); }
- /** Returns a <i>dim</i> dimensional array type for the base type <i>base</i>
- @param base The base type
- @param dim Number if dimensions
- @return A one dimensional array of the base type
- */
- public static Type arrayType(Type base, int dim) {
- StringBuffer sb = new StringBuffer(base.descriptor.length() + dim);
- for(int i=0;i<dim;i++) sb.append("[");
- sb.append(base.descriptor);
- return new Type(sb.toString());
+
+ public String toString() { return toString; }
+ public final String getDescriptor() { return descriptor; }
+ public int hashCode() { return descriptor.hashCode(); }
+ public boolean equals(java.lang.Object o) { return this==o; }
+
+ public Type.Array makeArray() { return (Type.Array)instance(descriptor+"["); }
+
+ public Type.Ref asRef() { throw new RuntimeException("attempted to use "+this+" as a Type.Ref, which it is not"); }
+ public Type.Class asClass() { throw new RuntimeException("attempted to use "+this+" as a Type.Class, which it is not"); }
+ public Type.Array asArray() { throw new RuntimeException("attempted to use "+this+" as a Type.Array, which it is not"); }
+ public boolean isPrimitive() { return !isRef(); }
+ public boolean isRef() { return false; }
+ public boolean isClass() { return false; }
+ public boolean isArray() { return false; }
+
+ // Protected/Private //////////////////////////////////////////////////////////////////////////////
+
+ protected final String descriptor;
+ protected final String toString;
+ protected Type(String descriptor) { this(descriptor, descriptor); }
+ protected Type(String descriptor, String humanReadable) {
+ this.toString = humanReadable;
+ instances.put(this.descriptor = descriptor, this);