Skip to content

Commit

Permalink
Harmonize JavaParser classpath setup (#342)
Browse files Browse the repository at this point in the history
* Harmonize `JavaParser` classpath setup

* Is only `JUnitAssertArrayEqualsToAssertThatTest` a problem?

* Always use major and minor version

* Enable `JUnitAssertArrayEqualsToAssertThatTest` again
  • Loading branch information
knutwannheden authored May 23, 2023
1 parent 60c9393 commit 53cfd4c
Show file tree
Hide file tree
Showing 99 changed files with 122 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static class AssertArrayEqualsToAssertThatVisitor extends JavaIsoVisitor<
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static class AssertEqualsToAssertThatVisitor extends JavaIsoVisitor<Execu
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.+")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class AssertFalseToAssertThatVisitor extends JavaIsoVisitor<Execut
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static class AssertNotEqualsToAssertThatVisitor extends JavaIsoVisitor<Ex
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class AssertNotNullToAssertThatVisitor extends JavaIsoVisitor<Exec
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static class AssertNullToAssertThatVisitor extends JavaIsoVisitor<Executi
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class AssertSameToAssertThatVisitor extends JavaIsoVisitor<Executi
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static class AssertExceptionTypeVisitor extends JavaIsoVisitor<Execution
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static class AssertTrueToAssertThatVisitor extends JavaIsoVisitor<Executi
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static class JUnitFailToAssertJFailVisitor extends JavaIsoVisitor<Executi
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down Expand Up @@ -147,7 +147,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
method = method.withTemplate(JavaTemplate.builder(this::getCursor, templateBuilder.toString())
.staticImports("org.assertj.core.api.Assertions" + ".fail")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2"))
.classpathFromResources(ctx, "assertj-core-3.24"))
.build(),
method.getCoordinates().replace(),
arguments.toArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static class UseExplicitContainsVisitor extends JavaIsoVisitor<ExecutionC
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static class UseExplicitSizeVisitor extends JavaIsoVisitor<ExecutionConte
private Supplier<JavaParser> assertionsParser(ExecutionContext ctx) {
if(assertionsParser == null) {
assertionsParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "assertj-core-3.24.2")
.classpathFromResources(ctx, "assertj-core-3.24")
.build();
}
return assertionsParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected JavaVisitor<ExecutionContext> getVisitor() {
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static class TestShouldIncludeAssertionsVisitor extends JavaIsoVisitor<E
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
private JavaTemplate getNestedJavaTemplate(ExecutionContext ctx) {
return JavaTemplate.builder(this::getCursor, "@Nested")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2"))
.classpathFromResources(ctx, "junit-jupiter-api-5.9"))
.imports(NESTED)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
private JavaTemplate getNestedJavaTemplate(ExecutionContext ctx) {
return JavaTemplate.builder(this::getCursor, "@Nested")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2"))
.classpathFromResources(ctx, "junit-jupiter-api-5.9"))
.imports(NESTED)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static class ExpectedExceptionToAssertThrowsVisitor extends JavaIsoVisito
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2", "hamcrest-2.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9", "hamcrest-2.2")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static class ParametersNoArgsImplicitMethodSource extends JavaIsoVisitor
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2", "hamcrest-2.2", "junit-jupiter-params-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9", "hamcrest-2.2", "junit-jupiter-params-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private J.MethodDeclaration updateMethodDeclarationAnnotationAndModifier(J.Metho
if (FindAnnotations.find(methodDeclaration.withBody(null), "@" + fullyQualifiedAnnotation).isEmpty()) {
md = methodDeclaration.withTemplate(JavaTemplate.builder(this::getCursor, annotation)
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2"))
.classpathFromResources(ctx, "junit-jupiter-api-5.9"))
.imports(fullyQualifiedAnnotation).build(),
methodDeclaration.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName)));
md = maybeAddPublicModifier(md);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
cd = cd.withTemplate(
JavaTemplate.builder(this::getCursor, "@ExtendWith(MockitoExtension.class)")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2", "mockito-junit-jupiter-3.12.4"))
.classpathFromResources(ctx, "junit-jupiter-api-5.9", "mockito-junit-jupiter-3.12"))
.imports("org.junit.jupiter.api.extension.ExtendWith", "org.mockito.junit.jupiter.MockitoExtension")
.build(),
cd.getCoordinates().addAnnotation(Comparator.comparing(J.Annotation::getSimpleName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public ParameterizedRunnerToParameterizedTestsVisitor(J.ClassDeclaration scope,
"@ParameterizedTest";

JavaParser.Builder<?, ?> javaParserBuilder = JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2", "junit-jupiter-params-5.9.2");
.classpathFromResources(ctx, "junit-jupiter-api-5.9", "junit-jupiter-params-5.9");

this.parameterizedTestTemplate = JavaTemplate.builder(this::getCursor, parameterizedTestAnnotationTemplate)
.javaParser(javaParserBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private JavaTemplate getExtendsWithTemplate(ExecutionContext ctx) {
if (extendsWithTemplate == null) {
extendsWithTemplate = JavaTemplate.builder(this::getCursor, "@ExtendWith(#{}.class)")
.javaParser(JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.dependsOn( "package " + extensionType.getPackageName() + ";\n" +
"import org.junit.jupiter.api.extension.Extension;\n" +
"public class " + extensionType.getClassName() + " implements Extension {}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
private JavaParser.Builder<?, ?> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
javaParser = JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2");
.classpathFromResources(ctx, "junit-jupiter-api-5.9");
}
return javaParser;

Expand Down Expand Up @@ -163,7 +163,7 @@ private static class AddNewFolderMethod extends JavaIsoVisitor<ExecutionContext>
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down Expand Up @@ -223,7 +223,7 @@ private static class TranslateNewFolderMethodInvocation extends JavaVisitor<Exec
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if (javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static class TestRuleToTestInfoVisitor extends JavaIsoVisitor<ExecutionC
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down Expand Up @@ -167,7 +167,7 @@ private static class BeforeMethodToTestInfoVisitor extends JavaIsoVisitor<Execut
private Supplier<JavaParser> javaParser(ExecutionContext ctx) {
if(javaParser == null) {
javaParser = () -> JavaParser.fromJavaVersion()
.classpathFromResources(ctx, "junit-jupiter-api-5.9.2")
.classpathFromResources(ctx, "junit-jupiter-api-5.9")
.build();
}
return javaParser;
Expand Down
Loading

0 comments on commit 53cfd4c

Please sign in to comment.