Skip to content

Commit

Permalink
add a reference to JavaTemplates documentation on first usage in `N…
Browse files Browse the repository at this point in the history
…oGuavaListsNewArrayList`
  • Loading branch information
MBoegers committed Feb 2, 2025
1 parent b8be50d commit bc4abf8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/yourorg/NoGuavaListsNewArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
// To avoid stale state persisting between cycles, getVisitor() should always return a new instance of
// its visitor
new JavaVisitor<ExecutionContext>() {
// Java Templates are used to generate Java code easily.
// They use a syntax that expand Java with possible type-safe insertions points.
// See https://docs.openrewrite.org/concepts-and-explanations/javatemplate for full documentation
private final JavaTemplate newArrayList = JavaTemplate.builder("new ArrayList<>()")
.imports("java.util.ArrayList")
.build();
Expand All @@ -84,6 +87,7 @@ public J visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
System.out.printf(printed);

// You must always delegate to the super method to ensure the visitor continues to visit deeper
// return cu; // this leads to a recipe that makes no changes at all
return super.visitCompilationUnit(cu, ctx);
}

Expand Down

0 comments on commit bc4abf8

Please sign in to comment.