Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert additional lambdas to expressions based on number of args #329

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private static boolean hasMethodOverloading(J.MethodInvocation method) {
// TODO this is actually more complex in the presence of generics and inheritance
static boolean hasMethodOverloading(JavaType.Method methodType) {
String methodName = methodType.getName();
int numberOfParameters = methodType.getParameterNames().size();
return Optional.of(methodType)
.map(JavaType.Method::getDeclaringType)
.filter(JavaType.Class.class::isInstance)
Expand All @@ -97,7 +98,8 @@ static boolean hasMethodOverloading(JavaType.Method methodType) {
.map(methods -> {
int overloadingCount = 0;
for (JavaType.Method dm : methods) {
if (dm.getName().equals(methodName)) {
if (methodName.equals(dm.getName()) &&
numberOfParameters == dm.getParameterNames().size()) {
if (++overloadingCount > 1) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Test {
"""
import java.util.function.Function;
class Test {
Function<Integer, Integer> f = n ->
Function<Integer, Integer> f = n ->
// The buttonType will always be "cancel", even if we pressed one of the entry type buttons
n + 1;
}
Expand Down Expand Up @@ -145,4 +145,41 @@ public void run() {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/pull/582")
void simplifyAssertThrows() {
rewriteRun(
spec-> spec.parser(JavaParser.fromJavaVersion().classpath("junit")),
//language=java
java(
"""
import static org.junit.jupiter.api.Assertions.assertThrows;

class Test {
void test() {
assertThrows(IllegalArgumentException.class, () -> {
foo();
});
}
void foo() {
throw new IllegalArgumentException("boom");
}
}
""",
"""
import static org.junit.jupiter.api.Assertions.assertThrows;

class Test {
void test() {
assertThrows(IllegalArgumentException.class, () ->
foo());
}
void foo() {
throw new IllegalArgumentException("boom");
}
}
"""
)
);
}
}
Loading