org.openrewrite.java.recipes.SelectRecipeExamples
Add @DocumentExample
to the first non-issue and not a disabled unit test of a recipe as an example, if there are not any examples yet.
GitHub, Issue Tracker, Maven Central
- groupId: org.openrewrite
- artifactId: rewrite-java
- version: 8.1.3
{% tabs %} {% tab title="org/openrewrite/java/cleanup/UnnecessaryParenthesesTest.java" %}
{% code title="org/openrewrite/java/cleanup/UnnecessaryParenthesesTest.java" %}
package org.openrewrite.java.cleanup;
import org.junit.jupiter.api.Test;
import org.openrewrite.Recipe;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import static org.openrewrite.java.Assertions.java;
class UnnecessaryParenthesesTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
Recipe recipe = new UnnecessaryParentheses();
spec.recipe(recipe);
}
@Test
void test1() {
rewriteRun(
java(
"""
BEFORE
""",
"""
AFTER
"""
)
);
}
@Test
void test2() {
rewriteRun(
java(
"""
BEFORE
""",
"""
AFTER
"""
)
);
}
}
{% endcode %}
{% code title="org/openrewrite/java/cleanup/UnnecessaryParenthesesTest.java" %}
package org.openrewrite.java.cleanup;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Recipe;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import static org.openrewrite.java.Assertions.java;
class UnnecessaryParenthesesTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
Recipe recipe = new UnnecessaryParentheses();
spec.recipe(recipe);
}
@DocumentExample
@Test
void test1() {
rewriteRun(
java(
"""
BEFORE
""",
"""
AFTER
"""
)
);
}
@Test
void test2() {
rewriteRun(
java(
"""
BEFORE
""",
"""
AFTER
"""
)
);
}
}
{% endcode %}
{% endtab %} {% tab title="Diff" %} {% code %}
--- org/openrewrite/java/cleanup/UnnecessaryParenthesesTest.java
+++ org/openrewrite/java/cleanup/UnnecessaryParenthesesTest.java
@@ -4,0 +4,1 @@
import org.junit.jupiter.api.Test;
+import org.openrewrite.DocumentExample;
import org.openrewrite.Recipe;
@@ -17,0 +18,1 @@
}
+ @DocumentExample
@Test
{% endcode %} {% endtab %} {% endtabs %}
This recipe has no required configuration parameters and comes from a rewrite core library. It can be activated directly without adding any dependencies. {% tabs %} {% tab title="Gradle" %} {% code title="build.gradle" %}
plugins {
id("org.openrewrite.rewrite") version("6.1.4")
}
rewrite {
activeRecipe("org.openrewrite.java.recipes.SelectRecipeExamples")
}
repositories {
mavenCentral()
}
{% endcode %} {% endtab %} {% tab title="Maven POM" %} {% code title="pom.xml" %}
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>5.2.4</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.recipes.SelectRecipeExamples</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
{% endcode %} {% endtab %}
{% tab title="Maven Command Line" %} You will need to have Maven installed on your machine before you can run the following command. {% code title="shell" %}
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.activeRecipes=org.openrewrite.java.recipes.SelectRecipeExamples
{% endcode %} {% endtab %} {% endtabs %}
The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.