+
+ 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 toString();
+ }
+
+ 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 toString() { return getDeclaringClass().toString()+"."+name+"["+type.toString()+"]"; }
+ public class Body extends HasAttributes {
+ public Field getField() { return Field.this; }
+ public Body(int flags, ClassFile.AttrGen attrs) {
+ super(flags, attrs);
+ if ((flags & ~VALID_FIELD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags");
+ }
+ }
+ }
+
+ public class Method extends Member {
+ final Type[] argTypes;
+ public final Type returnType;
+ public Type getReturnType() { return returnType; }
+ public int getNumArgs() { return argTypes.length; }
+ public Type getArgType(int i) { return argTypes[i]; }
+ public Type[] getArgTypes() {
+ Type[] ret = new Type[argTypes.length];
+ System.arraycopy(argTypes, 0, ret, 0, ret.length);
+ return ret;
+ }
+ public boolean isConstructor() { return getName().equals("<init>"); }
+ public boolean isClassInitializer() { return getName().equals("<clinit>"); }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ if (name.equals("<clinit>")) sb.append("static ");
+ else {
+ if (name.equals("<init>"))
+ sb.append(Class.this.getShortName());
+ else
+ sb.append(returnType.toString()).append(".").append(name);
+ sb.append("(");
+ for(int i=0; i<argTypes.length; i++)
+ sb.append((i==0?"":", ")+argTypes[i].toString());
+ sb.append(") ");
+ }
+ return sb.toString();
+ }
+ private Method(String name, Type returnType, Type[] argTypes) {
+ super(name);
+ this.argTypes = argTypes;
+ this.returnType = returnType;
+ }
+ //public Method.Body getBody(Context cx) { }
+ public String getTypeDescriptor() {
+ StringBuffer sb = new StringBuffer(argTypes.length*4);
+ sb.append("(");
+ for(int i=0;i<argTypes.length;i++) sb.append(argTypes[i].getDescriptor());
+ sb.append(")");
+ sb.append(returnType.getDescriptor());
+ return sb.toString();
+ }
+ public abstract class Body extends HasAttributes {
+ public abstract java.util.Hashtable getThrownExceptions();
+ public abstract void debugBodyToString(StringBuffer sb);
+ public Method getMethod() { return Method.this; }
+ public Body(int flags, ClassFile.AttrGen attrs) {
+ super(flags, attrs);
+ if ((flags & ~VALID_METHOD_FLAGS) != 0) throw new IllegalArgumentException("invalid flags");
+ }
+ public boolean isConcrete() { return !isAbstract() && !isNative() /*FIXME: !inAnInterface*/; }
+ public void toString(StringBuffer sb, String constructorName) {
+ int flags = getFlags();
+ sb.append(" ").append(ClassFile.flagsToString(flags,false));
+ sb.append(Method.this.toString());
+ java.util.Hashtable thrownExceptions = getThrownExceptions();
+ if (thrownExceptions.size() > 0) {
+ sb.append("throws");
+ for(java.util.Enumeration e = thrownExceptions.keys();e.hasMoreElements();)
+ sb.append(" ").append(((Type.Class)e.nextElement()).toString()).append(",");
+ sb.setLength(sb.length()-1);
+ sb.append(" ");
+ }
+ if ((flags & (NATIVE|ABSTRACT))==0) {
+ sb.append("{\n");
+ debugBodyToString(sb);
+ sb.append(" }\n");
+ } else {
+ sb.append(";");
+ }
+ }
+ }
+ }
+ }
+
+ // FEATURE: This probably isn't the best place for these
+ static String methodTypeDescriptor(Type[] argTypes, Type returnType) {
+ StringBuffer sb = new StringBuffer(argTypes.length*4);
+ sb.append("(");
+ for(int i=0;i<argTypes.length;i++) sb.append(argTypes[i].getDescriptor());
+ sb.append(")");
+ sb.append(returnType.getDescriptor());
+ return sb.toString();