rename CPGen -> ConstantPool
[org.ibex.classgen.git] / src / org / ibex / classgen / FieldGen.java
index 330849b..ef4edcb 100644 (file)
@@ -3,25 +3,42 @@ package org.ibex.classgen;
 import java.io.*;
 
 /** Class representing a field in a generated classfile
-    @see ClassGen#addField */
+    @see ClassFile#addField */
 public class FieldGen implements CGConst {
-    private final CPGen cp;
+    private final ConstantPool cp;
     private final String name;
     private final Type type;
     private final int flags;
-    private final ClassGen.AttrGen attrs;
+    private final ClassFile.AttrGen attrs;
     
     private Object constantValue;
+
+    public String toString() { StringBuffer sb = new StringBuffer(); toString(sb); return sb.toString(); }
+    public void   toString(StringBuffer sb) {
+        sb.append(ClassFile.flagsToString(flags));
+        sb.append(type);
+        sb.append(" ");
+        sb.append(name);
+        sb.append(";");
+        // FIXME: attrs
+    }
     
-    FieldGen(DataInput in) { throw new Error("Brian is lame"); }
-    FieldGen(ClassGen owner, String name, Type type, int flags) {
+    FieldGen(ConstantPool cp, DataInput in) throws IOException {
+        this.cp = cp;
+        flags = in.readShort();
+        name = cp.getUtf8ByIndex(in.readShort());
+        type = cp.getType(in.readShort());
+        attrs = new ClassFile.AttrGen(cp, in);
+    }
+
+    FieldGen(ClassFile owner, String name, Type type, int flags) {
         if((flags & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_VOLATILE|ACC_TRANSIENT|ACC_STATIC|ACC_FINAL)) != 0)
             throw new IllegalArgumentException("invalid flags");
         this.cp = owner.cp;
         this.name = name;
         this.type = type;
         this.flags = flags;
-        this.attrs = new ClassGen.AttrGen(cp);
+        this.attrs = new ClassFile.AttrGen(cp);
         
         cp.addUtf8(name);
         cp.addUtf8(type.getDescriptor());