Package com.avrix.agent
Class ClassModifier.ClassModifierBuilder
java.lang.Object
com.avrix.agent.ClassModifier.ClassModifierBuilder
- Enclosing class:
- ClassModifier
A class that implements the Builder pattern to create a
ClassModifier
object-
Constructor Summary
ConstructorDescriptionClassModifierBuilder
(String className) Builder constructor for classClassModifier
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Creates aClassModifier
object based on the current state of the builder.modifyConstructor
(String descriptor, BiConsumer<javassist.CtClass, javassist.CtConstructor> constructorModifier) Modifies a constructor of the class using a specified signature and constructor modifier.modifyDeclaredConstructor
(javassist.CtClass[] paramTypes, BiConsumer<javassist.CtClass, javassist.CtConstructor> constructorModifier) Modifies a declared constructor of the class using a specified signature and constructor modifier.modifyDeclaredField
(String fieldName, String descriptor, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a declared field of the class using a specified field modifier and description.modifyDeclaredField
(String fieldName, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a declared field of the class using a specified field modifier.modifyField
(String fieldName, String descriptor, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a field of the class using a specified field modifier and description.modifyField
(String fieldName, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a field of the class using a specified field modifier.modifyMethod
(String methodName, String methodSignature, BiConsumer<javassist.CtClass, javassist.CtMethod> methodModifier) Applying modifications to a method by its name using a set of instructions.modifyMethod
(String methodName, BiConsumer<javassist.CtClass, javassist.CtMethod> methodModifier) Applying modifications to a method by its name using a set of instructions.void
saveFile()
Saving a modified class to the "debug" directory.void
Saving a modified class to the specified directory.
-
Constructor Details
-
ClassModifierBuilder
Builder constructor for classClassModifier
- Parameters:
className
- the name of the class that needs to be modified
-
-
Method Details
-
modifyConstructor
public ClassModifier.ClassModifierBuilder modifyConstructor(String descriptor, BiConsumer<javassist.CtClass, javassist.CtConstructor> constructorModifier) Modifies a constructor of the class using a specified signature and constructor modifier.- Parameters:
descriptor
- The signature of the constructor to be modified (e.g., "()V" for a no-arg constructor).constructorModifier
- A BiConsumer that accepts a CtClass and CtConstructor to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyDeclaredConstructor
public ClassModifier.ClassModifierBuilder modifyDeclaredConstructor(javassist.CtClass[] paramTypes, BiConsumer<javassist.CtClass, javassist.CtConstructor> constructorModifier) Modifies a declared constructor of the class using a specified signature and constructor modifier.- Parameters:
paramTypes
- An array of CtClass objects representing the parameter types of the constructor.constructorModifier
- A BiConsumer that accepts a CtClass and CtConstructor to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyDeclaredField
public ClassModifier.ClassModifierBuilder modifyDeclaredField(String fieldName, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a declared field of the class using a specified field modifier.- Parameters:
fieldName
- The name of the field to be modified.fieldModifier
- A BiConsumer that accepts a CtClass and CtField to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyDeclaredField
public ClassModifier.ClassModifierBuilder modifyDeclaredField(String fieldName, String descriptor, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a declared field of the class using a specified field modifier and description.- Parameters:
fieldName
- The name of the field to be modified.descriptor
- The descriptor of the field type. If empty, it will search without descriptor.fieldModifier
- A BiConsumer that accepts a CtClass and CtField to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyField
public ClassModifier.ClassModifierBuilder modifyField(String fieldName, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a field of the class using a specified field modifier.- Parameters:
fieldName
- The name of the field to be modified.fieldModifier
- A BiConsumer that accepts a CtClass and CtField to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyField
public ClassModifier.ClassModifierBuilder modifyField(String fieldName, String descriptor, BiConsumer<javassist.CtClass, javassist.CtField> fieldModifier) Modifies a field of the class using a specified field modifier and description.- Parameters:
fieldName
- The name of the field to be modified.descriptor
- The descriptor of the field type. If empty, it will search without descriptor.fieldModifier
- A BiConsumer that accepts a CtClass and CtField to apply modifications.- Returns:
- The current instance of ClassModifierBuilder.
-
modifyMethod
public ClassModifier.ClassModifierBuilder modifyMethod(String methodName, BiConsumer<javassist.CtClass, javassist.CtMethod> methodModifier) Applying modifications to a method by its name using a set of instructions.- Parameters:
methodName
- name of the method being modifiedmethodModifier
- set of instructions for changing a method- Returns:
- the
ClassModifier.ClassModifierBuilder
instance for the call chain
-
modifyMethod
public ClassModifier.ClassModifierBuilder modifyMethod(String methodName, String methodSignature, BiConsumer<javassist.CtClass, javassist.CtMethod> methodModifier) Applying modifications to a method by its name using a set of instructions.- Parameters:
methodSignature
- the method signature in a format suitable for searching for method overloads (e.g. "int, String")methodName
- name of the method being modifiedmethodModifier
- set of instructions for changing a method- Returns:
- the
ClassModifier.ClassModifierBuilder
instance for the call chain
-
build
Creates aClassModifier
object based on the current state of the builder.- Returns:
ClassModifier
object
-
saveFile
public void saveFile()Saving a modified class to the "debug" directory. This method callssaveFile(Path)
passing the "debug" path as a parameter. Used to control changes to classes/methods. -
saveFile
Saving a modified class to the specified directory. Used to control changes to classes/methods.- Parameters:
path
- path to the directory where the class will be saved
-