Skip to content

Commit 62511c7

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 <[email protected]>
1 parent 32f5aea commit 62511c7

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

src/main/java/org/openrewrite/java/spring/boot2/ChangeEmbeddedServletContainerCustomizer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
5050
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
5151
J.ClassDeclaration c = super.visitClassDeclaration(classDecl, ctx);
5252

53-
c = c.withImplements(
53+
return c.withImplements(
5454
ListUtils.map(c.getImplements(), i -> {
5555
if (TypeUtils.isOfClassType(i.getType(), DEPRECATED_INTERFACE_FQN)) {
5656
maybeAddImport("org.springframework.boot.web.server.WebServerFactoryCustomizer");
@@ -61,8 +61,6 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
6161
return i;
6262
})
6363
);
64-
65-
return c;
6664
}
6765

6866
private J.ParameterizedType getWebFactoryCustomizerIdentifier(ExecutionContext ctx) {

src/main/java/org/openrewrite/java/spring/boot2/OutputCaptureExtension.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
142142
.javaParser(JavaParser.fromJavaVersion()
143143
.classpathFromResources(ctx, "spring-boot-test-2.*", "junit-jupiter-api-5.*"))
144144
.build();
145-
m = matchesTemplate.apply(getCursor(), m.getCoordinates().replace(), m.getArguments().get(0), variableName);
146-
return m;
145+
return matchesTemplate.apply(getCursor(), m.getCoordinates().replace(), m.getArguments().get(0), variableName);
147146
}
148147
}
149148

src/main/java/org/openrewrite/java/spring/util/concurrent/ListenableToCompletableFuture.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public J.CompilationUnit visitCompilationUnit(J.CompilationUnit compilationUnit,
3030
cu = (J.CompilationUnit) new ChangeMethodName(
3131
"org.springframework.util.concurrent.ListenableFuture addCallback(..)", "whenComplete", true, true)
3232
.getVisitor().visit(cu, ctx, getCursor().getParent());
33-
cu = (J.CompilationUnit) new ChangeType(
33+
return (J.CompilationUnit) new ChangeType(
3434
"org.springframework.util.concurrent.ListenableFuture",
3535
"java.util.concurrent.CompletableFuture", null)
3636
.getVisitor().visit(cu, ctx, getCursor().getParent());
37-
return cu;
3837
}
3938
}

0 commit comments

Comments
 (0)