import java.io.*;
/** Class generation object representing the whole classfile */
-public class ClassFile implements CGConst {
+public class ClassFile extends Type.Class.Body {
private final Type.Class thisType;
private final Type.Class superType;
private final Type.Class[] interfaces;
public ClassFile(Type.Class thisType, Type.Class superType, int flags) { this(thisType, superType, flags, null); }
public ClassFile(Type.Class thisType, Type.Class superType, int flags, Type.Class[] interfaces) {
+ thisType.super();
+ this.thisType = thisType;
if((flags & ~(PUBLIC|FINAL|SUPER|INTERFACE|ABSTRACT)) != 0)
throw new IllegalArgumentException("invalid flags");
- this.thisType = thisType;
this.superType = superType;
this.interfaces = interfaces;
this.flags = flags;
public ClassFile(DataInput i) throws IOException { this(i, false); }
public ClassFile(DataInput i, boolean ssa) throws IOException {
- int magic = i.readInt();
+ this(i.readInt(), i.readShort(), i.readShort(), new ConstantPool(i), i.readShort(), i, ssa);
+ }
+ private ClassFile(int magic, short minor, short major, ConstantPool cp,
+ short flags, DataInput i, boolean ssa) throws IOException {
+ this(magic, minor, major, cp, flags, (Type.Class)cp.getKeyByIndex(i.readShort()), i, ssa);
+ }
+ private ClassFile(int magic, short minor, short major, ConstantPool cp, short flags,
+ Type.Class thisType, DataInput i, boolean ssa) throws IOException {
+ thisType.super();
if (magic != 0xcafebabe) throw new ClassReadExn("invalid magic: " + Long.toString(0xffffffffL & magic, 16));
- minor = i.readShort();
- major = i.readShort();
- ConstantPool cp = new ConstantPool(i);
- flags = i.readShort();
+ this.minor = minor;
+ this.major = major;
+ this.flags = flags;
if((flags & ~(PUBLIC|FINAL|SUPER|INTERFACE|ABSTRACT)) != 0)
throw new ClassReadExn("invalid flags: " + Integer.toString(flags,16));
- thisType = (Type.Class) cp.getKeyByIndex(i.readShort());
+ this.thisType = thisType;
superType = (Type.Class) cp.getKeyByIndex(i.readShort());
interfaces = new Type.Class[i.readShort()];
for(int j=0; j<interfaces.length; j++) interfaces[j] = (Type.Class) cp.getKeyByIndex(i.readShort());
public Type.Class asClass() { return this; }
public boolean isClass() { return true; }
public String getShortName() { return toString.substring(toString.lastIndexOf('.')+1); }
+ public String getName() { return toString(); }
+ //public boolean extendsOrImplements(Type.Class c, Context cx) { }
String internalForm() { return descriptor.substring(1, descriptor.length()-1); }
private static String _initHelper(String s) {
if (!s.startsWith("L") || !s.endsWith(";")) s = "L" + s.replace('.', '/') + ";";
return a;
}
+ public abstract class Body extends HasFlags {
+ }
+
public Field field(String name, Type type) { return new Field(name, type); }
public Method method(String name, Type returnType, Type[] argTypes) { return new Method(name, returnType, argTypes); }
public Method method(String signature) {
public String getDescriptor() { return type.getDescriptor(); }
public Type getType() { return type; }
public String debugToString() { return getDeclaringClass()+"."+name+"["+type+"]"; }
+ public class Body extends HasFlags {
+ public final int flags;
+ public Body(int flags) { this.flags = flags; }
+ public int getFlags() { return flags; }
+ }
}
public class Method extends Member {
final Type[] argTypes;
public final Type returnType;
- public Type getArgType(int i) { return argTypes[i]; }
- public int getNumArgs() { return argTypes.length; }
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 debugToString() {
StringBuffer sb = new StringBuffer();
if (name.equals("<clinit>")) sb.append("static ");
this.argTypes = argTypes;
this.returnType = returnType;
}
+ //public Method.Body getBody(Context cx) { }
public String getDescriptor() {
StringBuffer sb = new StringBuffer(argTypes.length*4);
sb.append("(");
sb.append(returnType.getDescriptor());
return sb.toString();
}
- public abstract class Body implements HasFlags {
+ public abstract class Body extends HasFlags {
public abstract java.util.Hashtable getThrownExceptions();
public abstract void debugBodyToString(StringBuffer sb);
public void debugToString(StringBuffer sb, String constructorName) {