Skip to content

Commit

Permalink
Don't use lambdas for methods with type parameters. (#310)
Browse files Browse the repository at this point in the history
See the re-enabled testcase.
Fixes #309
  • Loading branch information
mbruggmann authored Jul 4, 2024
1 parent d5a3753 commit fc7ed29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
StringBuilder templateBuilder = new StringBuilder();
J.MethodDeclaration methodDeclaration = (J.MethodDeclaration) n.getBody().getStatements().get(0);

// If the functional interface method has type parameters, we can't replace it with a lambda.
if (methodDeclaration.getTypeParameters() != null && !methodDeclaration.getTypeParameters().isEmpty()) {
return n;
}

if (methodDeclaration.getParameters().get(0) instanceof J.Empty) {
templateBuilder.append("() -> {");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ public MapDropdownChoice(Supplier<? extends Map<K, ? extends V>> choiceMap) {
);
}

@Disabled
@Test
@Issue("https://github.com/openrewrite/rewrite-static-analysis/issues/309")
void dontUseLambdaForMethodWithTypeParameter() {
Expand Down

0 comments on commit fc7ed29

Please sign in to comment.