private void addAnnotationsAsAttribute(final ConstantPoolGen cp) { final Attribute[] attrs = AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries()); for (final Attribute attr : attrs) { addAttribute(attr); } }
/** * Instantiate from existing field. * * @param field Field object * @param cp constant pool (must contain the same entries as the field's constant pool) */ public FieldGen(Field field, ConstantPoolGen cp) { this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp); Attribute[] attrs = field.getAttributes(); for(int i=0; i < attrs.length; i++) { if(attrs[i] instanceof ConstantValue) setValue(((ConstantValue)attrs[i]).getConstantValueIndex()); else addAttribute(attrs[i]); } }
/** * Get field object after having set up all necessary values. */ public Field getField() { String signature = getSignature(); int name_index = cp.addUtf8(name); int signature_index = cp.addUtf8(signature); if(value != null) { checkType(type); int index = addConstant(); addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp.getConstantPool())); } return new Field(access_flags, name_index, signature_index, getAttributes(), cp.getConstantPool()); }
/** * Instantiate from existing field. * * @param field Field object * @param cp constant pool (must contain the same entries as the field's constant pool) */ public FieldGen(final Field field, final ConstantPoolGen cp) { this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp); final Attribute[] attrs = field.getAttributes(); for (final Attribute attr : attrs) { if (attr instanceof ConstantValue) { setValue(((ConstantValue) attr).getConstantValueIndex()); } else if (attr instanceof Annotations) { final Annotations runtimeAnnotations = (Annotations)attr; final AnnotationEntry[] annotationEntries = runtimeAnnotations.getAnnotationEntries(); for (final AnnotationEntry element : annotationEntries) { addAnnotationEntry(new AnnotationEntryGen(element,cp,false)); } } else { addAttribute(attr); } } }
/** * Get field object after having set up all necessary values. */ public Field getField() { final String signature = getSignature(); final int name_index = super.getConstantPool().addUtf8(super.getName()); final int signature_index = super.getConstantPool().addUtf8(signature); if (value != null) { checkType(super.getType()); final int index = addConstant(); addAttribute(new ConstantValue(super.getConstantPool().addUtf8("ConstantValue"), 2, index, super.getConstantPool().getConstantPool())); // sic } addAnnotationsAsAttribute(super.getConstantPool()); return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(), super.getConstantPool().getConstantPool()); // sic }