Class ClassModifier.ClassModifierBuilder

java.lang.Object
com.avrix.agent.ClassModifier.ClassModifierBuilder
Enclosing class:
ClassModifier

public static class ClassModifier.ClassModifierBuilder extends Object
A class that implements the Builder pattern to create a ClassModifier object
  • Constructor Details

    • ClassModifierBuilder

      public ClassModifierBuilder(String className)
      Builder constructor for class ClassModifier
      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 modified
      methodModifier - 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 modified
      methodModifier - set of instructions for changing a method
      Returns:
      the ClassModifier.ClassModifierBuilder instance for the call chain
    • build

      public ClassModifier build()
      Creates a ClassModifier 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 calls saveFile(Path) passing the "debug" path as a parameter. Used to control changes to classes/methods.
    • saveFile

      public void saveFile(Path path)
      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