public void visitProgramClass(ProgramClass programClass) { ClassEditor classEditor = new ClassEditor(programClass); // Remove all collected methods. for (Method method : methodsToRemove) { classEditor.removeMethod(method); } methodsToRemove.clear(); // Remove all collected fields. for (Field field : fieldsToRemove) { classEditor.removeField(field); } fieldsToRemove.clear(); }
/** * Removes the given field. Note that removing a field that is still being * referenced can cause unpredictable effects. */ public void removeField(Field field) { int fieldsCount = targetClass.u2fieldsCount; Field[] fields = targetClass.fields; int fieldIndex = findFieldIndex(field); // Shift the field entries. System.arraycopy(fields, fieldIndex+1, fields, fieldIndex, fieldsCount - fieldIndex - 1); // Clear the last entry. fields[--targetClass.u2fieldsCount] = null; }
/** * Removes the given interface. */ public void removeInterface(int interfaceConstantIndex) { int interfacesCount = targetClass.u2interfacesCount; int[] interfaces = targetClass.u2interfaces; int interfaceIndex = findInterfaceIndex(interfaceConstantIndex); // Shift the interface entries. System.arraycopy(interfaces, interfaceIndex+1, interfaces, interfaceIndex, interfacesCount - interfaceIndex - 1); // Clear the last entry. interfaces[--targetClass.u2interfacesCount] = 0; }
public void visitProgramClass(ProgramClass programClass) { if (DEBUG) { System.out.println("SimpleEnumClassSimplifier: ["+programClass.getName()+"]"); } // Unmark the class as an enum. programClass.u2accessFlags &= ~ClassConstants.ACC_ENUM; // Remove the valueOf method, if present. Method valueOfMethod = programClass.findMethod(ClassConstants.METHOD_NAME_VALUEOF, null); if (valueOfMethod != null) { new ClassEditor(programClass).removeMethod(valueOfMethod); } // Simplify the static initializer. programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT, ClassConstants.METHOD_TYPE_CLINIT, initializerSimplifier); }
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); } }
null); ClassEditor classEditor = new ClassEditor(lambdaClass); classEditor.addInterface(constantPoolEditor.addClassConstant(interfaceName, null));
/** * Creates a new MemberAdder that will copy methods into the given target * class. * @param targetClass the class to which all visited class members * will be added. * @param nameTransformer the transformer to be applied to each member's * name before copying. If null, the original * name will be used. * @param extraMemberVisitor an optional member visitor that visits each * new member right after it has been added. This * allows changing the visitor info, for instance. */ public MemberAdder(ProgramClass targetClass, StringTransformer nameTransformer, MemberVisitor extraMemberVisitor) { this.targetClass = targetClass; this.nameTransformer = nameTransformer; this.extraMemberVisitor = extraMemberVisitor; classEditor = new ClassEditor(targetClass); constantPoolEditor = new ConstantPoolEditor(targetClass); }
/** * Adds a new field to the edited class. * * @param u2accessFlags acces flags for the new field. * @param fieldName name of the new field. * @param fieldDescriptor descriptor of the new field. * * @return this SimpleClassEditor. */ public SimplifiedClassEditor addField(int u2accessFlags, String fieldName, String fieldDescriptor) { Field field = new ProgramField(u2accessFlags, constantPoolEditor.addUtf8Constant(fieldName), constantPoolEditor.addUtf8Constant(fieldDescriptor), null); classEditor.addField(field); return this; }
/** * Removes the given method. Note that removing a method that is still being * referenced can cause unpredictable effects. */ public void removeMethod(Method method) { int methodsCount = targetClass.u2methodsCount; Method[] methods = targetClass.methods; int methodIndex = findMethodIndex(method); // Shift the method entries. System.arraycopy(methods, methodIndex+1, methods, methodIndex, methodsCount - methodIndex - 1); // Clear the last entry. methods[--targetClass.u2methodsCount] = null; }
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); } }
public void visitProgramClass(ProgramClass programClass) { if (DEBUG) { System.out.println("SimpleEnumClassSimplifier: ["+programClass.getName()+"]"); } // Unmark the class as an enum. programClass.u2accessFlags &= ~ClassConstants.ACC_ENUM; // Remove the valueOf method, if present. Method valueOfMethod = programClass.findMethod(ClassConstants.METHOD_NAME_VALUEOF, null); if (valueOfMethod != null) { new ClassEditor(programClass).removeMethod(valueOfMethod); } // Simplify the static initializer. programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT, ClassConstants.METHOD_TYPE_CLINIT, initializerSimplifier); }
null); ClassEditor classEditor = new ClassEditor(lambdaClass); classEditor.addInterface(constantPoolEditor.addClassConstant(interfaceName, null));
/** * Creates a new MemberAdder that will copy methods into the given target * class. * @param targetClass the class to which all visited class members * will be added. * @param nameTransformer the transformer to be applied to each member's * name before copying. If null, the original * name will be used. * @param extraMemberVisitor an optional member visitor that visits each * new member right after it has been added. This * allows changing the visitor info, for instance. */ public MemberAdder(ProgramClass targetClass, StringTransformer nameTransformer, MemberVisitor extraMemberVisitor) { this.targetClass = targetClass; this.nameTransformer = nameTransformer; this.extraMemberVisitor = extraMemberVisitor; classEditor = new ClassEditor(targetClass); constantPoolEditor = new ConstantPoolEditor(targetClass); }
/** * Adds a new field to the edited class. * * @param u2accessFlags acces flags for the new field. * @param fieldName name of the new field. * @param fieldDescriptor descriptor of the new field. * * @return this SimpleClassEditor. */ public SimplifiedClassEditor addField(int u2accessFlags, String fieldName, String fieldDescriptor) { Field field = new ProgramField(u2accessFlags, constantPoolEditor.addUtf8Constant(fieldName), constantPoolEditor.addUtf8Constant(fieldDescriptor), null); classEditor.addField(field); return this; }
/** * Removes the given method. Note that removing a method that is still being * referenced can cause unpredictable effects. */ public void removeMethod(Method method) { int methodsCount = targetClass.u2methodsCount; Method[] methods = targetClass.methods; int methodIndex = findMethodIndex(method); // Shift the method entries. System.arraycopy(methods, methodIndex+1, methods, methodIndex, methodsCount - methodIndex - 1); // Clear the last entry. methods[--targetClass.u2methodsCount] = null; }
public void visitProgramClass(ProgramClass programClass) { ClassEditor classEditor = new ClassEditor(programClass); // Remove all collected methods. for (Method method : methodsToRemove) { classEditor.removeMethod(method); } methodsToRemove.clear(); // Remove all collected fields. for (Field field : fieldsToRemove) { classEditor.removeField(field); } fieldsToRemove.clear(); }
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); } }
public void visitProgramClass(ProgramClass programClass) { if (DEBUG) { System.out.println("SimpleEnumClassSimplifier: ["+programClass.getName()+"]"); } // Unmark the class as an enum. programClass.u2accessFlags &= ~ClassConstants.ACC_ENUM; // Remove the valueOf method, if present. Method valueOfMethod = programClass.findMethod(ClassConstants.METHOD_NAME_VALUEOF, null); if (valueOfMethod != null) { new ClassEditor(programClass).removeMethod(valueOfMethod); } // Simplify the static initializer. programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT, ClassConstants.METHOD_TYPE_CLINIT, initializerSimplifier); }
null); ClassEditor classEditor = new ClassEditor(lambdaClass); classEditor.addInterface(constantPoolEditor.addClassConstant(interfaceName, null));
/** * Creates a new MemberAdder that will copy methods into the given target * class. * @param targetClass the class to which all visited class members * will be added. * @param nameTransformer the transformer to be applied to each member's * name before copying. If null, the original * name will be used. * @param extraMemberVisitor an optional member visitor that visits each * new member right after it has been added. This * allows changing the visitor info, for instance. */ public MemberAdder(ProgramClass targetClass, StringTransformer nameTransformer, MemberVisitor extraMemberVisitor) { this.targetClass = targetClass; this.nameTransformer = nameTransformer; this.extraMemberVisitor = extraMemberVisitor; classEditor = new ClassEditor(targetClass); constantPoolEditor = new ConstantPoolEditor(targetClass); }