// Public API //////////////////////////////////////////////////////////////////////////////
public static final Type VOID = new Primitive("V", "void");
- public static final Type INT = new Primitive("I", "int");
- public static final Type LONG = new Primitive("J", "long");
- public static final Type BOOLEAN = new Primitive("Z", "boolean");
- public static final Type DOUBLE = new Primitive("D", "double");
- public static final Type FLOAT = new Primitive("F", "float");
- public static final Type BYTE = new Primitive("B", "byte");
- public static final Type CHAR = new Primitive("C", "char");
- public static final Type SHORT = new Primitive("S", "short");
+ public static final Type INT = new Primitive("I", "int", 10);
+ public static final Type LONG = new Primitive("J", "long", 11);
+ public static final Type BOOLEAN = new Primitive("Z", "boolean", 4);
+ public static final Type DOUBLE = new Primitive("D", "double", 7);
+ public static final Type FLOAT = new Primitive("F", "float", 6);
+ public static final Type BYTE = new Primitive("B", "byte", 8);
+ public static final Type CHAR = new Primitive("C", "char", 5);
+ public static final Type SHORT = new Primitive("S", "short", 9);
public static final Type NULL = new Null();
public static final Type.Class OBJECT = Type.Class.instance("java.lang.Object");
// it probably should be in Context.java
return null;
}
+
+ public static Type fromArraySpec(int i) {
+ switch(i) {
+ case 4: return Type.BOOLEAN;
+ case 5: return Type.CHAR;
+ case 6: return Type.FLOAT;
+ case 7: return Type.DOUBLE;
+ case 8: return Type.BYTE;
+ case 9: return Type.SHORT;
+ case 10: return Type.INT;
+ case 11: return Type.LONG;
+ default: throw new IllegalStateException("invalid array type");
+ }
+ }
// Protected/Private //////////////////////////////////////////////////////////////////////////////
public static class Primitive extends Type {
private String humanReadable;
- Primitive(String descriptor, String humanReadable) {
+ private int arraySpec;
+ Primitive(String descriptor, String humanReadable) { this(descriptor, humanReadable, -1); }
+ Primitive(String descriptor, String humanReadable, int arraySpec) {
super(descriptor);
this.humanReadable = humanReadable;
+ this.arraySpec = arraySpec;
}
public String toString() { return humanReadable; }
public boolean isPrimitive() { return true; }
+ public int toArraySpec() {
+ if (arraySpec < 0) throw new Error("you can't make arrays of " + this);
+ return arraySpec;
+ }
}
public abstract static class Ref extends Type {
public abstract String toString();
public Type.Ref asRef() { return this; }
public boolean isRef() { return true; }
+ abstract String internalForm();
}
public static class Array extends Type.Ref {
public boolean isArray() { return true; }
public String toString() { return base.toString() + "[]"; }
public Type getElementType() { return base; }
+ String internalForm() { return getDescriptor(); }
}
public static class Class extends Type.Ref {
public Type.Class.Body getBody(Context cx) { return cx.resolve(this.getName()); }
public abstract class Body extends HasAttributes {
public abstract Type.Class.Method.Body[] methods();
- public abstract Type.Class.Field.Body addField(Type.Class.Field field, int flags);
public abstract Type.Class.Field.Body[] fields();
public Body(int flags, ClassFile.AttrGen attrs) {
super(flags, attrs);
public String getName() { return name; }
public abstract String getTypeDescriptor();
public abstract String toString();
+ public abstract int hashCode();
+ public abstract boolean equals(Object o);
}
public class Field extends Member {
if ((flags & ~VALID_FIELD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags");
}
}
+ public int hashCode() {
+ return type.hashCode() ^ name.hashCode() ^ getDeclaringClass().hashCode();
+ }
+ public boolean equals(Object o_) {
+ if(o_ == this) return true;
+ if(!(o_ instanceof Field)) return false;
+ Field o = (Field) o_;
+ return o.getDeclaringClass() == getDeclaringClass() && o.type == type && o.name.equals(name);
+ }
}
public class Method extends Member {
}
}
}
+ public int hashCode() {
+ int h = returnType.hashCode() ^ name.hashCode() ^ getDeclaringClass().hashCode();
+ for(int i=0;i<argTypes.length;i++) h ^= argTypes[i].hashCode();
+ return h;
+ }
+ public boolean equals(Object o_) {
+ if(o_ == this) return true;
+ if(!(o_ instanceof Method)) return false;
+ Method o = (Method) o_;
+ if(!(o.getDeclaringClass() == getDeclaringClass() && o.returnType == returnType && o.name.equals(name))) return false;
+ if(o.argTypes.length != argTypes.length) return false;
+ for(int i=0;i<argTypes.length;i++)
+ if(o.argTypes[i] != argTypes[i]) return false;
+ return true;
+ }
}
}