X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fclassgen%2FFieldGen.java;h=aab5586c11e185bdf456fb3e380c5846f3628edb;hb=61c79c5fd88e1017446c804adcafde230f4d90e8;hp=b2d25bc9a2e5de5dae134c28763ea9aa42fd1c55;hpb=fb8a2dfe2f45b27710921562df968b86f2faceee;p=org.ibex.classgen.git diff --git a/src/org/ibex/classgen/FieldGen.java b/src/org/ibex/classgen/FieldGen.java index b2d25bc..aab5586 100644 --- a/src/org/ibex/classgen/FieldGen.java +++ b/src/org/ibex/classgen/FieldGen.java @@ -2,6 +2,8 @@ package org.ibex.classgen; import java.io.*; +/** Class representing a field in a generated classfile + @see ClassGen#addField */ public class FieldGen implements CGConst { private final CPGen cp; private final String name; @@ -10,8 +12,26 @@ public class FieldGen implements CGConst { private final ClassGen.AttrGen attrs; private Object constantValue; + + public String toString() { StringBuffer sb = new StringBuffer(); toString(sb); return sb.toString(); } + public void toString(StringBuffer sb) { + sb.append(ClassGen.flagsToString(flags)); + sb.append(type.humanReadable()); + sb.append(" "); + sb.append(name); + sb.append(";"); + // FIXME: attrs + } - FieldGen(ClassGen owner, String name,Type type, int flags) { + FieldGen(CPGen cp, DataInput in) throws IOException { + this.cp = cp; + flags = in.readShort(); + name = cp.getUtf8ByIndex(in.readShort()); + type = cp.getType(in.readShort()); + attrs = new ClassGen.AttrGen(cp, in); + } + + FieldGen(ClassGen 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; @@ -33,7 +53,7 @@ public class FieldGen implements CGConst { void finish() { if(constantValue != null && !attrs.contains("ConstantValue")) - attrs.add("ConstantValue",cp.add(constantValue)); + attrs.add("ConstantValue", cp.add(constantValue)); } void dump(DataOutput o) throws IOException {