Skip to content

Commit 581944e

Browse files
committed
MethodMatcher: Optimize parameters case (..)
Using `(..)` to match any parameters is very common for `MethodMatchers`. This case is now correctly optimized, as there was a bug in `matchAllArguments()`.
1 parent b09b22f commit 581944e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public MethodMatcher(String signature, @Nullable Boolean matchOverrides) {
9191
this(signature, Boolean.TRUE.equals(matchOverrides));
9292
}
9393

94-
public @Nullable MethodMatcher(String signature, boolean matchOverrides) {
94+
public MethodMatcher(String signature, boolean matchOverrides) {
9595
this.matchOverrides = matchOverrides;
9696

9797
MethodSignatureParser parser = new MethodSignatureParser(new CommonTokenStream(new MethodSignatureLexer(
@@ -138,7 +138,7 @@ public MethodMatcher(String signature, @Nullable Boolean matchOverrides) {
138138
}
139139

140140
private static boolean matchAllArguments(MethodSignatureParser.FormalsPatternContext context) {
141-
return context.dotDot() != null && context.formalsPatternAfterDotDot() == null;
141+
return context.dotDot() != null && context.formalsPatternAfterDotDot().isEmpty();
142142
}
143143

144144
private static boolean isPlainIdentifier(MethodSignatureParser.TargetTypePatternContext context) {
@@ -344,6 +344,10 @@ private boolean matchesAllowingUnknownTypes(J.MethodInvocation method) {
344344
return false;
345345
}
346346

347+
if (argumentPattern == ANY_ARGUMENTS_PATTERN) {
348+
return true;
349+
}
350+
347351
final String argumentSignature = argumentsFromExpressionTypes(method);
348352
final Pattern relaxedArgumentPattern = Pattern.compile(
349353
argumentPattern.pattern().replaceAll("((?:[a-zA-Z0-9]+\\.?)+)",

0 commit comments

Comments
 (0)