Skip to content

Commit 7db1681

Browse files
committed
Removing JavaVisitor#template
1 parent 1358278 commit 7db1681

17 files changed

+31
-27
lines changed

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaDirectExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected TreeVisitor<?, ExecutionContext> getSingleSourceApplicableTest() {
4545
@Override
4646
protected TreeVisitor<?, ExecutionContext> getVisitor() {
4747
return new JavaVisitor<ExecutionContext>() {
48-
private final JavaTemplate template = template("Runnable::run")
48+
private final JavaTemplate template = JavaTemplate.builder(this::getCursor, "Runnable::run")
4949
.imports("java.lang.Runnable")
5050
.build();
5151

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewArrayList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
5656
@Override
5757
protected TreeVisitor<?, ExecutionContext> getVisitor() {
5858
return new JavaVisitor<ExecutionContext>() {
59-
private final JavaTemplate newArrayList = template("new ArrayList<>()")
59+
private final JavaTemplate newArrayList = JavaTemplate.builder(this::getCursor, "new ArrayList<>()")
6060
.imports("java.util.ArrayList")
6161
.build();
6262

63-
private final JavaTemplate newArrayListIterable = template("new ArrayList<>(#{any(java.lang.Iterable)})")
63+
private final JavaTemplate newArrayListIterable = JavaTemplate.builder(this::getCursor, "new ArrayList<>(#{any(java.lang.Iterable)})")
6464
.imports("java.util.ArrayList")
6565
.build();
6666

67-
private final JavaTemplate newArrayListCapacity = template("new ArrayList<>(#{any(int)})")
67+
private final JavaTemplate newArrayListCapacity = JavaTemplate.builder(this::getCursor, "new ArrayList<>(#{any(int)})")
6868
.imports("java.util.ArrayList")
6969
.build();
7070

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewCopyOnWriteArrayList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
5454
@Override
5555
protected TreeVisitor<?, ExecutionContext> getVisitor() {
5656
return new JavaVisitor<ExecutionContext>() {
57-
private final JavaTemplate newArrayList = template("new CopyOnWriteArrayList<>()")
57+
private final JavaTemplate newArrayList = JavaTemplate.builder(this::getCursor, "new CopyOnWriteArrayList<>()")
5858
.imports("java.util.concurrent.CopyOnWriteArrayList")
5959
.build();
6060

61-
private final JavaTemplate newArrayListIterable = template("new CopyOnWriteArrayList<>(#{any(java.lang.Iterable)})")
61+
private final JavaTemplate newArrayListIterable = JavaTemplate.builder(this::getCursor, "new CopyOnWriteArrayList<>(#{any(java.lang.Iterable)})")
6262
.imports("java.util.concurrent.CopyOnWriteArrayList")
6363
.build();
6464

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaListsNewLinkedList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
5454
@Override
5555
protected TreeVisitor<?, ExecutionContext> getVisitor() {
5656
return new JavaVisitor<ExecutionContext>() {
57-
private final JavaTemplate newLinkedList = template("new LinkedList<>()")
57+
private final JavaTemplate newLinkedList = JavaTemplate.builder(this::getCursor, "new LinkedList<>()")
5858
.imports("java.util.LinkedList")
5959
.build();
6060

61-
private final JavaTemplate newLinkedListIterable = template("new LinkedList<>(#{any(java.lang.Iterable)})")
61+
private final JavaTemplate newLinkedListIterable = JavaTemplate.builder(this::getCursor, "new LinkedList<>(#{any(java.lang.Iterable)})")
6262
.imports("java.util.LinkedList")
6363
.build();
6464

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaSetsNewConcurrentHashSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected TreeVisitor<?, ExecutionContext> getApplicableTest() {
4545
@Override
4646
protected TreeVisitor<?, ExecutionContext> getVisitor() {
4747
return new JavaVisitor<ExecutionContext>() {
48-
private final JavaTemplate newConcurrentHashSet = template("Collections.newSetFromMap(new ConcurrentHashMap<>())")
48+
private final JavaTemplate newConcurrentHashSet = JavaTemplate.builder(this::getCursor, "Collections.newSetFromMap(new ConcurrentHashMap<>())")
4949
.imports("java.util.Collections")
5050
.imports("java.util.concurrent.ConcurrentHashMap")
5151
.build();

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaSetsNewHashSet.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.openrewrite.ExecutionContext;
1919
import org.openrewrite.Recipe;
2020
import org.openrewrite.TreeVisitor;
21-
import org.openrewrite.java.JavaIsoVisitor;
2221
import org.openrewrite.java.JavaTemplate;
2322
import org.openrewrite.java.JavaVisitor;
2423
import org.openrewrite.java.MethodMatcher;
@@ -50,11 +49,11 @@ protected TreeVisitor<?, ExecutionContext> getApplicableTest() {
5049
@Override
5150
protected TreeVisitor<?, ExecutionContext> getVisitor() {
5251
return new JavaVisitor<ExecutionContext>() {
53-
private final JavaTemplate newHashSet = template("new HashSet<>()")
52+
private final JavaTemplate newHashSet = JavaTemplate.builder(this::getCursor, "new HashSet<>()")
5453
.imports("java.util.HashSet")
5554
.build();
5655

57-
private final JavaTemplate newHashSetIterable = template("new HashSet<>(#{any(java.lang.Iterable)})")
56+
private final JavaTemplate newHashSetIterable = JavaTemplate.builder(this::getCursor, "new HashSet<>(#{any(java.lang.Iterable)})")
5857
.imports("java.util.HashSet")
5958
.build();
6059

@@ -71,7 +70,7 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext execu
7170
method.getArguments().get(0));
7271
} else {
7372
maybeAddImport("java.util.Arrays");
74-
JavaTemplate newHashSetVarargs = template("new HashSet<>(Arrays.asList(" + method.getArguments().stream().map(a -> "#{any()}").collect(Collectors.joining(",")) + "))")
73+
JavaTemplate newHashSetVarargs = JavaTemplate.builder(this::getCursor, "new HashSet<>(Arrays.asList(" + method.getArguments().stream().map(a -> "#{any()}").collect(Collectors.joining(",")) + "))")
7574
.imports("java.util.Arrays")
7675
.imports("java.util.HashSet")
7776
.build();

src/main/java/org/openrewrite/java/migrate/guava/NoGuavaSetsNewLinkedHashSet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionCon
5656
@Override
5757
protected TreeVisitor<?, ExecutionContext> getVisitor() {
5858
return new JavaVisitor<ExecutionContext>() {
59-
private final JavaTemplate newLinkedHashSet = template("new LinkedHashSet<>()")
59+
private final JavaTemplate newLinkedHashSet = JavaTemplate.builder(this::getCursor, "new LinkedHashSet<>()")
6060
.imports("java.util.LinkedHashSet")
6161
.build();
6262

63-
private final JavaTemplate newLinkedHashSetIterable = template("new LinkedHashSet<>(#{any(java.lang.Iterable)})")
63+
private final JavaTemplate newLinkedHashSetIterable = JavaTemplate.builder(this::getCursor, "new LinkedHashSet<>(#{any(java.lang.Iterable)})")
6464
.imports("java.util.LinkedHashSet")
6565
.build();
6666

67-
private final JavaTemplate newLinkedHashSetCapacity = template("new LinkedHashSet<>(#{any(int)})")
67+
private final JavaTemplate newLinkedHashSetCapacity = JavaTemplate.builder(this::getCursor, "new LinkedHashSet<>(#{any(int)})")
6868
.imports("java.util.LinkedHashSet")
6969
.build();
7070

src/main/java/org/openrewrite/java/migrate/lang/MigrateClassLoaderDefineClass.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public String getDescription() {
3939
@Override
4040
protected TreeVisitor<?, ExecutionContext> getVisitor() {
4141
return new JavaIsoVisitor<ExecutionContext>() {
42-
final JavaTemplate template = template("null, #{anyArray(byte)}, #{any(int)}, #{any(int)}")
42+
final JavaTemplate template = JavaTemplate.builder(this::getCursor, "null, #{anyArray(byte)}, #{any(int)}, #{any(int)}")
4343
.build();
4444

4545
@Override

src/main/java/org/openrewrite/java/migrate/logging/MigrateGetLoggingMXBeanToGetPlatformMXBean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.openrewrite.Recipe;
2020
import org.openrewrite.TreeVisitor;
2121
import org.openrewrite.java.JavaIsoVisitor;
22+
import org.openrewrite.java.JavaTemplate;
2223
import org.openrewrite.java.MethodMatcher;
2324
import org.openrewrite.java.search.UsesMethod;
2425
import org.openrewrite.java.tree.J;
@@ -52,7 +53,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
5253
J.MethodInvocation m = method;
5354
if (MATCHER.matches(m)) {
5455
m = m.withTemplate(
55-
template("ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class)")
56+
JavaTemplate.builder(this::getCursor, "ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class)")
5657
.imports("java.lang.management.ManagementFactory", "java.lang.management.PlatformLoggingMXBean")
5758
.build(),
5859
m.getCoordinates().replace()

src/main/java/org/openrewrite/java/migrate/logging/MigrateLogRecordSetMillisToSetInstant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.openrewrite.Recipe;
2020
import org.openrewrite.TreeVisitor;
2121
import org.openrewrite.java.JavaIsoVisitor;
22+
import org.openrewrite.java.JavaTemplate;
2223
import org.openrewrite.java.MethodMatcher;
2324
import org.openrewrite.java.search.UsesMethod;
2425
import org.openrewrite.java.tree.J;
@@ -52,7 +53,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
5253
J.MethodInvocation m = method;
5354
if (MATCHER.matches(m)) {
5455
m = m.withName(m.getName().withName("setInstant")).withTemplate(
55-
template("Instant.ofEpochMilli(#{any(long)})")
56+
JavaTemplate.builder(this::getCursor, "Instant.ofEpochMilli(#{any(long)})")
5657
.imports("java.time.Instant")
5758
.build(),
5859
m.getCoordinates().replaceArguments(),

0 commit comments

Comments
 (0)