Class JavaTemplate.Builder

java.lang.Object
org.openrewrite.java.JavaTemplate.Builder
Enclosing class:
JavaTemplate

public static class JavaTemplate.Builder extends Object
  • Constructor Details

    • Builder

      protected Builder(String code)
  • Method Details

    • contextSensitive

      public JavaTemplate.Builder contextSensitive()
      A template snippet is context-sensitive when it refers to the class, variables, methods, or other symbols visible from its insertion scope. When a template is completely self-contained, it is not context-sensitive. Context-free template snippets can be cached, since it does not matter where the resulting LST elements will be inserted. Since the LST elements in a context-sensitive snippet vary depending on where they are inserted the resulting LST elements cannot be reused between different insertion points and are not cached.

      An example of a context-free snippet might be something like this, to be used as a local variable declaration: int i = 1;

      An example of a context-sensitive snippet is: int i = a; This cannot be made sense of without the surrounding scope which includes the declaration of "a".

    • imports

      public JavaTemplate.Builder imports(String... fullyQualifiedTypeNames)
    • staticImports

      public JavaTemplate.Builder staticImports(String... fullyQualifiedMemberTypeNames)
    • javaParser

      public JavaTemplate.Builder javaParser(org.openrewrite.java.JavaParser.Builder<?,?> parser)
    • doAfterVariableSubstitution

      public JavaTemplate.Builder doAfterVariableSubstitution(Consumer<String> afterVariableSubstitution)
    • doBeforeParseTemplate

      public JavaTemplate.Builder doBeforeParseTemplate(Consumer<String> beforeParseTemplate)
    • build

      public JavaTemplate build()