Class JavaTemplate


  • @Incubating(since="7.0.0")
    public class JavaTemplate
    extends java.lang.Object
    Build ASTs from the text of Java source code without knowing how to build the AST elements that make up that text.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JavaTemplate.Builder  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JavaTemplate.Builder builder​(java.util.function.Supplier<org.openrewrite.Cursor> parentScope, java.lang.String code)  
      <J2 extends J>
      J2
      withTemplate​(org.openrewrite.Tree changing, JavaCoordinates coordinates, java.lang.Object... parameters)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • builder

        public static JavaTemplate.Builder builder​(java.util.function.Supplier<org.openrewrite.Cursor> parentScope,
                                                   java.lang.String code)
      • withTemplate

        public <J2 extends J> J2 withTemplate​(org.openrewrite.Tree changing,
                                              JavaCoordinates coordinates,
                                              java.lang.Object... parameters)
        Type Parameters:
        J2 - The type of the changing tree.
        Parameters:
        changing - The tree that will be returned modified where one of its subtrees will have been added or replaced by an AST formed from the template.
        coordinates - The point where the template will either insert or replace code.
        parameters - Parameters substituted into the template.
        Returns:
        A modified form of the changing tree.