Skip to content

Commit 758e7cf

Browse files
committed
fix build & tests
1 parent 172f644 commit 758e7cf

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/main/java/org/openrewrite/staticanalysis/LambdaBlockToExpression.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,22 @@ private static boolean hasLambdaArgument(J.MethodInvocation method) {
9292
return hasLambdaArgument;
9393
}
9494

95-
// Check whether a method has overloading methods in the declaring class
96-
static boolean hasAmbiguousMethodOverloading(J.MethodInvocation method) {
95+
// Check whether a method has overloading methods in the declaring class
96+
private static boolean hasAmbiguousMethodOverloading(J.MethodInvocation method) {
9797
JavaType.Method methodType = method.getMethodType();
98+
String methodName = methodType.getName();
99+
return methodType != null && hasAmbiguousMethodOverloading(methodType, method.getArguments(), methodName);
100+
}
98101

99-
if(methodType == null) {
100-
return false;
101-
}
102-
int numberOfArguments = method.getArguments().size();
102+
static boolean hasAmbiguousMethodOverloading(MethodCall method) {
103+
JavaType.Method methodType = method.getMethodType();
104+
String methodName = methodType.getName();
105+
return methodType != null && hasAmbiguousMethodOverloading(methodType, method.getArguments(), methodName);
106+
}
103107

104108
// TODO this is actually more complex in the presence of generics and inheritance
105-
String methodName = methodType.getName();
109+
static boolean hasAmbiguousMethodOverloading(JavaType.Method methodType, List<Expression> arguments, String methodName) {
110+
int numberOfArguments = arguments.size();
106111

107112
//all methods of the given type
108113
List<JavaType.Method> methodsOfType = Optional.of(methodType)
@@ -128,7 +133,7 @@ static boolean hasAmbiguousMethodOverloading(J.MethodInvocation method) {
128133
// then there is no ambiguity
129134
for (int i = 0; i < numberOfArguments; i++) {
130135
int finalI = i;
131-
if (method.getArguments().get(i) instanceof J.Lambda) {
136+
if (arguments.get(i) instanceof J.Lambda) {
132137
long distinctElementsCount = potentiallyOverLoadedMethods.stream()
133138
.map(m -> m.getParameterTypes().get(finalI))
134139
.distinct().count();

src/main/java/org/openrewrite/staticanalysis/RemoveRedundantTypeCast.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.List;
2525
import java.util.Set;
2626

27-
import static org.openrewrite.staticanalysis.LambdaBlockToExpression.hasMethodOverloading;
27+
import static org.openrewrite.staticanalysis.LambdaBlockToExpression.hasAmbiguousMethodOverloading;
2828

2929
@Incubating(since = "7.23.0")
3030
public class RemoveRedundantTypeCast extends Recipe {
@@ -74,8 +74,7 @@ public J visitTypeCast(J.TypeCast typeCast, ExecutionContext ctx) {
7474
} else if (parentValue instanceof MethodCall) {
7575
MethodCall methodCall = (MethodCall) parentValue;
7676
JavaType.Method methodType = methodCall.getMethodType();
77-
int numberOfArguments = methodCall.getArguments().size();
78-
if (methodType == null || hasMethodOverloading(methodType, numberOfArguments)) {
77+
if (methodType == null || hasAmbiguousMethodOverloading(methodCall)) {
7978
return visited;
8079
} else if (!methodType.getParameterTypes().isEmpty()) {
8180
List<Expression> arguments = methodCall.getArguments();

0 commit comments

Comments
 (0)