pulled {Method,Member,Field}Ref into Type.Class; made them inner classes; much cleaner
[org.ibex.classgen.git] / src / org / ibex / classgen / MethodGen.java
index 31d1229..ba055bf 100644 (file)
@@ -10,7 +10,8 @@ public class MethodGen implements CGConst {
     
     private static final int NO_CODE = -1;
     private static final int FINISHED = -2;
-    
+
+    private final ClassFile owner;
     private final CPGen cp;
     private final String name;
     private final Type ret;
@@ -49,8 +50,9 @@ public class MethodGen implements CGConst {
         // FIXME: attrs, body
     }
 
-    MethodGen(CPGen cp, DataInput in) throws IOException {
+    MethodGen(CPGen cp, DataInput in, ClassFile owner) throws IOException {
         this.cp = cp;
+        this.owner = owner;
         flags = in.readShort();
         name = cp.getUtf8ByIndex(in.readShort());
         String descriptor = cp.getUtf8ByIndex(in.readShort());
@@ -70,21 +72,19 @@ public class MethodGen implements CGConst {
         this.ret = ret;
         this.args = args;
         this.flags = flags;
+        this.owner = owner;
         
         attrs = new ClassFile.AttrGen(cp);
         codeAttrs = new ClassFile.AttrGen(cp);
         
         cp.addUtf8(name);
-        cp.addUtf8(getDescriptor());
+        cp.addUtf8(owner.getType().method(name, ret, args).getDescriptor());
         
         if((owner.flags & ACC_INTERFACE) != 0 || (flags & (ACC_ABSTRACT|ACC_NATIVE)) != 0) size = capacity = -1;
         
         maxLocals = Math.max(args.length + (flags&ACC_STATIC)==0 ? 1 : 0, 4);
     }
     
-    /** Returns the descriptor string for this method */
-    public String getDescriptor() { return new MethodRef(null, name, ret, args).getDescriptor(); }
-    
     private class ExnTableEnt {
         public int start;
         public int end;
@@ -629,7 +629,7 @@ public class MethodGen implements CGConst {
     void dump(DataOutput o) throws IOException {
         o.writeShort(flags);
         o.writeShort(cp.getUtf8Index(name));
-        o.writeShort(cp.getUtf8Index(getDescriptor()));
+        o.writeShort(cp.getUtf8Index(owner.getType().method(name, ret, args).getDescriptor()));
         o.writeShort(attrs.size());
         attrs.dump(o);
     }