if(tag == 0) throw new Error("should never happen");
CPRefEnt ce = new CPRefEnt(tag);
ce.e1 = add(key.klass);
- ce.e2 = addNameAndType(key.name, key.descriptor);
+ ce.e2 = addNameAndType(key.name, key.getDescriptor());
ent = ce;
} else {
throw new IllegalArgumentException("Unknown type passed to add");
*/
public class FieldRef extends MemberRef {
/** Create a reference to field <i>name</i> of class <i>c</i> with the type <i>t</i> */
- public FieldRef(Type.Class c, String name, Type t) { super(c, name, t.getDescriptor()); }
- /** Equivalent to FieldRef(new Type.Class(s), ...)
- @see #FieldRef(Type.Class, String, Type, )
- */
- public FieldRef(String s, String name, Type t) { this(Type.instance(s).asClass(), name, t); }
+ public final Type type;
+ public FieldRef(Type.Class c, String name, Type t) { super(c, name); this.type = t; }
+ public String getDescriptor() { return name; }
}
+
@see FieldRef
*/
public abstract class MemberRef {
- Type.Class klass;
- String name;
- String descriptor;
+ public final Type.Class klass;
+ public final String name;
- MemberRef(Type.Class klass, String name, String descriptor) { this.klass = klass; this.name = name; this.descriptor = descriptor; }
- MemberRef(MemberRef o) { this.klass = o.klass; this.name = o.name; this.descriptor = o.descriptor; }
+ MemberRef(Type.Class klass, String name) {
+ this.klass = klass;
+ this.name = name;
+ }
+ public abstract String getDescriptor();
public boolean equals(Object o_) {
if(!(o_ instanceof MemberRef)) return false;
MemberRef o = (MemberRef) o_;
- return o.klass.equals(klass) && o.name.equals(name) && o.descriptor.equals(descriptor);
+ return o.klass.equals(klass) && o.name.equals(name) && o.getDescriptor().equals(getDescriptor());
}
- public int hashCode() { return klass.hashCode() ^ name.hashCode() ^ descriptor.hashCode(); }
+ public int hashCode() { return klass.hashCode() ^ name.hashCode() ^ getDescriptor().hashCode(); }
}
}
/** Returns the descriptor string for this method */
- public String getDescriptor() { return MethodRef.getDescriptor(ret, args); }
+ public String getDescriptor() { return new MethodRef(null, name, ret, args).getDescriptor(); }
private class ExnTableEnt {
public int start;
if(arg instanceof Long || arg instanceof Double) op = LDC2_W;
break;
- case INVOKEINTERFACE:
- if(arg instanceof MethodRef) arg = new MethodRef.I((MethodRef)arg);
+ case INVOKEINTERFACE: {
+ MethodRef mr = (MethodRef)arg;
+ if(arg instanceof MethodRef) arg = new MethodRef.I(mr.klass, mr.name, mr.returnType, mr.argTypes);
break;
+ }
}
int opdata = OP_DATA[op&0xff];
if((opdata&OP_CPENT_FLAG) != 0 && !(arg instanceof CPGen.Ent))
@see CGConst#INVOKEINTERFACE
*/
public class MethodRef extends MemberRef {
+
+ final Type[] argTypes;
+ final Type returnType;
+
/** Create a reference to method <i>name</i> of class <i>c</i> with the return type <i>ret</i> and the
arguments <i>args</i> */
- public MethodRef(Type.Class c, String name, Type ret, Type[] args) {
- super(c, name, getDescriptor(ret, args));
- }
- /** Equivalent to MethodRef(new Type.Class(s), ...)
- @see #MethodRef(Type.Class, String, Type, Type[])
- */
- public MethodRef(String s, String name, Type ret, Type[] args) {
- this(Type.instance(s).asClass(), name, ret, args);
+ public MethodRef(Type.Class c, String name, Type returnType, Type[] argTypes) {
+ super(c, name);
+ this.argTypes = argTypes;
+ this.returnType = returnType;
}
- MethodRef(MethodRef i) { super(i); }
- static String getDescriptor(Type ret, Type[] args) {
- StringBuffer sb = new StringBuffer(args.length*4);
+ public String getDescriptor() {
+ StringBuffer sb = new StringBuffer(argTypes.length*4);
sb.append("(");
- for(int i=0;i<args.length;i++) sb.append(args[i].getDescriptor());
+ for(int i=0;i<argTypes.length;i++) sb.append(argTypes[i].getDescriptor());
sb.append(")");
- sb.append(ret.getDescriptor());
+ sb.append(returnType.getDescriptor());
return sb.toString();
}
to MethodRef.I's when they are applied to an INVOKEINTERFACE bytecode */
public static class I extends MethodRef {
public I(Type.Class c, String name, Type ret, Type[] args) { super(c, name, ret, args); }
- public I(String s, String name, Type ret, Type[] args) { super(s, name, ret, args); }
- I(MethodRef m) { super(m); }
}
}