|
22 | 22 | import org.openrewrite.gradle.marker.GradleDependencyConfiguration; |
23 | 23 | import org.openrewrite.gradle.marker.GradleProject; |
24 | 24 | import org.openrewrite.gradle.trait.GradleMultiDependency; |
25 | | -import org.openrewrite.groovy.GroovyIsoVisitor; |
26 | | -import org.openrewrite.groovy.tree.G; |
27 | 25 | import org.openrewrite.internal.ListUtils; |
28 | 26 | import org.openrewrite.internal.StringUtils; |
| 27 | +import org.openrewrite.java.JavaIsoVisitor; |
29 | 28 | import org.openrewrite.java.tree.J; |
| 29 | +import org.openrewrite.java.tree.JavaSourceFile; |
30 | 30 | import org.openrewrite.semver.DependencyMatcher; |
31 | 31 |
|
32 | 32 | import java.util.HashMap; |
@@ -76,26 +76,28 @@ public Validated<Object> validate() { |
76 | 76 |
|
77 | 77 | @Override |
78 | 78 | public TreeVisitor<?, ExecutionContext> getVisitor() { |
79 | | - return Preconditions.check(new IsBuildGradle<>(), new GroovyIsoVisitor<ExecutionContext>() { |
| 79 | + return Preconditions.check(new IsBuildGradle<>(), new JavaIsoVisitor<ExecutionContext>() { |
80 | 80 | final DependencyMatcher depMatcher = requireNonNull(DependencyMatcher.build(groupId + ":" + artifactId).getValue()); |
81 | 81 |
|
82 | 82 | @SuppressWarnings("NotNullFieldNotInitialized") |
83 | 83 | GradleProject gradleProject; |
84 | 84 |
|
85 | 85 | @Override |
86 | | - public G.CompilationUnit visitCompilationUnit(G.CompilationUnit cu, ExecutionContext ctx) { |
87 | | - Optional<GradleProject> maybeGp = cu.getMarkers().findFirst(GradleProject.class); |
88 | | - if (!maybeGp.isPresent()) { |
89 | | - return cu; |
90 | | - } |
91 | | - |
92 | | - gradleProject = maybeGp.get(); |
93 | | - |
94 | | - G.CompilationUnit g = super.visitCompilationUnit(cu, ctx); |
95 | | - if (g != cu) { |
96 | | - g = g.withMarkers(g.getMarkers().setByType(updateGradleModel(gradleProject))); |
| 86 | + public @Nullable J visit(@Nullable Tree tree, ExecutionContext ctx) { |
| 87 | + if (tree instanceof JavaSourceFile) { |
| 88 | + JavaSourceFile sf = (JavaSourceFile) tree; |
| 89 | + Optional<GradleProject> maybeGp = sf.getMarkers().findFirst(GradleProject.class); |
| 90 | + if (maybeGp.isPresent()) { |
| 91 | + gradleProject = maybeGp.get(); |
| 92 | + J result = super.visit(tree, ctx); |
| 93 | + if (result != tree && result instanceof JavaSourceFile) { |
| 94 | + JavaSourceFile updated = (JavaSourceFile) result; |
| 95 | + return updated.withMarkers(updated.getMarkers().setByType(updateGradleModel(gradleProject))); |
| 96 | + } |
| 97 | + } |
| 98 | + return sf; |
97 | 99 | } |
98 | | - return g; |
| 100 | + return super.visit(tree, ctx); |
99 | 101 | } |
100 | 102 |
|
101 | 103 | @Override |
|
0 commit comments