Skip to content

Commit d270d8a

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

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ private J.VariableDeclarations maybeAddTypeExpression(J.VariableDeclarations mul
188188
currentType = ((JavaType.Array) currentType).getElemType();
189189
}
190190
return result;
191-
} else if (type instanceof JavaType.Variable) {
191+
}
192+
if (type instanceof JavaType.Variable) {
192193
return buildTypeTree(((JavaType.Variable) type).getType(), space);
193-
} else if (type instanceof JavaType.GenericTypeVariable) {
194+
}
195+
if (type instanceof JavaType.GenericTypeVariable) {
194196
JavaType.GenericTypeVariable genericType = (JavaType.GenericTypeVariable) type;
195197

196198
if (!genericType.getName().equals("?")) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,14 @@ static J.MemberReference newInstanceMethodReference(Expression containing, Strin
162162
}
163163
if (type instanceof JavaType.GenericTypeVariable) {
164164
return getClassType(((JavaType.GenericTypeVariable) type).getBounds().get(0));
165-
} else if (type instanceof JavaType.Array) {
165+
}
166+
if (type instanceof JavaType.Array) {
166167
return getClassType(((JavaType.Array) type).getElemType());
167-
} else if (type instanceof JavaType.Variable) {
168+
}
169+
if (type instanceof JavaType.Variable) {
168170
return getClassType(((JavaType.Variable) type).getOwner());
169-
} else if (type instanceof JavaType.Method) {
171+
}
172+
if (type instanceof JavaType.Method) {
170173
return getClassType(((JavaType.Method) type).getDeclaringType());
171174
}
172175
return null;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3536,6 +3536,32 @@ examples:
35363536
language: java
35373537
---
35383538
type: specs.openrewrite.org/v1beta/example
3539+
recipeName: org.openrewrite.staticanalysis.UnwrapElseAfterReturn
3540+
examples:
3541+
- description: ''
3542+
sources:
3543+
- before: |
3544+
class Test {
3545+
int foo(boolean condition) {
3546+
if (condition) {
3547+
return 1;
3548+
} else {
3549+
return 2;
3550+
}
3551+
}
3552+
}
3553+
after: |
3554+
class Test {
3555+
int foo(boolean condition) {
3556+
if (condition) {
3557+
return 1;
3558+
}
3559+
return 2;
3560+
}
3561+
}
3562+
language: java
3563+
---
3564+
type: specs.openrewrite.org/v1beta/example
35393565
recipeName: org.openrewrite.staticanalysis.UnwrapRepeatableAnnotations
35403566
examples:
35413567
- description: ''

0 commit comments

Comments
 (0)