mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Derive OpenRewrite recipes from a subset of Refaster rules (#925)
Using OpenRewrite's `rewrite-templating` annotation processor, Refaster rules are now converted into matching recipes and bundled as part of the `error-prone-contrib` artifact. Note that not all rules are supported yet.
This commit is contained in:
@@ -60,7 +60,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<scope>test</scope>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.auto</groupId>
|
||||
@@ -181,6 +181,31 @@
|
||||
<artifactId>mongodb-driver-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-java</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-java-11</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-templating</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reactivestreams</groupId>
|
||||
<artifactId>reactive-streams</artifactId>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package tech.picnic.errorprone.refasterrules;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.openrewrite.java.Assertions.java;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import java.io.IOException;
|
||||
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) {
|
||||
spec.recipe(new StringRulesRecipes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringValueOf() {
|
||||
// XXX: Use text blocks once supported.
|
||||
rewriteRun(
|
||||
java(
|
||||
"import java.util.Objects;\n"
|
||||
+ '\n'
|
||||
+ "class Test {\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"
|
||||
+ '}'));
|
||||
}
|
||||
|
||||
@Disabled("Not all rules are currently supported")
|
||||
@Test
|
||||
void allRules() throws IOException {
|
||||
rewriteRun(
|
||||
spec ->
|
||||
spec.parser(JavaParser.fromJavaVersion().classpath("guava", "refaster-test-support")),
|
||||
java(
|
||||
loadResource("StringRulesTestInput.java"), loadResource("StringRulesTestOutput.java")));
|
||||
}
|
||||
|
||||
private String loadResource(String resource) throws IOException {
|
||||
return Resources.toString(Resources.getResource(getClass(), resource), UTF_8);
|
||||
}
|
||||
}
|
||||
45
pom.xml
45
pom.xml
@@ -451,6 +451,18 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-templating</artifactId>
|
||||
<version>1.3.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openrewrite.recipe</groupId>
|
||||
<artifactId>rewrite-recipe-bom</artifactId>
|
||||
<version>2.5.4</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-bom</artifactId>
|
||||
@@ -891,6 +903,10 @@
|
||||
<groupId>com.google.auto.service</groupId>
|
||||
<artifactId>auto-service</artifactId>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.openrewrite</groupId>
|
||||
<artifactId>rewrite-templating</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs>
|
||||
<arg>--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
|
||||
@@ -1167,12 +1183,15 @@
|
||||
non-distributed (i.e. Picnic-internal) deployable
|
||||
artifacts (i.e. web services). -->
|
||||
<includedLicense>Apache-2.0</includedLicense>
|
||||
<includedLicense>BSD-2-Clause</includedLicense>
|
||||
<includedLicense>BSD-3-Clause</includedLicense>
|
||||
<includedLicense>CC0-1.0</includedLicense>
|
||||
<includedLicense>CDDL-1.1</includedLicense>
|
||||
<includedLicense>EPL-1.0</includedLicense>
|
||||
<includedLicense>EPL-2.0</includedLicense>
|
||||
<includedLicense>GPL-2.0-with-classpath-exception</includedLicense>
|
||||
<includedLicense>ICU</includedLicense>
|
||||
<includedLicense>LGPL-2.1+</includedLicense>
|
||||
<includedLicense>LGPL-3.0+</includedLicense>
|
||||
<includedLicense>MIT</includedLicense>
|
||||
<includedLicense>MIT-0</includedLicense>
|
||||
@@ -1195,10 +1214,20 @@
|
||||
| The Apache Software License, Version 2.0
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- -->
|
||||
<!-- XXX: Get projects referencing just "BSD"
|
||||
to explicitly state the clause count. -->
|
||||
BSD-2-Clause
|
||||
| The BSD License
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- XXX: Get projects referencing just "BSD"
|
||||
to explicitly state the clause count. -->
|
||||
BSD-3-Clause
|
||||
| 3-Clause BSD License
|
||||
| BSD 3-clause
|
||||
| BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
|
||||
<!-- XXX: Typo; file ticket. -->
|
||||
| BSD licence
|
||||
| BSD License 3
|
||||
| Eclipse Distribution License (New BSD License)
|
||||
| New BSD License
|
||||
@@ -1207,6 +1236,7 @@
|
||||
<!-- -->
|
||||
CC0-1.0
|
||||
| CC0
|
||||
| Public Domain, per Creative Commons CC0
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- -->
|
||||
@@ -1225,6 +1255,12 @@
|
||||
EPL-2.0
|
||||
| Eclipse Public License - v 2.0
|
||||
| Eclipse Public License v2.0
|
||||
| EPL 2.0
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- -->
|
||||
ICU
|
||||
| Unicode/ICU License
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- -->
|
||||
@@ -1236,6 +1272,12 @@
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- -->
|
||||
LGPL-2.1+
|
||||
| LGPL-2.1-or-later
|
||||
</licenseMerge>
|
||||
<licenseMerge>
|
||||
<!-- XXX: Get projects referencing just "LGPL"
|
||||
to explicitly state the license version. -->
|
||||
LGPL-3.0+
|
||||
| GNU Lesser Public License
|
||||
</licenseMerge>
|
||||
@@ -1245,6 +1287,7 @@
|
||||
| MIT license
|
||||
| MIT License
|
||||
| The MIT License
|
||||
| The MIT License (MIT)
|
||||
</licenseMerge>
|
||||
</licenseMerges>
|
||||
<!-- Nearly no projects ship a "missing third party
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user