- public static class Array extends Object {
- private int dim;
- protected Array(Type t) { super(_initHelper(t, 1)); this.dim = 1; }
- protected Array(Type t, int dim) { super(_initHelper(t, dim)); this.dim = dim; }
- public Type.Array asArray() { return this; }
- public boolean isArray() { return true; }
- public String humanReadable() {
- String ret = super.internalForm().replace('/', '.');
- for(int i=0; i<dim; i++) ret += "[]";
- return ret;
+ public Field field(String name, Type type) { return new Field(name, type); }
+ public abstract class Body extends HasFlags {
+ }
+
+ public Method method(String name, Type returnType, Type[] argTypes) { return new Method(name, returnType, argTypes); }
+ public Method method(String leftCrap, String rightCrap) { return method(leftCrap+rightCrap); }
+
+ /** see JVM Spec section 2.10.2 */
+ public Method method(String signature) {
+ // FEATURE: This parser is ugly but it works (and shouldn't be a problem) might want to clean it up though
+ String name = signature.substring(0, signature.indexOf('('));
+ String s = signature.substring(signature.indexOf('('));
+ if(!s.startsWith("(")) throw new IllegalArgumentException("invalid method type descriptor");
+ int p = s.indexOf(')');
+ if(p == -1) throw new IllegalArgumentException("invalid method type descriptor");
+ String argsDesc = s.substring(1,p);
+ String retDesc = s.substring(p+1);
+ Type[] argsBuf = new Type[argsDesc.length()];
+ int i;
+ for(i=0,p=0;argsDesc.length() > 0;i++,p=0) {
+ while(p < argsDesc.length() && argsDesc.charAt(p) == '[') p++;
+ if(p == argsDesc.length()) throw new IllegalArgumentException("invalid method type descriptor");
+ if(argsDesc.charAt(p) == 'L') {
+ p = argsDesc.indexOf(';');
+ if(p == -1) throw new IllegalArgumentException("invalid method type descriptor");
+ }
+ argsBuf[i] = Type.fromDescriptor(argsDesc.substring(0,p+1));
+ argsDesc = argsDesc.substring(p+1);
+ }
+ Type args[] = new Type[i];
+ System.arraycopy(argsBuf,0,args,0,i);
+ return method(name, Type.fromDescriptor(retDesc), args);
+ }
+
+ public abstract class Member {
+ public final String name;
+ private Member(String name) { this.name = name; }
+ public Type.Class getDeclaringClass() { return Type.Class.this; }
+ public String getName() { return name; }
+ public abstract String getTypeDescriptor();
+ public abstract String debugToString();
+ }
+
+ public class Field extends Member {
+ public final Type type;
+ private Field(String name, Type t) { super(name); this.type = t; }
+ public String getTypeDescriptor() { return type.getDescriptor(); }
+ public Type getType() { return type; }
+ public String debugToString() { return getDeclaringClass().debugToString()+"."+name+"["+type.debugToString()+"]"; }
+ public class Body extends HasFlags {
+ public final int flags;
+ public Body(int flags) {
+ if ((flags & ~VALID_FIELD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags");
+ this.flags = flags;
+ }
+ public int getFlags() { return flags; }
+ public Field getField() { return Field.this; }
+ }