X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FFieldGen.java;h=ef4edcbdc1201a597763bcbbfe30cd5c235371ea;hb=0e74145dcd9c0aa01c5403d9d9bc9cb496776ba8;hp=330849b096c0fbd6f31457a1f2eba5aa337a4b0d;hpb=50a344886756b00af0e30d548a7a86822ef7e962;p=org.ibex.classgen.git diff --git a/src/org/ibex/classgen/FieldGen.java b/src/org/ibex/classgen/FieldGen.java index 330849b..ef4edcb 100644 --- a/src/org/ibex/classgen/FieldGen.java +++ b/src/org/ibex/classgen/FieldGen.java @@ -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());