Skip to content

Commit 3b2d847

Browse files
timtebeekTeamModerne
authored andcommitted
OpenRewrite recipe best practices
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices?organizationId=QUxML01vZGVybmUvTW9kZXJuZSArIE9wZW5SZXdyaXRl Co-authored-by: Moderne <team@moderne.io>
1 parent 2a0baac commit 3b2d847

4 files changed

Lines changed: 92 additions & 4 deletions

File tree

src/main/java/org/openrewrite/staticanalysis/SingleLineCommentSpacing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ public Space visitSpace(Space space, Space.Location loc, ExecutionContext ctx) {
6767
}
6868
};
6969
}
70-
}
70+
}

src/main/java/org/openrewrite/staticanalysis/UnnecessaryExplicitTypeArguments.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
package org.openrewrite.staticanalysis;
1717

1818
import lombok.Getter;
19+
import org.jspecify.annotations.Nullable;
1920
import org.openrewrite.*;
2021
import org.openrewrite.java.JavaIsoVisitor;
2122
import org.openrewrite.java.tree.*;
2223
import org.openrewrite.staticanalysis.java.JavaFileChecker;
2324

24-
import org.jspecify.annotations.Nullable;
25-
2625
import java.util.ArrayList;
2726
import java.util.List;
2827

src/main/resources/META-INF/rewrite/examples.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,6 +2770,29 @@ examples:
27702770
language: java
27712771
---
27722772
type: specs.openrewrite.org/v1beta/example
2773+
recipeName: org.openrewrite.staticanalysis.RemoveMethodsOnlyCallSuper
2774+
examples:
2775+
- description: '`RemoveMethodsOnlyCallSuperTest#removeVoidMethodOnlyCallingSuper`'
2776+
sources:
2777+
- before: |
2778+
class Child extends Parent {
2779+
@Override
2780+
void foo() {
2781+
super.foo();
2782+
}
2783+
}
2784+
after: |
2785+
class Child extends Parent {
2786+
}
2787+
language: java
2788+
- before: |
2789+
class Parent {
2790+
void foo() {
2791+
}
2792+
}
2793+
language: java
2794+
---
2795+
type: specs.openrewrite.org/v1beta/example
27732796
recipeName: org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof
27742797
examples:
27752798
- description: '`RemoveRedundantNullCheckBeforeInstanceofTest#removeRedundantNullCheck`'
@@ -2944,6 +2967,29 @@ examples:
29442967
language: java
29452968
---
29462969
type: specs.openrewrite.org/v1beta/example
2970+
recipeName: org.openrewrite.staticanalysis.RemoveUnusedLabels
2971+
examples:
2972+
- description: '`RemoveUnusedLabelsTest#unusedLabelOnForLoop`'
2973+
sources:
2974+
- before: |
2975+
class A {
2976+
void foo() {
2977+
label: for (int i = 0; i < 10; i++) {
2978+
System.out.println(i);
2979+
}
2980+
}
2981+
}
2982+
after: |
2983+
class A {
2984+
void foo() {
2985+
for (int i = 0; i < 10; i++) {
2986+
System.out.println(i);
2987+
}
2988+
}
2989+
}
2990+
language: java
2991+
---
2992+
type: specs.openrewrite.org/v1beta/example
29472993
recipeName: org.openrewrite.staticanalysis.RemoveUnusedLocalVariables
29482994
examples:
29492995
- description: '`RemoveUnusedLocalVariablesTest#removeUnusedLocalVariables`'
@@ -3661,6 +3707,25 @@ examples:
36613707
language: java
36623708
---
36633709
type: specs.openrewrite.org/v1beta/example
3710+
recipeName: org.openrewrite.staticanalysis.SillyEqualsCheck
3711+
examples:
3712+
- description: '`SillyEqualsCheckTest#replaceEqualsNullWithEqualityCheck`'
3713+
sources:
3714+
- before: |
3715+
class A {
3716+
boolean foo(String s) {
3717+
return s.equals(null);
3718+
}
3719+
}
3720+
after: |
3721+
class A {
3722+
boolean foo(String s) {
3723+
return s == null;
3724+
}
3725+
}
3726+
language: java
3727+
---
3728+
type: specs.openrewrite.org/v1beta/example
36643729
recipeName: org.openrewrite.staticanalysis.SimplifyArraysAsList
36653730
examples:
36663731
- description: '`SimplifyArraysAsListTest#simplifyStringArrayCreation`'
@@ -3997,6 +4062,27 @@ examples:
39974062
language: java
39984063
---
39994064
type: specs.openrewrite.org/v1beta/example
4065+
recipeName: org.openrewrite.staticanalysis.StaticAccessViaInstance
4066+
examples:
4067+
- description: '`StaticAccessViaInstanceTest#staticFieldViaInstance`'
4068+
sources:
4069+
- before: |
4070+
class MyClass {
4071+
static int COUNT = 0;
4072+
void foo(MyClass instance) {
4073+
int x = instance.COUNT;
4074+
}
4075+
}
4076+
after: |
4077+
class MyClass {
4078+
static int COUNT = 0;
4079+
void foo(MyClass instance) {
4080+
int x = MyClass.COUNT;
4081+
}
4082+
}
4083+
language: java
4084+
---
4085+
type: specs.openrewrite.org/v1beta/example
40004086
recipeName: org.openrewrite.staticanalysis.StaticMethodNotFinal
40014087
examples:
40024088
- description: '`StaticMethodNotFinalTest#removeFinalFromStaticMethods`'

src/test/java/org/openrewrite/staticanalysis/SingleLineCommentSpacingTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,19 @@
1616
package org.openrewrite.staticanalysis;
1717

1818
import org.junit.jupiter.api.Test;
19-
import static org.openrewrite.java.Assertions.java;
19+
import org.openrewrite.DocumentExample;
2020
import org.openrewrite.test.RewriteTest;
2121

22+
import static org.openrewrite.java.Assertions.java;
23+
2224
class SingleLineCommentSpacingTest implements RewriteTest {
2325

2426
@Override
2527
public void defaults(org.openrewrite.test.RecipeSpec spec) {
2628
spec.recipe(new SingleLineCommentSpacing());
2729
}
2830

31+
@DocumentExample
2932
@Test
3033
void addsSpaceAfterDoubleSlash() {
3134
rewriteRun(

0 commit comments

Comments
 (0)