+ FieldGen fg = new FieldGen(f.getAccessFlags(),f.getType(),f.getName(),cp);
+ Attribute[] attrs = f.getAttributes();
+ for(int j=0;j<attrs.length;j++) {
+ if(attrs[j] instanceof ConstantValue) {
+ ConstantObject co = (ConstantObject) oldCP.getConstant(((ConstantValue)attrs[i]).getConstantValueIndex());
+ Object o = co.getConstantValue(oldCP.getConstantPool());
+ if(co instanceof ConstantLong) fg.setInitValue(((Number)o).longValue());
+ else if(co instanceof ConstantInteger) fg.setInitValue(((Number)o).intValue());
+ else if(co instanceof ConstantFloat) fg.setInitValue(((Number)o).floatValue());
+ else if(co instanceof ConstantDouble) fg.setInitValue(((Number)o).floatValue());
+ else if(co instanceof ConstantString) fg.setInitValue((String)o);
+ else throw new Error("should never happen");
+ } else {
+ Attribute a = attrs[j];
+ Constant con = oldCP.getConstant(a.getNameIndex());
+ a.setNameIndex(cp.addConstant(con,oldCP));
+ //System.err.println("Adding attribute: " + attrs[j]);
+ fg.addAttribute(a);
+ }
+ }
+ /*if(f.getConstantValue() != null) throw new Error("this might be broken");
+ FieldGen fg = new FieldGen(f.getAccessFlags(),f.getType(),f.getName(),cp);*/
+ cg.addField(fg.getField());