Skip to content

Commit

Permalink
Drop unnecessary visitReturn
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Sep 19, 2024
1 parent cff5324 commit 13cd2e0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,6 @@ public J.Identifier visitIdentifier(J.Identifier identifier, ExecutionContext ct
}
return super.visitIdentifier(ident, ctx);
}

@Override
public J.Return visitReturn(J.Return _return, ExecutionContext ctx) {
J.Return r = super.visitReturn(_return, ctx);
J.MethodDeclaration method = getCursor().firstEnclosing(J.MethodDeclaration.class);
if (r.getExpression() instanceof J.MethodInvocation) {
J.MethodInvocation returnMethod = (J.MethodInvocation) r.getExpression();
if (returnMethod.getSelect() instanceof J.Identifier) {
J.Identifier returnSelect = (J.Identifier) returnMethod.getSelect();
if (returnMethod.getMethodType() != null) {
if (method != null && returnSelect.getSimpleName().equals("super") && TypeUtils.isAssignableTo(RESPONSE_ENTITY_EXCEPTION_HANDLER_FQ, returnMethod.getMethodType().getDeclaringType())) {
List<Expression> expressions = ListUtils.map(((J.MethodInvocation) r.getExpression()).getArguments(), (index, arg) -> {
if (arg instanceof J.Identifier) {
J.Identifier ident = (J.Identifier) arg;
Statement methodArg = method.getParameters().get(index);
if (methodArg instanceof J.VariableDeclarations) {
J.VariableDeclarations vd = (J.VariableDeclarations) methodArg;
if (ident.getSimpleName().equals(vd.getVariables().get(0).getSimpleName())) {
if (!TypeUtils.isOfType(ident.getType(), vd.getVariables().get(0).getType())) {
return ident.withType(vd.getVariables().get(0).getType());
}
}
}
}
return arg;
});
return maybeAutoFormat(_return, r.withExpression((((J.MethodInvocation) r.getExpression()).withArguments(expressions))), ctx);
}
}
}
}
return super.visitReturn(_return, ctx);
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object bo
return super.handleExceptionInternal(ex, body, headers, status, request);
}
}
""",
spec -> spec.afterRecipe(cu -> {

J.MethodDeclaration md = (J.MethodDeclaration) cu.getClasses().get(0).getBody().getStatements().get(0);
List<Statement> parameters = md.getParameters();
})
"""
)
);
}
Expand Down

0 comments on commit 13cd2e0

Please sign in to comment.