Skip to content

Commit 87ebca8

Browse files
timtebeekTeamModerne
authored andcommitted
refactor: Inline local variable assignments before return/throw
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.staticanalysis.InlineVariable?organizationId=ODQ2MGExMTUtNDg0My00N2EwLTgzMGMtNGE1NGExMTBmZDkw Co-authored-by: Moderne <team@moderne.io>
1 parent 24c2390 commit 87ebca8

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/main/java/org/openrewrite/java/logging/slf4j/ChangeLogLevel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
9191
if (!StringUtils.isBlank(startsWith) && !lit.getValue().toString().startsWith(startsWith)) {
9292
return m;
9393
}
94-
m = (J.MethodInvocation) new ChangeMethodName(methodPattern, to.name().toLowerCase(), true, null)
94+
return (J.MethodInvocation) new ChangeMethodName(methodPattern, to.name().toLowerCase(), true, null)
9595
.getVisitor()
9696
.visitNonNull(m, ctx);
97-
return m;
9897
}
9998
});
10099
}

src/main/java/org/openrewrite/java/logging/slf4j/Slf4jLogShouldBeConstant.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,14 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
100100
if (TypeUtils.isAssignableTo(JavaType.ShallowClass.build("java.lang.Throwable"), valueOf.getType())) {
101101
J.MethodInvocation m = JavaTemplate.builder("\"Exception\", #{any()}").contextSensitive().build()
102102
.apply(getCursor(), method.getCoordinates().replaceArguments(), valueOf);
103-
m = m.withSelect(method.getSelect());
104-
return m;
103+
return m.withSelect(method.getSelect());
105104
}
106105
} else if (OBJECT_TO_STRING.matches(args.get(0))) {
107106
Expression toString = ((J.MethodInvocation) args.get(0)).getSelect();
108107
if (toString != null) {
109108
J.MethodInvocation m = JavaTemplate.builder("\"{}\", #{any()}").contextSensitive().build()
110109
.apply(getCursor(), method.getCoordinates().replaceArguments(), toString);
111-
m = m.withSelect(method.getSelect());
112-
return m;
110+
return m.withSelect(method.getSelect());
113111
}
114112
}
115113
}

0 commit comments

Comments
 (0)