Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 committed Dec 18, 2023
1 parent f81c88b commit d640a18
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 24 deletions.
1 change: 0 additions & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--batch-mode
--errors
--strict-checksums
-Dstyle.color=always
7 changes: 1 addition & 6 deletions error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-11</artifactId>
<scope>provided</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
Expand Down Expand Up @@ -271,11 +271,6 @@
<artifactId>refaster-support</artifactId>
<version>${project.version}</version>
</path>
<path>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<version>${version.rewrite-templating}</version>
</path>
</annotationProcessorPaths>
<compilerArgs combine.children="append">
<arg>-Xplugin:RefasterRuleCompiler</arg>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package tech.picnic.errorprone.refasterrules;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.openrewrite.java.Assertions.java;

import com.google.errorprone.FileObjects;
import com.google.common.io.Resources;
import java.io.IOException;
import javax.tools.JavaFileObject;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

// XXX: This class currently validates the OpenRewrite recipe generation by applying a single
// recipe. Generalize this setup to cover all generated recipes (for _all_ Refaster rule
// collections), ideally by reusing the `RefasterRulesTest` test resources. (This may introduce
// additional hurdles, as OpenRewrite removes obsolete imports, while Refaster doesn't.)
final class StringRulesRecipesTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
Expand All @@ -21,30 +25,32 @@ public void defaults(RecipeSpec spec) {
void stringValueOf() {
// XXX: Use text blocks once supported.
rewriteRun(
// language=java
java(
"import java.util.Objects;\n"
+ '\n'
+ "class Test {\n"
+ " String test(Object object) {\n"
+ " return Objects.toString(object);\n"
+ " }\n"
+ "}",
+ " String test(Object object) {\n"
+ " return Objects.toString(object);\n"
+ " }\n"
+ '}',
"class Test {\n"
+ " String test(Object object) {\n"
+ " return String.valueOf(object);\n"
+ " }\n"
+ "}"));
+ " String test(Object object) {\n"
+ " return String.valueOf(object);\n"
+ " }\n"
+ '}'));
}

@Test
@Disabled("Not all rules are currently supported")
void reuseStringRulesTestInputOutput() throws IOException {
String rule = "StringRules";
JavaFileObject before = FileObjects.forResource(getClass(), rule + "TestInput.java");
JavaFileObject after = FileObjects.forResource(getClass(), rule + "TestOutput.java");
@Test
void allRules() throws IOException {
rewriteRun(
spec ->
spec.parser(JavaParser.fromJavaVersion().classpath("guava", "refaster-test-support")),
java(before.getCharContent(true).toString(), after.getCharContent(true).toString()));
java(
loadResource("StringRulesTestInput.java"), loadResource("StringRulesTestOutput.java")));
}

private String loadResource(String resource) throws IOException {
return Resources.toString(Resources.getResource(getClass(), resource), UTF_8);
}
}
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@
</exclusion>
</exclusions>
</dependency>
<!-- Specified as a workaround for
https://github.com/mojohaus/versions-maven-plugin/issues/244. -->
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<version>${version.rewrite-templating}</version>
</dependency>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-recipe-bom</artifactId>
Expand Down Expand Up @@ -943,6 +950,11 @@
<artifactId>mockito-errorprone</artifactId>
<version>${version.mockito}</version>
</path>
<path>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<version>${version.rewrite-templating}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
Expand Down
15 changes: 15 additions & 0 deletions refaster-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
15 changes: 15 additions & 0 deletions refaster-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down

0 comments on commit d640a18

Please sign in to comment.