Class InlineValueRewriter

java.lang.Object
org.approvej.approve.InlineValueRewriter

@NullMarked public class InlineValueRewriter extends Object
Rewrites byValue() string arguments in test source files.

When the Configuration.defaultInlineValueReviewer() is configured (e.g. as automatic), this class replaces the string argument of a byValue() call with a text block containing the new received value. Only the argument itself is replaced — the rest of the file is left untouched.

Supports Java (.java), Kotlin (.kt), Groovy (.groovy), and Scala (.scala) source files.

  • Method Details

    • rewrite

      public static void rewrite(Path sourcePath, String methodName, String newValue)
      Rewrites the byValue() call in the given test method, replacing the string argument with a text block containing the new value.

      The method is located in the source file by its name, then the byValue() call within that method is rewritten. This approach is robust even when earlier rewrites have shifted line numbers in the same file.

      Parameters:
      sourcePath - path to the source file
      methodName - the name of the test method containing the byValue() call
      newValue - the new value to write as a text block argument
    • rewriteContent

      public static String rewriteContent(String content, String methodName, String newValue, Path sourcePath)
      Rewrites the content of a source file, replacing the byValue() argument in the given method with a text block containing the new value.
      Parameters:
      content - the source file content
      methodName - the test method name
      newValue - the new value
      sourcePath - the source file path (used to detect the language)
      Returns:
      the rewritten content