public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) { new AttributesEditor((ProgramClass)clazz, (ProgramMember)method, codeAttribute, false).deleteAttribute(attributeName); } }
!replaceAttribute(targetAttribute.u2attributesCount, targetAttribute.attributes, attribute)) addAttribute(targetAttribute.u2attributesCount, targetAttribute.attributes, attribute); !replaceAttribute(targetMember.u2attributesCount, targetMember.attributes, attribute)) addAttribute(targetMember.u2attributesCount, targetMember.attributes, attribute); !replaceAttribute(targetClass.u2attributesCount, targetClass.attributes, attribute)) addAttribute(targetClass.u2attributesCount, targetClass.attributes, attribute);
/** * Finds the specified attribute in the target. */ public Attribute findAttribute(String attributeName) { // What's the target? return targetAttribute != null ? findAttribute(targetAttribute.u2attributesCount, targetAttribute.attributes, attributeName) : targetMember != null ? findAttribute(targetMember.u2attributesCount, targetMember.attributes, attributeName) : findAttribute(targetClass.u2attributesCount, targetClass.attributes, attributeName); }
public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute) { // Create a copy of the attribute. SyntheticAttribute newSyntheticAttribute = new SyntheticAttribute(constantAdder.addConstant(clazz, syntheticAttribute.u2attributeNameIndex)); // Add it to the target. attributesEditor.addAttribute(newSyntheticAttribute); }
new AttributesEditor(programClass, programMethod, codeAttribute, true).deleteAttribute(stackMapAttributeName); new AttributesEditor(programClass, programMethod, codeAttribute, true).addAttribute(stackMapAttribute);
public void finishEditing() { endCodeFragment(); CodeAttribute codeAttribute = new CodeAttribute(constantPoolEditor.addUtf8Constant(ClassConstants.ATTR_Code)); visitCodeAttribute(programClass, method, codeAttribute); new AttributesEditor(programClass, method, false).addAttribute(codeAttribute); classEditor.addMethod(method); } }
new AttributesEditor(targetClass, false); (BootstrapMethodsAttribute)attributesEditor.findAttribute(ClassConstants.ATTR_BootstrapMethods); new BootstrapMethodInfo[0]); attributesEditor.addAttribute(targetBootstrapMethodsAttribute);
public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant) { // Find the bootstrap methods attribute. AttributesEditor attributesEditor = new AttributesEditor((ProgramClass)clazz, false); BootstrapMethodsAttribute bootstrapMethodsAttribute = (BootstrapMethodsAttribute)attributesEditor.findAttribute(ClassConstants.ATTR_BootstrapMethods); // Add the name and type constant. clazz.constantPoolEntryAccept(invokeDynamicConstant.u2nameAndTypeIndex, this); // Copy the referenced classes. Clazz[] referencedClasses = invokeDynamicConstant.referencedClasses; Clazz[] referencedClassesCopy = null; if (referencedClasses != null) { referencedClassesCopy = new Clazz[referencedClasses.length]; System.arraycopy(referencedClasses, 0, referencedClassesCopy, 0, referencedClasses.length); } bootstrapMethodsAttribute.bootstrapMethodEntryAccept(clazz, invokeDynamicConstant.getBootstrapMethodAttributeIndex(), bootstrapMethodsAttributeAdder); // Then add the actual invoke dynamic constant. constantIndex = constantPoolEditor.addInvokeDynamicConstant(bootstrapMethodsAttributeAdder.getBootstrapMethodIndex(), constantIndex, referencedClassesCopy); }
/** * Deletes the specified attribute from the target. */ public void deleteAttribute(String attributeName) { // What's the target? if (targetAttribute != null) { targetAttribute.u2attributesCount = deleteAttribute(targetAttribute.u2attributesCount, targetAttribute.attributes, attributeName); } else if (targetMember != null) { targetMember.u2attributesCount = deleteAttribute(targetMember.u2attributesCount, targetMember.attributes, attributeName); } else { targetClass.u2attributesCount = deleteAttribute(targetClass.u2attributesCount, targetClass.attributes, attributeName); } }
/** * Creates a new AttributeAdder that will copy attributes into the given * target attribute. */ public AttributeAdder(ProgramClass targetClass, ProgramMember targetMember, CodeAttribute targetCodeAttribute, boolean replaceAttributes) { this.targetClass = targetClass; this.targetMember = targetMember; this.targetCodeAttribute = targetCodeAttribute; this.replaceAttributes = replaceAttributes; constantAdder = new ConstantAdder(targetClass); attributesEditor = new AttributesEditor(targetClass, targetMember, targetCodeAttribute, replaceAttributes); }
/** * Deletes the attributes with the given name from the given array of * attributes, returning the new number of attributes. */ private int deleteAttribute(int attributesCount, Attribute[] attributes, String attributeName) { // Find the attribute. int index = findAttributeIndex(attributesCount, attributes, attributeName); if (index < 0) { return attributesCount; } // Shift the other attributes in the array. System.arraycopy(attributes, index + 1, attributes, index, attributesCount - index - 1); // Clear the last entry in the array. attributes[--attributesCount] = null; return attributesCount; }
public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) { // Create a copy of the attribute. InnerClassesAttribute newInnerClassesAttribute = new InnerClassesAttribute(constantAdder.addConstant(clazz, innerClassesAttribute.u2attributeNameIndex), 0, null); // Add it to the target class. attributesEditor.addAttribute(newInnerClassesAttribute); }
new AttributesEditor(programClass, programMethod, codeAttribute, true).deleteAttribute(stackMapAttributeName); new AttributesEditor(programClass, programMethod, codeAttribute, true).addAttribute(stackMapAttribute);
public void finishEditing() { endCodeFragment(); CodeAttribute codeAttribute = new CodeAttribute(constantPoolEditor.addUtf8Constant(ClassConstants.ATTR_Code)); visitCodeAttribute(programClass, method, codeAttribute); new AttributesEditor(programClass, method, false).addAttribute(codeAttribute); classEditor.addMethod(method); } }
new AttributesEditor(targetClass, false); (BootstrapMethodsAttribute)attributesEditor.findAttribute(ClassConstants.ATTR_BootstrapMethods); new BootstrapMethodInfo[0]); attributesEditor.addAttribute(targetBootstrapMethodsAttribute);
public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant) { // Find the bootstrap methods attribute. AttributesEditor attributesEditor = new AttributesEditor((ProgramClass)clazz, false); BootstrapMethodsAttribute bootstrapMethodsAttribute = (BootstrapMethodsAttribute)attributesEditor.findAttribute(ClassConstants.ATTR_BootstrapMethods); // Add the name and type constant. clazz.constantPoolEntryAccept(invokeDynamicConstant.u2nameAndTypeIndex, this); // Copy the referenced classes. Clazz[] referencedClasses = invokeDynamicConstant.referencedClasses; Clazz[] referencedClassesCopy = null; if (referencedClasses != null) { referencedClassesCopy = new Clazz[referencedClasses.length]; System.arraycopy(referencedClasses, 0, referencedClassesCopy, 0, referencedClasses.length); } bootstrapMethodsAttribute.bootstrapMethodEntryAccept(clazz, invokeDynamicConstant.getBootstrapMethodAttributeIndex(), bootstrapMethodsAttributeAdder); // Then add the actual invoke dynamic constant. constantIndex = constantPoolEditor.addInvokeDynamicConstant(bootstrapMethodsAttributeAdder.getBootstrapMethodIndex(), constantIndex, referencedClassesCopy); }
/** * Deletes the specified attribute from the target. */ public void deleteAttribute(String attributeName) { // What's the target? if (targetAttribute != null) { targetAttribute.u2attributesCount = deleteAttribute(targetAttribute.u2attributesCount, targetAttribute.attributes, attributeName); } else if (targetMember != null) { targetMember.u2attributesCount = deleteAttribute(targetMember.u2attributesCount, targetMember.attributes, attributeName); } else { targetClass.u2attributesCount = deleteAttribute(targetClass.u2attributesCount, targetClass.attributes, attributeName); } }
/** * Creates a new AttributeAdder that will copy attributes into the given * target attribute. */ public AttributeAdder(ProgramClass targetClass, ProgramMember targetMember, CodeAttribute targetCodeAttribute, boolean replaceAttributes) { this.targetClass = targetClass; this.targetMember = targetMember; this.targetCodeAttribute = targetCodeAttribute; this.replaceAttributes = replaceAttributes; constantAdder = new ConstantAdder(targetClass); attributesEditor = new AttributesEditor(targetClass, targetMember, targetCodeAttribute, replaceAttributes); }
/** * Deletes the attributes with the given name from the given array of * attributes, returning the new number of attributes. */ private int deleteAttribute(int attributesCount, Attribute[] attributes, String attributeName) { // Find the attribute. int index = findAttributeIndex(attributesCount, attributes, attributeName); if (index < 0) { return attributesCount; } // Shift the other attributes in the array. System.arraycopy(attributes, index + 1, attributes, index, attributesCount - index - 1); // Clear the last entry in the array. attributes[--attributesCount] = null; return attributesCount; }
public void visitProgramClass(ProgramClass programClass) { new AttributesEditor(programClass, false).deleteAttribute(attributeName); } }