From 24459b9d441a849f62cf6e4c7ec7894b2ac7647b Mon Sep 17 00:00:00 2001
From: Jente Sondervorst
Date: Wed, 30 Jul 2025 13:53:19 +0200
Subject: [PATCH 1/5] Fixed wildcard matching for elements with type
information.
---
.../openrewrite/java/MethodMatcherTest.java | 13 +
.../src/main/antlr/MethodSignatureParser.g4 | 7 +-
.../org/openrewrite/java/MethodMatcher.java | 13 +
.../grammar/MethodSignatureParser.interp | 3 +-
.../grammar/MethodSignatureParser.java | 581 ++++++++++--------
.../MethodSignatureParserBaseListener.java | 12 +
.../MethodSignatureParserBaseVisitor.java | 7 +
.../MethodSignatureParserListener.java | 10 +
.../grammar/MethodSignatureParserVisitor.java | 6 +
9 files changed, 410 insertions(+), 242 deletions(-)
diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
index 29b6679d227..bbf67b97670 100644
--- a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
+++ b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
@@ -404,6 +404,13 @@ void matchUnknownTypesWildcardArguments() {
void matchUnknownTypesSingleWildcardArgument() {
var mi = asMethodInvocation("Assert.assertTrue(Foo.bar(), \"message\");");
assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, String)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(String, *)").matches(mi, true));
+ }
+
+ @Test
+ void matchUnknownTypesMultipleWildcardArgument() {
+ var mi = asMethodInvocation("Assert.assertTrue(Foo.bar(), \"message\");");
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, *)").matches(mi, true));
}
static J.MethodInvocation asMethodInvocation(String code) {
@@ -413,6 +420,12 @@ class MyTest {
void test() {
%s
}
+
+ class Foo {
+ static String bar() {
+ return "bar";
+ }
+ }
}
""", code)
)
diff --git a/rewrite-java/src/main/antlr/MethodSignatureParser.g4 b/rewrite-java/src/main/antlr/MethodSignatureParser.g4
index 027d998e8df..e5600fcfa72 100644
--- a/rewrite-java/src/main/antlr/MethodSignatureParser.g4
+++ b/rewrite-java/src/main/antlr/MethodSignatureParser.g4
@@ -12,10 +12,15 @@ formalParametersPattern
formalsPattern
: dotDot (COMMA SPACE* formalsPatternAfterDotDot)*
- | optionalParensTypePattern (COMMA SPACE* formalsPattern)*
+ | wildcard (COMMA SPACE* formalsPattern)*
+ | optionalParensTypePattern (COMMA SPACE* formalsPattern)*
| formalTypePattern ELLIPSIS
;
+wildcard
+ : WILDCARD
+ ;
+
dotDot
: DOTDOT
;
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
index 9fdd7ac2855..8ec1d7513a0 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
@@ -553,6 +553,12 @@ public String visitDotDot(MethodSignatureParser.DotDotContext ctx) {
return super.visitDotDot(ctx);
}
+ @Override
+ public String visitWildcard(MethodSignatureParser.WildcardContext ctx) {
+ arguments.add(Argument.WILDCARD);
+ return super.visitWildcard(ctx);
+ }
+
@Override
public String visitFormalTypePattern(MethodSignatureParser.FormalTypePatternContext ctx) {
arguments.add(new Argument.FormalType(ctx));
@@ -598,6 +604,13 @@ String getRegex() {
}
};
+ private static final Argument WILDCARD = new Argument() {
+ @Override
+ String getRegex() {
+ return "([^,]+)";
+ }
+ };
+
private static class FormalType extends Argument {
private final MethodSignatureParser.FormalTypePatternContext ctx;
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.interp b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.interp
index dc15f803912..4c38b1f225c 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.interp
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.interp
@@ -40,6 +40,7 @@ rule names:
methodPattern
formalParametersPattern
formalsPattern
+wildcard
dotDot
formalsPatternAfterDotDot
optionalParensTypePattern
@@ -50,4 +51,4 @@ simpleNamePattern
atn:
-[4, 1, 16, 173, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 1, 0, 1, 0, 5, 0, 23, 8, 0, 10, 0, 12, 0, 26, 9, 0, 1, 0, 1, 0, 3, 0, 30, 8, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 37, 8, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 5, 2, 44, 8, 2, 10, 2, 12, 2, 47, 9, 2, 1, 2, 5, 2, 50, 8, 2, 10, 2, 12, 2, 53, 9, 2, 1, 2, 1, 2, 1, 2, 5, 2, 58, 8, 2, 10, 2, 12, 2, 61, 9, 2, 1, 2, 5, 2, 64, 8, 2, 10, 2, 12, 2, 67, 9, 2, 1, 2, 1, 2, 1, 2, 3, 2, 72, 8, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 5, 4, 79, 8, 4, 10, 4, 12, 4, 82, 9, 4, 1, 4, 5, 4, 85, 8, 4, 10, 4, 12, 4, 88, 9, 4, 1, 4, 1, 4, 1, 4, 3, 4, 93, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 100, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 106, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 114, 8, 6, 10, 6, 12, 6, 117, 9, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 123, 8, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 131, 8, 7, 10, 7, 12, 7, 134, 9, 7, 1, 8, 4, 8, 137, 8, 8, 11, 8, 12, 8, 138, 1, 8, 1, 8, 5, 8, 143, 8, 8, 10, 8, 12, 8, 146, 9, 8, 1, 9, 1, 9, 1, 9, 5, 9, 151, 8, 9, 10, 9, 12, 9, 154, 9, 9, 1, 9, 3, 9, 157, 8, 9, 1, 9, 1, 9, 1, 9, 5, 9, 162, 8, 9, 10, 9, 12, 9, 165, 9, 9, 1, 9, 3, 9, 168, 8, 9, 1, 9, 3, 9, 171, 8, 9, 1, 9, 0, 2, 12, 14, 10, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 0, 1, 4, 0, 7, 7, 9, 9, 13, 13, 16, 16, 190, 0, 20, 1, 0, 0, 0, 2, 34, 1, 0, 0, 0, 4, 71, 1, 0, 0, 0, 6, 73, 1, 0, 0, 0, 8, 92, 1, 0, 0, 0, 10, 99, 1, 0, 0, 0, 12, 105, 1, 0, 0, 0, 14, 122, 1, 0, 0, 0, 16, 136, 1, 0, 0, 0, 18, 170, 1, 0, 0, 0, 20, 29, 3, 12, 6, 0, 21, 23, 5, 15, 0, 0, 22, 21, 1, 0, 0, 0, 23, 26, 1, 0, 0, 0, 24, 22, 1, 0, 0, 0, 24, 25, 1, 0, 0, 0, 25, 30, 1, 0, 0, 0, 26, 24, 1, 0, 0, 0, 27, 30, 5, 7, 0, 0, 28, 30, 5, 14, 0, 0, 29, 24, 1, 0, 0, 0, 29, 27, 1, 0, 0, 0, 29, 28, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 32, 3, 18, 9, 0, 32, 33, 3, 2, 1, 0, 33, 1, 1, 0, 0, 0, 34, 36, 5, 2, 0, 0, 35, 37, 3, 4, 2, 0, 36, 35, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 39, 5, 3, 0, 0, 39, 3, 1, 0, 0, 0, 40, 51, 3, 6, 3, 0, 41, 45, 5, 6, 0, 0, 42, 44, 5, 15, 0, 0, 43, 42, 1, 0, 0, 0, 44, 47, 1, 0, 0, 0, 45, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 48, 1, 0, 0, 0, 47, 45, 1, 0, 0, 0, 48, 50, 3, 8, 4, 0, 49, 41, 1, 0, 0, 0, 50, 53, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 52, 1, 0, 0, 0, 52, 72, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 65, 3, 10, 5, 0, 55, 59, 5, 6, 0, 0, 56, 58, 5, 15, 0, 0, 57, 56, 1, 0, 0, 0, 58, 61, 1, 0, 0, 0, 59, 57, 1, 0, 0, 0, 59, 60, 1, 0, 0, 0, 60, 62, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 62, 64, 3, 4, 2, 0, 63, 55, 1, 0, 0, 0, 64, 67, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 72, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 68, 69, 3, 14, 7, 0, 69, 70, 5, 12, 0, 0, 70, 72, 1, 0, 0, 0, 71, 40, 1, 0, 0, 0, 71, 54, 1, 0, 0, 0, 71, 68, 1, 0, 0, 0, 72, 5, 1, 0, 0, 0, 73, 74, 5, 13, 0, 0, 74, 7, 1, 0, 0, 0, 75, 86, 3, 10, 5, 0, 76, 80, 5, 6, 0, 0, 77, 79, 5, 15, 0, 0, 78, 77, 1, 0, 0, 0, 79, 82, 1, 0, 0, 0, 80, 78, 1, 0, 0, 0, 80, 81, 1, 0, 0, 0, 81, 83, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 83, 85, 3, 8, 4, 0, 84, 76, 1, 0, 0, 0, 85, 88, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 93, 1, 0, 0, 0, 88, 86, 1, 0, 0, 0, 89, 90, 3, 14, 7, 0, 90, 91, 5, 12, 0, 0, 91, 93, 1, 0, 0, 0, 92, 75, 1, 0, 0, 0, 92, 89, 1, 0, 0, 0, 93, 9, 1, 0, 0, 0, 94, 95, 5, 2, 0, 0, 95, 96, 3, 14, 7, 0, 96, 97, 5, 3, 0, 0, 97, 100, 1, 0, 0, 0, 98, 100, 3, 14, 7, 0, 99, 94, 1, 0, 0, 0, 99, 98, 1, 0, 0, 0, 100, 11, 1, 0, 0, 0, 101, 102, 6, 6, -1, 0, 102, 106, 3, 16, 8, 0, 103, 104, 5, 8, 0, 0, 104, 106, 3, 12, 6, 3, 105, 101, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 106, 115, 1, 0, 0, 0, 107, 108, 10, 2, 0, 0, 108, 109, 5, 10, 0, 0, 109, 114, 3, 12, 6, 3, 110, 111, 10, 1, 0, 0, 111, 112, 5, 11, 0, 0, 112, 114, 3, 12, 6, 2, 113, 107, 1, 0, 0, 0, 113, 110, 1, 0, 0, 0, 114, 117, 1, 0, 0, 0, 115, 113, 1, 0, 0, 0, 115, 116, 1, 0, 0, 0, 116, 13, 1, 0, 0, 0, 117, 115, 1, 0, 0, 0, 118, 119, 6, 7, -1, 0, 119, 123, 3, 16, 8, 0, 120, 121, 5, 8, 0, 0, 121, 123, 3, 14, 7, 3, 122, 118, 1, 0, 0, 0, 122, 120, 1, 0, 0, 0, 123, 132, 1, 0, 0, 0, 124, 125, 10, 2, 0, 0, 125, 126, 5, 10, 0, 0, 126, 131, 3, 14, 7, 3, 127, 128, 10, 1, 0, 0, 128, 129, 5, 11, 0, 0, 129, 131, 3, 14, 7, 2, 130, 124, 1, 0, 0, 0, 130, 127, 1, 0, 0, 0, 131, 134, 1, 0, 0, 0, 132, 130, 1, 0, 0, 0, 132, 133, 1, 0, 0, 0, 133, 15, 1, 0, 0, 0, 134, 132, 1, 0, 0, 0, 135, 137, 7, 0, 0, 0, 136, 135, 1, 0, 0, 0, 137, 138, 1, 0, 0, 0, 138, 136, 1, 0, 0, 0, 138, 139, 1, 0, 0, 0, 139, 144, 1, 0, 0, 0, 140, 141, 5, 4, 0, 0, 141, 143, 5, 5, 0, 0, 142, 140, 1, 0, 0, 0, 143, 146, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 144, 145, 1, 0, 0, 0, 145, 17, 1, 0, 0, 0, 146, 144, 1, 0, 0, 0, 147, 152, 5, 16, 0, 0, 148, 149, 5, 9, 0, 0, 149, 151, 5, 16, 0, 0, 150, 148, 1, 0, 0, 0, 151, 154, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 156, 1, 0, 0, 0, 154, 152, 1, 0, 0, 0, 155, 157, 5, 9, 0, 0, 156, 155, 1, 0, 0, 0, 156, 157, 1, 0, 0, 0, 157, 171, 1, 0, 0, 0, 158, 163, 5, 9, 0, 0, 159, 160, 5, 16, 0, 0, 160, 162, 5, 9, 0, 0, 161, 159, 1, 0, 0, 0, 162, 165, 1, 0, 0, 0, 163, 161, 1, 0, 0, 0, 163, 164, 1, 0, 0, 0, 164, 167, 1, 0, 0, 0, 165, 163, 1, 0, 0, 0, 166, 168, 5, 16, 0, 0, 167, 166, 1, 0, 0, 0, 167, 168, 1, 0, 0, 0, 168, 171, 1, 0, 0, 0, 169, 171, 5, 1, 0, 0, 170, 147, 1, 0, 0, 0, 170, 158, 1, 0, 0, 0, 170, 169, 1, 0, 0, 0, 171, 19, 1, 0, 0, 0, 25, 24, 29, 36, 45, 51, 59, 65, 71, 80, 86, 92, 99, 105, 113, 115, 122, 130, 132, 138, 144, 152, 156, 163, 167, 170]
\ No newline at end of file
+[4, 1, 16, 191, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 1, 0, 1, 0, 5, 0, 25, 8, 0, 10, 0, 12, 0, 28, 9, 0, 1, 0, 1, 0, 3, 0, 32, 8, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 3, 1, 39, 8, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 5, 2, 46, 8, 2, 10, 2, 12, 2, 49, 9, 2, 1, 2, 5, 2, 52, 8, 2, 10, 2, 12, 2, 55, 9, 2, 1, 2, 1, 2, 1, 2, 5, 2, 60, 8, 2, 10, 2, 12, 2, 63, 9, 2, 1, 2, 5, 2, 66, 8, 2, 10, 2, 12, 2, 69, 9, 2, 1, 2, 1, 2, 1, 2, 5, 2, 74, 8, 2, 10, 2, 12, 2, 77, 9, 2, 1, 2, 5, 2, 80, 8, 2, 10, 2, 12, 2, 83, 9, 2, 1, 2, 1, 2, 1, 2, 3, 2, 88, 8, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 5, 5, 97, 8, 5, 10, 5, 12, 5, 100, 9, 5, 1, 5, 5, 5, 103, 8, 5, 10, 5, 12, 5, 106, 9, 5, 1, 5, 1, 5, 1, 5, 3, 5, 111, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 118, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 3, 7, 124, 8, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 132, 8, 7, 10, 7, 12, 7, 135, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 141, 8, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 149, 8, 8, 10, 8, 12, 8, 152, 9, 8, 1, 9, 4, 9, 155, 8, 9, 11, 9, 12, 9, 156, 1, 9, 1, 9, 5, 9, 161, 8, 9, 10, 9, 12, 9, 164, 9, 9, 1, 10, 1, 10, 1, 10, 5, 10, 169, 8, 10, 10, 10, 12, 10, 172, 9, 10, 1, 10, 3, 10, 175, 8, 10, 1, 10, 1, 10, 1, 10, 5, 10, 180, 8, 10, 10, 10, 12, 10, 183, 9, 10, 1, 10, 3, 10, 186, 8, 10, 1, 10, 3, 10, 189, 8, 10, 1, 10, 0, 2, 14, 16, 11, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 1, 4, 0, 7, 7, 9, 9, 13, 13, 16, 16, 210, 0, 22, 1, 0, 0, 0, 2, 36, 1, 0, 0, 0, 4, 87, 1, 0, 0, 0, 6, 89, 1, 0, 0, 0, 8, 91, 1, 0, 0, 0, 10, 110, 1, 0, 0, 0, 12, 117, 1, 0, 0, 0, 14, 123, 1, 0, 0, 0, 16, 140, 1, 0, 0, 0, 18, 154, 1, 0, 0, 0, 20, 188, 1, 0, 0, 0, 22, 31, 3, 14, 7, 0, 23, 25, 5, 15, 0, 0, 24, 23, 1, 0, 0, 0, 25, 28, 1, 0, 0, 0, 26, 24, 1, 0, 0, 0, 26, 27, 1, 0, 0, 0, 27, 32, 1, 0, 0, 0, 28, 26, 1, 0, 0, 0, 29, 32, 5, 7, 0, 0, 30, 32, 5, 14, 0, 0, 31, 26, 1, 0, 0, 0, 31, 29, 1, 0, 0, 0, 31, 30, 1, 0, 0, 0, 32, 33, 1, 0, 0, 0, 33, 34, 3, 20, 10, 0, 34, 35, 3, 2, 1, 0, 35, 1, 1, 0, 0, 0, 36, 38, 5, 2, 0, 0, 37, 39, 3, 4, 2, 0, 38, 37, 1, 0, 0, 0, 38, 39, 1, 0, 0, 0, 39, 40, 1, 0, 0, 0, 40, 41, 5, 3, 0, 0, 41, 3, 1, 0, 0, 0, 42, 53, 3, 8, 4, 0, 43, 47, 5, 6, 0, 0, 44, 46, 5, 15, 0, 0, 45, 44, 1, 0, 0, 0, 46, 49, 1, 0, 0, 0, 47, 45, 1, 0, 0, 0, 47, 48, 1, 0, 0, 0, 48, 50, 1, 0, 0, 0, 49, 47, 1, 0, 0, 0, 50, 52, 3, 10, 5, 0, 51, 43, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 88, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 67, 3, 6, 3, 0, 57, 61, 5, 6, 0, 0, 58, 60, 5, 15, 0, 0, 59, 58, 1, 0, 0, 0, 60, 63, 1, 0, 0, 0, 61, 59, 1, 0, 0, 0, 61, 62, 1, 0, 0, 0, 62, 64, 1, 0, 0, 0, 63, 61, 1, 0, 0, 0, 64, 66, 3, 4, 2, 0, 65, 57, 1, 0, 0, 0, 66, 69, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 88, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 70, 81, 3, 12, 6, 0, 71, 75, 5, 6, 0, 0, 72, 74, 5, 15, 0, 0, 73, 72, 1, 0, 0, 0, 74, 77, 1, 0, 0, 0, 75, 73, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 78, 1, 0, 0, 0, 77, 75, 1, 0, 0, 0, 78, 80, 3, 4, 2, 0, 79, 71, 1, 0, 0, 0, 80, 83, 1, 0, 0, 0, 81, 79, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 88, 1, 0, 0, 0, 83, 81, 1, 0, 0, 0, 84, 85, 3, 16, 8, 0, 85, 86, 5, 12, 0, 0, 86, 88, 1, 0, 0, 0, 87, 42, 1, 0, 0, 0, 87, 56, 1, 0, 0, 0, 87, 70, 1, 0, 0, 0, 87, 84, 1, 0, 0, 0, 88, 5, 1, 0, 0, 0, 89, 90, 5, 9, 0, 0, 90, 7, 1, 0, 0, 0, 91, 92, 5, 13, 0, 0, 92, 9, 1, 0, 0, 0, 93, 104, 3, 12, 6, 0, 94, 98, 5, 6, 0, 0, 95, 97, 5, 15, 0, 0, 96, 95, 1, 0, 0, 0, 97, 100, 1, 0, 0, 0, 98, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 101, 1, 0, 0, 0, 100, 98, 1, 0, 0, 0, 101, 103, 3, 10, 5, 0, 102, 94, 1, 0, 0, 0, 103, 106, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 111, 1, 0, 0, 0, 106, 104, 1, 0, 0, 0, 107, 108, 3, 16, 8, 0, 108, 109, 5, 12, 0, 0, 109, 111, 1, 0, 0, 0, 110, 93, 1, 0, 0, 0, 110, 107, 1, 0, 0, 0, 111, 11, 1, 0, 0, 0, 112, 113, 5, 2, 0, 0, 113, 114, 3, 16, 8, 0, 114, 115, 5, 3, 0, 0, 115, 118, 1, 0, 0, 0, 116, 118, 3, 16, 8, 0, 117, 112, 1, 0, 0, 0, 117, 116, 1, 0, 0, 0, 118, 13, 1, 0, 0, 0, 119, 120, 6, 7, -1, 0, 120, 124, 3, 18, 9, 0, 121, 122, 5, 8, 0, 0, 122, 124, 3, 14, 7, 3, 123, 119, 1, 0, 0, 0, 123, 121, 1, 0, 0, 0, 124, 133, 1, 0, 0, 0, 125, 126, 10, 2, 0, 0, 126, 127, 5, 10, 0, 0, 127, 132, 3, 14, 7, 3, 128, 129, 10, 1, 0, 0, 129, 130, 5, 11, 0, 0, 130, 132, 3, 14, 7, 2, 131, 125, 1, 0, 0, 0, 131, 128, 1, 0, 0, 0, 132, 135, 1, 0, 0, 0, 133, 131, 1, 0, 0, 0, 133, 134, 1, 0, 0, 0, 134, 15, 1, 0, 0, 0, 135, 133, 1, 0, 0, 0, 136, 137, 6, 8, -1, 0, 137, 141, 3, 18, 9, 0, 138, 139, 5, 8, 0, 0, 139, 141, 3, 16, 8, 3, 140, 136, 1, 0, 0, 0, 140, 138, 1, 0, 0, 0, 141, 150, 1, 0, 0, 0, 142, 143, 10, 2, 0, 0, 143, 144, 5, 10, 0, 0, 144, 149, 3, 16, 8, 3, 145, 146, 10, 1, 0, 0, 146, 147, 5, 11, 0, 0, 147, 149, 3, 16, 8, 2, 148, 142, 1, 0, 0, 0, 148, 145, 1, 0, 0, 0, 149, 152, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 150, 151, 1, 0, 0, 0, 151, 17, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 153, 155, 7, 0, 0, 0, 154, 153, 1, 0, 0, 0, 155, 156, 1, 0, 0, 0, 156, 154, 1, 0, 0, 0, 156, 157, 1, 0, 0, 0, 157, 162, 1, 0, 0, 0, 158, 159, 5, 4, 0, 0, 159, 161, 5, 5, 0, 0, 160, 158, 1, 0, 0, 0, 161, 164, 1, 0, 0, 0, 162, 160, 1, 0, 0, 0, 162, 163, 1, 0, 0, 0, 163, 19, 1, 0, 0, 0, 164, 162, 1, 0, 0, 0, 165, 170, 5, 16, 0, 0, 166, 167, 5, 9, 0, 0, 167, 169, 5, 16, 0, 0, 168, 166, 1, 0, 0, 0, 169, 172, 1, 0, 0, 0, 170, 168, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 174, 1, 0, 0, 0, 172, 170, 1, 0, 0, 0, 173, 175, 5, 9, 0, 0, 174, 173, 1, 0, 0, 0, 174, 175, 1, 0, 0, 0, 175, 189, 1, 0, 0, 0, 176, 181, 5, 9, 0, 0, 177, 178, 5, 16, 0, 0, 178, 180, 5, 9, 0, 0, 179, 177, 1, 0, 0, 0, 180, 183, 1, 0, 0, 0, 181, 179, 1, 0, 0, 0, 181, 182, 1, 0, 0, 0, 182, 185, 1, 0, 0, 0, 183, 181, 1, 0, 0, 0, 184, 186, 5, 16, 0, 0, 185, 184, 1, 0, 0, 0, 185, 186, 1, 0, 0, 0, 186, 189, 1, 0, 0, 0, 187, 189, 5, 1, 0, 0, 188, 165, 1, 0, 0, 0, 188, 176, 1, 0, 0, 0, 188, 187, 1, 0, 0, 0, 189, 21, 1, 0, 0, 0, 27, 26, 31, 38, 47, 53, 61, 67, 75, 81, 87, 98, 104, 110, 117, 123, 131, 133, 140, 148, 150, 156, 162, 170, 174, 181, 185, 188]
\ No newline at end of file
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
index bdd836a23d4..121b667db79 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
@@ -40,14 +40,14 @@ public class MethodSignatureParser extends Parser {
BANG=8, WILDCARD=9, AND=10, OR=11, ELLIPSIS=12, DOTDOT=13, POUND=14, SPACE=15,
Identifier=16;
public static final int
- RULE_methodPattern = 0, RULE_formalParametersPattern = 1, RULE_formalsPattern = 2,
- RULE_dotDot = 3, RULE_formalsPatternAfterDotDot = 4, RULE_optionalParensTypePattern = 5,
- RULE_targetTypePattern = 6, RULE_formalTypePattern = 7, RULE_classNameOrInterface = 8,
- RULE_simpleNamePattern = 9;
+ RULE_methodPattern = 0, RULE_formalParametersPattern = 1, RULE_formalsPattern = 2,
+ RULE_wildcard = 3, RULE_dotDot = 4, RULE_formalsPatternAfterDotDot = 5,
+ RULE_optionalParensTypePattern = 6, RULE_targetTypePattern = 7, RULE_formalTypePattern = 8,
+ RULE_classNameOrInterface = 9, RULE_simpleNamePattern = 10;
private static String[] makeRuleNames() {
return new String[] {
- "methodPattern", "formalParametersPattern", "formalsPattern", "dotDot",
- "formalsPatternAfterDotDot", "optionalParensTypePattern", "targetTypePattern",
+ "methodPattern", "formalParametersPattern", "formalsPattern", "wildcard",
+ "dotDot", "formalsPatternAfterDotDot", "optionalParensTypePattern", "targetTypePattern",
"formalTypePattern", "classNameOrInterface", "simpleNamePattern"
};
}
@@ -161,9 +161,9 @@ public final MethodPatternContext methodPattern() throws RecognitionException {
try {
enterOuterAlt(_localctx, 1);
{
- setState(20);
+ setState(22);
targetTypePattern(0);
- setState(29);
+ setState(31);
_errHandler.sync(this);
switch (_input.LA(1)) {
case CONSTRUCTOR:
@@ -171,17 +171,17 @@ public final MethodPatternContext methodPattern() throws RecognitionException {
case SPACE:
case Identifier:
{
- setState(24);
+ setState(26);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==SPACE) {
{
{
- setState(21);
+ setState(23);
match(SPACE);
}
}
- setState(26);
+ setState(28);
_errHandler.sync(this);
_la = _input.LA(1);
}
@@ -189,22 +189,22 @@ public final MethodPatternContext methodPattern() throws RecognitionException {
break;
case DOT:
{
- setState(27);
+ setState(29);
match(DOT);
}
break;
case POUND:
{
- setState(28);
+ setState(30);
match(POUND);
}
break;
default:
throw new NoViableAltException(this);
}
- setState(31);
+ setState(33);
simpleNamePattern();
- setState(32);
+ setState(34);
formalParametersPattern();
}
}
@@ -252,19 +252,19 @@ public final FormalParametersPatternContext formalParametersPattern() throws Rec
try {
enterOuterAlt(_localctx, 1);
{
- setState(34);
- match(LPAREN);
setState(36);
+ match(LPAREN);
+ setState(38);
_errHandler.sync(this);
_la = _input.LA(1);
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 74628L) != 0)) {
{
- setState(35);
+ setState(37);
formalsPattern();
}
}
- setState(38);
+ setState(40);
match(RPAREN);
}
}
@@ -298,8 +298,8 @@ public FormalsPatternAfterDotDotContext formalsPatternAfterDotDot(int i) {
public TerminalNode SPACE(int i) {
return getToken(MethodSignatureParser.SPACE, i);
}
- public OptionalParensTypePatternContext optionalParensTypePattern() {
- return getRuleContext(OptionalParensTypePatternContext.class,0);
+ public WildcardContext wildcard() {
+ return getRuleContext(WildcardContext.class,0);
}
public List formalsPattern() {
return getRuleContexts(FormalsPatternContext.class);
@@ -307,6 +307,9 @@ public List formalsPattern() {
public FormalsPatternContext formalsPattern(int i) {
return getRuleContext(FormalsPatternContext.class,i);
}
+ public OptionalParensTypePatternContext optionalParensTypePattern() {
+ return getRuleContext(OptionalParensTypePatternContext.class,0);
+ }
public FormalTypePatternContext formalTypePattern() {
return getRuleContext(FormalTypePatternContext.class,0);
}
@@ -336,43 +339,43 @@ public final FormalsPatternContext formalsPattern() throws RecognitionException
int _la;
try {
int _alt;
- setState(71);
+ setState(87);
_errHandler.sync(this);
- switch ( getInterpreter().adaptivePredict(_input,7,_ctx) ) {
+ switch ( getInterpreter().adaptivePredict(_input,9,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(40);
+ setState(42);
dotDot();
- setState(51);
+ setState(53);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,4,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(41);
+ setState(43);
match(COMMA);
- setState(45);
+ setState(47);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==SPACE) {
{
{
- setState(42);
+ setState(44);
match(SPACE);
}
}
- setState(47);
+ setState(49);
_errHandler.sync(this);
_la = _input.LA(1);
}
- setState(48);
+ setState(50);
formalsPatternAfterDotDot();
}
}
}
- setState(53);
+ setState(55);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,4,_ctx);
}
@@ -381,37 +384,37 @@ public final FormalsPatternContext formalsPattern() throws RecognitionException
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(54);
- optionalParensTypePattern();
- setState(65);
+ setState(56);
+ wildcard();
+ setState(67);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,6,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(55);
+ setState(57);
match(COMMA);
- setState(59);
+ setState(61);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==SPACE) {
{
{
- setState(56);
+ setState(58);
match(SPACE);
}
}
- setState(61);
+ setState(63);
_errHandler.sync(this);
_la = _input.LA(1);
}
- setState(62);
+ setState(64);
formalsPattern();
}
}
}
- setState(67);
+ setState(69);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,6,_ctx);
}
@@ -420,9 +423,48 @@ public final FormalsPatternContext formalsPattern() throws RecognitionException
case 3:
enterOuterAlt(_localctx, 3);
{
- setState(68);
+ setState(70);
+ optionalParensTypePattern();
+ setState(81);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,8,_ctx);
+ while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
+ if ( _alt==1 ) {
+ {
+ {
+ setState(71);
+ match(COMMA);
+ setState(75);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ while (_la==SPACE) {
+ {
+ {
+ setState(72);
+ match(SPACE);
+ }
+ }
+ setState(77);
+ _errHandler.sync(this);
+ _la = _input.LA(1);
+ }
+ setState(78);
+ formalsPattern();
+ }
+ }
+ }
+ setState(83);
+ _errHandler.sync(this);
+ _alt = getInterpreter().adaptivePredict(_input,8,_ctx);
+ }
+ }
+ break;
+ case 4:
+ enterOuterAlt(_localctx, 4);
+ {
+ setState(84);
formalTypePattern(0);
- setState(69);
+ setState(85);
match(ELLIPSIS);
}
break;
@@ -439,6 +481,49 @@ public final FormalsPatternContext formalsPattern() throws RecognitionException
return _localctx;
}
+ @SuppressWarnings("CheckReturnValue")
+ public static class WildcardContext extends ParserRuleContext {
+ public TerminalNode WILDCARD() { return getToken(MethodSignatureParser.WILDCARD, 0); }
+ public WildcardContext(ParserRuleContext parent, int invokingState) {
+ super(parent, invokingState);
+ }
+ @Override public int getRuleIndex() { return RULE_wildcard; }
+ @Override
+ public void enterRule(ParseTreeListener listener) {
+ if ( listener instanceof MethodSignatureParserListener ) ((MethodSignatureParserListener)listener).enterWildcard(this);
+ }
+ @Override
+ public void exitRule(ParseTreeListener listener) {
+ if ( listener instanceof MethodSignatureParserListener ) ((MethodSignatureParserListener)listener).exitWildcard(this);
+ }
+ @Override
+ public T accept(ParseTreeVisitor extends T> visitor) {
+ if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitWildcard(this);
+ else return visitor.visitChildren(this);
+ }
+ }
+
+ public final WildcardContext wildcard() throws RecognitionException {
+ WildcardContext _localctx = new WildcardContext(_ctx, getState());
+ enterRule(_localctx, 6, RULE_wildcard);
+ try {
+ enterOuterAlt(_localctx, 1);
+ {
+ setState(89);
+ match(WILDCARD);
+ }
+ }
+ catch (RecognitionException re) {
+ _localctx.exception = re;
+ _errHandler.reportError(this, re);
+ _errHandler.recover(this, re);
+ }
+ finally {
+ exitRule();
+ }
+ return _localctx;
+ }
+
@SuppressWarnings("CheckReturnValue")
public static class DotDotContext extends ParserRuleContext {
public TerminalNode DOTDOT() { return getToken(MethodSignatureParser.DOTDOT, 0); }
@@ -463,11 +548,11 @@ public T accept(ParseTreeVisitor extends T> visitor) {
public final DotDotContext dotDot() throws RecognitionException {
DotDotContext _localctx = new DotDotContext(_ctx, getState());
- enterRule(_localctx, 6, RULE_dotDot);
+ enterRule(_localctx, 8, RULE_dotDot);
try {
enterOuterAlt(_localctx, 1);
{
- setState(73);
+ setState(91);
match(DOTDOT);
}
}
@@ -526,58 +611,58 @@ public T accept(ParseTreeVisitor extends T> visitor) {
public final FormalsPatternAfterDotDotContext formalsPatternAfterDotDot() throws RecognitionException {
FormalsPatternAfterDotDotContext _localctx = new FormalsPatternAfterDotDotContext(_ctx, getState());
- enterRule(_localctx, 8, RULE_formalsPatternAfterDotDot);
+ enterRule(_localctx, 10, RULE_formalsPatternAfterDotDot);
int _la;
try {
int _alt;
- setState(92);
+ setState(110);
_errHandler.sync(this);
- switch ( getInterpreter().adaptivePredict(_input,10,_ctx) ) {
+ switch ( getInterpreter().adaptivePredict(_input,12,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
- setState(75);
+ setState(93);
optionalParensTypePattern();
- setState(86);
+ setState(104);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,9,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,11,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(76);
+ setState(94);
match(COMMA);
- setState(80);
+ setState(98);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la==SPACE) {
{
{
- setState(77);
+ setState(95);
match(SPACE);
}
}
- setState(82);
+ setState(100);
_errHandler.sync(this);
_la = _input.LA(1);
}
- setState(83);
+ setState(101);
formalsPatternAfterDotDot();
}
}
}
- setState(88);
+ setState(106);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,9,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,11,_ctx);
}
}
break;
case 2:
enterOuterAlt(_localctx, 2);
{
- setState(89);
+ setState(107);
formalTypePattern(0);
- setState(90);
+ setState(108);
match(ELLIPSIS);
}
break;
@@ -622,19 +707,19 @@ public T accept(ParseTreeVisitor extends T> visitor) {
public final OptionalParensTypePatternContext optionalParensTypePattern() throws RecognitionException {
OptionalParensTypePatternContext _localctx = new OptionalParensTypePatternContext(_ctx, getState());
- enterRule(_localctx, 10, RULE_optionalParensTypePattern);
+ enterRule(_localctx, 12, RULE_optionalParensTypePattern);
try {
- setState(99);
+ setState(117);
_errHandler.sync(this);
switch (_input.LA(1)) {
case LPAREN:
enterOuterAlt(_localctx, 1);
{
- setState(94);
+ setState(112);
match(LPAREN);
- setState(95);
+ setState(113);
formalTypePattern(0);
- setState(96);
+ setState(114);
match(RPAREN);
}
break;
@@ -645,7 +730,7 @@ public final OptionalParensTypePatternContext optionalParensTypePattern() throws
case Identifier:
enterOuterAlt(_localctx, 2);
{
- setState(98);
+ setState(116);
formalTypePattern(0);
}
break;
@@ -705,13 +790,14 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
TargetTypePatternContext _localctx = new TargetTypePatternContext(_ctx, _parentState);
- int _startState = 12;
- enterRecursionRule(_localctx, 12, RULE_targetTypePattern, _p);
+ TargetTypePatternContext _prevctx = _localctx;
+ int _startState = 14;
+ enterRecursionRule(_localctx, 14, RULE_targetTypePattern, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(105);
+ setState(123);
_errHandler.sync(this);
switch (_input.LA(1)) {
case DOT:
@@ -719,15 +805,15 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
case DOTDOT:
case Identifier:
{
- setState(102);
+ setState(120);
classNameOrInterface();
}
break;
case BANG:
{
- setState(103);
+ setState(121);
match(BANG);
- setState(104);
+ setState(122);
targetTypePattern(3);
}
break;
@@ -735,25 +821,26 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
- setState(115);
+ setState(133);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,14,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,16,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
+ _prevctx = _localctx;
{
- setState(113);
+ setState(131);
_errHandler.sync(this);
- switch ( getInterpreter().adaptivePredict(_input,13,_ctx) ) {
+ switch ( getInterpreter().adaptivePredict(_input,15,_ctx) ) {
case 1:
{
_localctx = new TargetTypePatternContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_targetTypePattern);
- setState(107);
+ setState(125);
if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
- setState(108);
+ setState(126);
match(AND);
- setState(109);
+ setState(127);
targetTypePattern(3);
}
break;
@@ -761,20 +848,20 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
{
_localctx = new TargetTypePatternContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_targetTypePattern);
- setState(110);
+ setState(128);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(111);
+ setState(129);
match(OR);
- setState(112);
+ setState(130);
targetTypePattern(2);
}
break;
}
}
}
- setState(117);
+ setState(135);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,14,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,16,_ctx);
}
}
}
@@ -830,13 +917,14 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
FormalTypePatternContext _localctx = new FormalTypePatternContext(_ctx, _parentState);
- int _startState = 14;
- enterRecursionRule(_localctx, 14, RULE_formalTypePattern, _p);
+ FormalTypePatternContext _prevctx = _localctx;
+ int _startState = 16;
+ enterRecursionRule(_localctx, 16, RULE_formalTypePattern, _p);
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(122);
+ setState(140);
_errHandler.sync(this);
switch (_input.LA(1)) {
case DOT:
@@ -844,15 +932,15 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
case DOTDOT:
case Identifier:
{
- setState(119);
+ setState(137);
classNameOrInterface();
}
break;
case BANG:
{
- setState(120);
+ setState(138);
match(BANG);
- setState(121);
+ setState(139);
formalTypePattern(3);
}
break;
@@ -860,25 +948,26 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
throw new NoViableAltException(this);
}
_ctx.stop = _input.LT(-1);
- setState(132);
+ setState(150);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,17,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,19,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
+ _prevctx = _localctx;
{
- setState(130);
+ setState(148);
_errHandler.sync(this);
- switch ( getInterpreter().adaptivePredict(_input,16,_ctx) ) {
+ switch ( getInterpreter().adaptivePredict(_input,18,_ctx) ) {
case 1:
{
_localctx = new FormalTypePatternContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_formalTypePattern);
- setState(124);
+ setState(142);
if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
- setState(125);
+ setState(143);
match(AND);
- setState(126);
+ setState(144);
formalTypePattern(3);
}
break;
@@ -886,20 +975,20 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
{
_localctx = new FormalTypePatternContext(_parentctx, _parentState);
pushNewRecursionContext(_localctx, _startState, RULE_formalTypePattern);
- setState(127);
+ setState(145);
if (!(precpred(_ctx, 1))) throw new FailedPredicateException(this, "precpred(_ctx, 1)");
- setState(128);
+ setState(146);
match(OR);
- setState(129);
+ setState(147);
formalTypePattern(2);
}
break;
}
}
}
- setState(134);
+ setState(152);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,17,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,19,_ctx);
}
}
}
@@ -961,13 +1050,13 @@ public T accept(ParseTreeVisitor extends T> visitor) {
public final ClassNameOrInterfaceContext classNameOrInterface() throws RecognitionException {
ClassNameOrInterfaceContext _localctx = new ClassNameOrInterfaceContext(_ctx, getState());
- enterRule(_localctx, 16, RULE_classNameOrInterface);
+ enterRule(_localctx, 18, RULE_classNameOrInterface);
int _la;
try {
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(136);
+ setState(154);
_errHandler.sync(this);
_alt = 1;
do {
@@ -975,7 +1064,7 @@ public final ClassNameOrInterfaceContext classNameOrInterface() throws Recogniti
case 1:
{
{
- setState(135);
+ setState(153);
_la = _input.LA(1);
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 74368L) != 0)) ) {
_errHandler.recoverInline(this);
@@ -991,27 +1080,27 @@ public final ClassNameOrInterfaceContext classNameOrInterface() throws Recogniti
default:
throw new NoViableAltException(this);
}
- setState(138);
+ setState(156);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,18,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,20,_ctx);
} while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER );
- setState(144);
+ setState(162);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,19,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,21,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(140);
+ setState(158);
match(LBRACK);
- setState(141);
+ setState(159);
match(RBRACK);
}
}
}
- setState(146);
+ setState(164);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,19,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,21,_ctx);
}
}
}
@@ -1058,42 +1147,42 @@ public T accept(ParseTreeVisitor extends T> visitor) {
public final SimpleNamePatternContext simpleNamePattern() throws RecognitionException {
SimpleNamePatternContext _localctx = new SimpleNamePatternContext(_ctx, getState());
- enterRule(_localctx, 18, RULE_simpleNamePattern);
+ enterRule(_localctx, 20, RULE_simpleNamePattern);
int _la;
try {
int _alt;
- setState(170);
+ setState(188);
_errHandler.sync(this);
switch (_input.LA(1)) {
case Identifier:
enterOuterAlt(_localctx, 1);
{
- setState(147);
+ setState(165);
match(Identifier);
- setState(152);
+ setState(170);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,20,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,22,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(148);
+ setState(166);
match(WILDCARD);
- setState(149);
+ setState(167);
match(Identifier);
}
}
}
- setState(154);
+ setState(172);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,20,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,22,_ctx);
}
- setState(156);
+ setState(174);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==WILDCARD) {
{
- setState(155);
+ setState(173);
match(WILDCARD);
}
}
@@ -1103,32 +1192,32 @@ public final SimpleNamePatternContext simpleNamePattern() throws RecognitionExce
case WILDCARD:
enterOuterAlt(_localctx, 2);
{
- setState(158);
+ setState(176);
match(WILDCARD);
- setState(163);
+ setState(181);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,22,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,24,_ctx);
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
{
{
- setState(159);
+ setState(177);
match(Identifier);
- setState(160);
+ setState(178);
match(WILDCARD);
}
}
}
- setState(165);
+ setState(183);
_errHandler.sync(this);
- _alt = getInterpreter().adaptivePredict(_input,22,_ctx);
+ _alt = getInterpreter().adaptivePredict(_input,24,_ctx);
}
- setState(167);
+ setState(185);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==Identifier) {
{
- setState(166);
+ setState(184);
match(Identifier);
}
}
@@ -1138,7 +1227,7 @@ public final SimpleNamePatternContext simpleNamePattern() throws RecognitionExce
case CONSTRUCTOR:
enterOuterAlt(_localctx, 3);
{
- setState(169);
+ setState(187);
match(CONSTRUCTOR);
}
break;
@@ -1160,9 +1249,9 @@ public final SimpleNamePatternContext simpleNamePattern() throws RecognitionExce
@Override
public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
switch (ruleIndex) {
- case 6:
- return targetTypePattern_sempred((TargetTypePatternContext)_localctx, predIndex);
case 7:
+ return targetTypePattern_sempred((TargetTypePatternContext)_localctx, predIndex);
+ case 8:
return formalTypePattern_sempred((FormalTypePatternContext)_localctx, predIndex);
}
return true;
@@ -1187,113 +1276,125 @@ private boolean formalTypePattern_sempred(FormalTypePatternContext _localctx, in
}
public static final String _serializedATN =
- "\u0004\u0001\u0010\u00ad\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001"+
+ "\u0004\u0001\u0010\u00bf\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001"+
"\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004"+
"\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007"+
- "\u0002\b\u0007\b\u0002\t\u0007\t\u0001\u0000\u0001\u0000\u0005\u0000\u0017"+
- "\b\u0000\n\u0000\f\u0000\u001a\t\u0000\u0001\u0000\u0001\u0000\u0003\u0000"+
- "\u001e\b\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001"+
- "\u0003\u0001%\b\u0001\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002"+
- "\u0001\u0002\u0005\u0002,\b\u0002\n\u0002\f\u0002/\t\u0002\u0001\u0002"+
- "\u0005\u00022\b\u0002\n\u0002\f\u00025\t\u0002\u0001\u0002\u0001\u0002"+
- "\u0001\u0002\u0005\u0002:\b\u0002\n\u0002\f\u0002=\t\u0002\u0001\u0002"+
- "\u0005\u0002@\b\u0002\n\u0002\f\u0002C\t\u0002\u0001\u0002\u0001\u0002"+
- "\u0001\u0002\u0003\u0002H\b\u0002\u0001\u0003\u0001\u0003\u0001\u0004"+
- "\u0001\u0004\u0001\u0004\u0005\u0004O\b\u0004\n\u0004\f\u0004R\t\u0004"+
- "\u0001\u0004\u0005\u0004U\b\u0004\n\u0004\f\u0004X\t\u0004\u0001\u0004"+
- "\u0001\u0004\u0001\u0004\u0003\u0004]\b\u0004\u0001\u0005\u0001\u0005"+
- "\u0001\u0005\u0001\u0005\u0001\u0005\u0003\u0005d\b\u0005\u0001\u0006"+
- "\u0001\u0006\u0001\u0006\u0001\u0006\u0003\u0006j\b\u0006\u0001\u0006"+
- "\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0005\u0006"+
- "r\b\u0006\n\u0006\f\u0006u\t\u0006\u0001\u0007\u0001\u0007\u0001\u0007"+
- "\u0001\u0007\u0003\u0007{\b\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
- "\u0001\u0007\u0001\u0007\u0001\u0007\u0005\u0007\u0083\b\u0007\n\u0007"+
- "\f\u0007\u0086\t\u0007\u0001\b\u0004\b\u0089\b\b\u000b\b\f\b\u008a\u0001"+
- "\b\u0001\b\u0005\b\u008f\b\b\n\b\f\b\u0092\t\b\u0001\t\u0001\t\u0001\t"+
- "\u0005\t\u0097\b\t\n\t\f\t\u009a\t\t\u0001\t\u0003\t\u009d\b\t\u0001\t"+
- "\u0001\t\u0001\t\u0005\t\u00a2\b\t\n\t\f\t\u00a5\t\t\u0001\t\u0003\t\u00a8"+
- "\b\t\u0001\t\u0003\t\u00ab\b\t\u0001\t\u0000\u0002\f\u000e\n\u0000\u0002"+
- "\u0004\u0006\b\n\f\u000e\u0010\u0012\u0000\u0001\u0004\u0000\u0007\u0007"+
- "\t\t\r\r\u0010\u0010\u00be\u0000\u0014\u0001\u0000\u0000\u0000\u0002\""+
- "\u0001\u0000\u0000\u0000\u0004G\u0001\u0000\u0000\u0000\u0006I\u0001\u0000"+
- "\u0000\u0000\b\\\u0001\u0000\u0000\u0000\nc\u0001\u0000\u0000\u0000\f"+
- "i\u0001\u0000\u0000\u0000\u000ez\u0001\u0000\u0000\u0000\u0010\u0088\u0001"+
- "\u0000\u0000\u0000\u0012\u00aa\u0001\u0000\u0000\u0000\u0014\u001d\u0003"+
- "\f\u0006\u0000\u0015\u0017\u0005\u000f\u0000\u0000\u0016\u0015\u0001\u0000"+
- "\u0000\u0000\u0017\u001a\u0001\u0000\u0000\u0000\u0018\u0016\u0001\u0000"+
- "\u0000\u0000\u0018\u0019\u0001\u0000\u0000\u0000\u0019\u001e\u0001\u0000"+
- "\u0000\u0000\u001a\u0018\u0001\u0000\u0000\u0000\u001b\u001e\u0005\u0007"+
- "\u0000\u0000\u001c\u001e\u0005\u000e\u0000\u0000\u001d\u0018\u0001\u0000"+
- "\u0000\u0000\u001d\u001b\u0001\u0000\u0000\u0000\u001d\u001c\u0001\u0000"+
- "\u0000\u0000\u001e\u001f\u0001\u0000\u0000\u0000\u001f \u0003\u0012\t"+
- "\u0000 !\u0003\u0002\u0001\u0000!\u0001\u0001\u0000\u0000\u0000\"$\u0005"+
- "\u0002\u0000\u0000#%\u0003\u0004\u0002\u0000$#\u0001\u0000\u0000\u0000"+
- "$%\u0001\u0000\u0000\u0000%&\u0001\u0000\u0000\u0000&\'\u0005\u0003\u0000"+
- "\u0000\'\u0003\u0001\u0000\u0000\u0000(3\u0003\u0006\u0003\u0000)-\u0005"+
- "\u0006\u0000\u0000*,\u0005\u000f\u0000\u0000+*\u0001\u0000\u0000\u0000"+
- ",/\u0001\u0000\u0000\u0000-+\u0001\u0000\u0000\u0000-.\u0001\u0000\u0000"+
- "\u0000.0\u0001\u0000\u0000\u0000/-\u0001\u0000\u0000\u000002\u0003\b\u0004"+
- "\u00001)\u0001\u0000\u0000\u000025\u0001\u0000\u0000\u000031\u0001\u0000"+
- "\u0000\u000034\u0001\u0000\u0000\u00004H\u0001\u0000\u0000\u000053\u0001"+
- "\u0000\u0000\u00006A\u0003\n\u0005\u00007;\u0005\u0006\u0000\u00008:\u0005"+
- "\u000f\u0000\u000098\u0001\u0000\u0000\u0000:=\u0001\u0000\u0000\u0000"+
- ";9\u0001\u0000\u0000\u0000;<\u0001\u0000\u0000\u0000<>\u0001\u0000\u0000"+
- "\u0000=;\u0001\u0000\u0000\u0000>@\u0003\u0004\u0002\u0000?7\u0001\u0000"+
- "\u0000\u0000@C\u0001\u0000\u0000\u0000A?\u0001\u0000\u0000\u0000AB\u0001"+
- "\u0000\u0000\u0000BH\u0001\u0000\u0000\u0000CA\u0001\u0000\u0000\u0000"+
- "DE\u0003\u000e\u0007\u0000EF\u0005\f\u0000\u0000FH\u0001\u0000\u0000\u0000"+
- "G(\u0001\u0000\u0000\u0000G6\u0001\u0000\u0000\u0000GD\u0001\u0000\u0000"+
- "\u0000H\u0005\u0001\u0000\u0000\u0000IJ\u0005\r\u0000\u0000J\u0007\u0001"+
- "\u0000\u0000\u0000KV\u0003\n\u0005\u0000LP\u0005\u0006\u0000\u0000MO\u0005"+
- "\u000f\u0000\u0000NM\u0001\u0000\u0000\u0000OR\u0001\u0000\u0000\u0000"+
- "PN\u0001\u0000\u0000\u0000PQ\u0001\u0000\u0000\u0000QS\u0001\u0000\u0000"+
- "\u0000RP\u0001\u0000\u0000\u0000SU\u0003\b\u0004\u0000TL\u0001\u0000\u0000"+
- "\u0000UX\u0001\u0000\u0000\u0000VT\u0001\u0000\u0000\u0000VW\u0001\u0000"+
- "\u0000\u0000W]\u0001\u0000\u0000\u0000XV\u0001\u0000\u0000\u0000YZ\u0003"+
- "\u000e\u0007\u0000Z[\u0005\f\u0000\u0000[]\u0001\u0000\u0000\u0000\\K"+
- "\u0001\u0000\u0000\u0000\\Y\u0001\u0000\u0000\u0000]\t\u0001\u0000\u0000"+
- "\u0000^_\u0005\u0002\u0000\u0000_`\u0003\u000e\u0007\u0000`a\u0005\u0003"+
- "\u0000\u0000ad\u0001\u0000\u0000\u0000bd\u0003\u000e\u0007\u0000c^\u0001"+
- "\u0000\u0000\u0000cb\u0001\u0000\u0000\u0000d\u000b\u0001\u0000\u0000"+
- "\u0000ef\u0006\u0006\uffff\uffff\u0000fj\u0003\u0010\b\u0000gh\u0005\b"+
- "\u0000\u0000hj\u0003\f\u0006\u0003ie\u0001\u0000\u0000\u0000ig\u0001\u0000"+
- "\u0000\u0000js\u0001\u0000\u0000\u0000kl\n\u0002\u0000\u0000lm\u0005\n"+
- "\u0000\u0000mr\u0003\f\u0006\u0003no\n\u0001\u0000\u0000op\u0005\u000b"+
- "\u0000\u0000pr\u0003\f\u0006\u0002qk\u0001\u0000\u0000\u0000qn\u0001\u0000"+
- "\u0000\u0000ru\u0001\u0000\u0000\u0000sq\u0001\u0000\u0000\u0000st\u0001"+
- "\u0000\u0000\u0000t\r\u0001\u0000\u0000\u0000us\u0001\u0000\u0000\u0000"+
- "vw\u0006\u0007\uffff\uffff\u0000w{\u0003\u0010\b\u0000xy\u0005\b\u0000"+
- "\u0000y{\u0003\u000e\u0007\u0003zv\u0001\u0000\u0000\u0000zx\u0001\u0000"+
- "\u0000\u0000{\u0084\u0001\u0000\u0000\u0000|}\n\u0002\u0000\u0000}~\u0005"+
- "\n\u0000\u0000~\u0083\u0003\u000e\u0007\u0003\u007f\u0080\n\u0001\u0000"+
- "\u0000\u0080\u0081\u0005\u000b\u0000\u0000\u0081\u0083\u0003\u000e\u0007"+
- "\u0002\u0082|\u0001\u0000\u0000\u0000\u0082\u007f\u0001\u0000\u0000\u0000"+
- "\u0083\u0086\u0001\u0000\u0000\u0000\u0084\u0082\u0001\u0000\u0000\u0000"+
- "\u0084\u0085\u0001\u0000\u0000\u0000\u0085\u000f\u0001\u0000\u0000\u0000"+
- "\u0086\u0084\u0001\u0000\u0000\u0000\u0087\u0089\u0007\u0000\u0000\u0000"+
- "\u0088\u0087\u0001\u0000\u0000\u0000\u0089\u008a\u0001\u0000\u0000\u0000"+
- "\u008a\u0088\u0001\u0000\u0000\u0000\u008a\u008b\u0001\u0000\u0000\u0000"+
- "\u008b\u0090\u0001\u0000\u0000\u0000\u008c\u008d\u0005\u0004\u0000\u0000"+
- "\u008d\u008f\u0005\u0005\u0000\u0000\u008e\u008c\u0001\u0000\u0000\u0000"+
- "\u008f\u0092\u0001\u0000\u0000\u0000\u0090\u008e\u0001\u0000\u0000\u0000"+
- "\u0090\u0091\u0001\u0000\u0000\u0000\u0091\u0011\u0001\u0000\u0000\u0000"+
- "\u0092\u0090\u0001\u0000\u0000\u0000\u0093\u0098\u0005\u0010\u0000\u0000"+
- "\u0094\u0095\u0005\t\u0000\u0000\u0095\u0097\u0005\u0010\u0000\u0000\u0096"+
- "\u0094\u0001\u0000\u0000\u0000\u0097\u009a\u0001\u0000\u0000\u0000\u0098"+
- "\u0096\u0001\u0000\u0000\u0000\u0098\u0099\u0001\u0000\u0000\u0000\u0099"+
- "\u009c\u0001\u0000\u0000\u0000\u009a\u0098\u0001\u0000\u0000\u0000\u009b"+
- "\u009d\u0005\t\u0000\u0000\u009c\u009b\u0001\u0000\u0000\u0000\u009c\u009d"+
- "\u0001\u0000\u0000\u0000\u009d\u00ab\u0001\u0000\u0000\u0000\u009e\u00a3"+
- "\u0005\t\u0000\u0000\u009f\u00a0\u0005\u0010\u0000\u0000\u00a0\u00a2\u0005"+
- "\t\u0000\u0000\u00a1\u009f\u0001\u0000\u0000\u0000\u00a2\u00a5\u0001\u0000"+
- "\u0000\u0000\u00a3\u00a1\u0001\u0000\u0000\u0000\u00a3\u00a4\u0001\u0000"+
- "\u0000\u0000\u00a4\u00a7\u0001\u0000\u0000\u0000\u00a5\u00a3\u0001\u0000"+
- "\u0000\u0000\u00a6\u00a8\u0005\u0010\u0000\u0000\u00a7\u00a6\u0001\u0000"+
- "\u0000\u0000\u00a7\u00a8\u0001\u0000\u0000\u0000\u00a8\u00ab\u0001\u0000"+
- "\u0000\u0000\u00a9\u00ab\u0005\u0001\u0000\u0000\u00aa\u0093\u0001\u0000"+
- "\u0000\u0000\u00aa\u009e\u0001\u0000\u0000\u0000\u00aa\u00a9\u0001\u0000"+
- "\u0000\u0000\u00ab\u0013\u0001\u0000\u0000\u0000\u0019\u0018\u001d$-3"+
- ";AGPV\\ciqsz\u0082\u0084\u008a\u0090\u0098\u009c\u00a3\u00a7\u00aa";
+ "\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0001\u0000\u0001\u0000"+
+ "\u0005\u0000\u0019\b\u0000\n\u0000\f\u0000\u001c\t\u0000\u0001\u0000\u0001"+
+ "\u0000\u0003\u0000 \b\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+
+ "\u0001\u0001\u0001\u0003\u0001\'\b\u0001\u0001\u0001\u0001\u0001\u0001"+
+ "\u0002\u0001\u0002\u0001\u0002\u0005\u0002.\b\u0002\n\u0002\f\u00021\t"+
+ "\u0002\u0001\u0002\u0005\u00024\b\u0002\n\u0002\f\u00027\t\u0002\u0001"+
+ "\u0002\u0001\u0002\u0001\u0002\u0005\u0002<\b\u0002\n\u0002\f\u0002?\t"+
+ "\u0002\u0001\u0002\u0005\u0002B\b\u0002\n\u0002\f\u0002E\t\u0002\u0001"+
+ "\u0002\u0001\u0002\u0001\u0002\u0005\u0002J\b\u0002\n\u0002\f\u0002M\t"+
+ "\u0002\u0001\u0002\u0005\u0002P\b\u0002\n\u0002\f\u0002S\t\u0002\u0001"+
+ "\u0002\u0001\u0002\u0001\u0002\u0003\u0002X\b\u0002\u0001\u0003\u0001"+
+ "\u0003\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0005"+
+ "\u0005a\b\u0005\n\u0005\f\u0005d\t\u0005\u0001\u0005\u0005\u0005g\b\u0005"+
+ "\n\u0005\f\u0005j\t\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0003\u0005"+
+ "o\b\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006"+
+ "\u0003\u0006v\b\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
+ "\u0003\u0007|\b\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
+ "\u0001\u0007\u0001\u0007\u0005\u0007\u0084\b\u0007\n\u0007\f\u0007\u0087"+
+ "\t\u0007\u0001\b\u0001\b\u0001\b\u0001\b\u0003\b\u008d\b\b\u0001\b\u0001"+
+ "\b\u0001\b\u0001\b\u0001\b\u0001\b\u0005\b\u0095\b\b\n\b\f\b\u0098\t\b"+
+ "\u0001\t\u0004\t\u009b\b\t\u000b\t\f\t\u009c\u0001\t\u0001\t\u0005\t\u00a1"+
+ "\b\t\n\t\f\t\u00a4\t\t\u0001\n\u0001\n\u0001\n\u0005\n\u00a9\b\n\n\n\f"+
+ "\n\u00ac\t\n\u0001\n\u0003\n\u00af\b\n\u0001\n\u0001\n\u0001\n\u0005\n"+
+ "\u00b4\b\n\n\n\f\n\u00b7\t\n\u0001\n\u0003\n\u00ba\b\n\u0001\n\u0003\n"+
+ "\u00bd\b\n\u0001\n\u0000\u0002\u000e\u0010\u000b\u0000\u0002\u0004\u0006"+
+ "\b\n\f\u000e\u0010\u0012\u0014\u0000\u0001\u0004\u0000\u0007\u0007\t\t"+
+ "\r\r\u0010\u0010\u00d2\u0000\u0016\u0001\u0000\u0000\u0000\u0002$\u0001"+
+ "\u0000\u0000\u0000\u0004W\u0001\u0000\u0000\u0000\u0006Y\u0001\u0000\u0000"+
+ "\u0000\b[\u0001\u0000\u0000\u0000\nn\u0001\u0000\u0000\u0000\fu\u0001"+
+ "\u0000\u0000\u0000\u000e{\u0001\u0000\u0000\u0000\u0010\u008c\u0001\u0000"+
+ "\u0000\u0000\u0012\u009a\u0001\u0000\u0000\u0000\u0014\u00bc\u0001\u0000"+
+ "\u0000\u0000\u0016\u001f\u0003\u000e\u0007\u0000\u0017\u0019\u0005\u000f"+
+ "\u0000\u0000\u0018\u0017\u0001\u0000\u0000\u0000\u0019\u001c\u0001\u0000"+
+ "\u0000\u0000\u001a\u0018\u0001\u0000\u0000\u0000\u001a\u001b\u0001\u0000"+
+ "\u0000\u0000\u001b \u0001\u0000\u0000\u0000\u001c\u001a\u0001\u0000\u0000"+
+ "\u0000\u001d \u0005\u0007\u0000\u0000\u001e \u0005\u000e\u0000\u0000\u001f"+
+ "\u001a\u0001\u0000\u0000\u0000\u001f\u001d\u0001\u0000\u0000\u0000\u001f"+
+ "\u001e\u0001\u0000\u0000\u0000 !\u0001\u0000\u0000\u0000!\"\u0003\u0014"+
+ "\n\u0000\"#\u0003\u0002\u0001\u0000#\u0001\u0001\u0000\u0000\u0000$&\u0005"+
+ "\u0002\u0000\u0000%\'\u0003\u0004\u0002\u0000&%\u0001\u0000\u0000\u0000"+
+ "&\'\u0001\u0000\u0000\u0000\'(\u0001\u0000\u0000\u0000()\u0005\u0003\u0000"+
+ "\u0000)\u0003\u0001\u0000\u0000\u0000*5\u0003\b\u0004\u0000+/\u0005\u0006"+
+ "\u0000\u0000,.\u0005\u000f\u0000\u0000-,\u0001\u0000\u0000\u0000.1\u0001"+
+ "\u0000\u0000\u0000/-\u0001\u0000\u0000\u0000/0\u0001\u0000\u0000\u0000"+
+ "02\u0001\u0000\u0000\u00001/\u0001\u0000\u0000\u000024\u0003\n\u0005\u0000"+
+ "3+\u0001\u0000\u0000\u000047\u0001\u0000\u0000\u000053\u0001\u0000\u0000"+
+ "\u000056\u0001\u0000\u0000\u00006X\u0001\u0000\u0000\u000075\u0001\u0000"+
+ "\u0000\u00008C\u0003\u0006\u0003\u00009=\u0005\u0006\u0000\u0000:<\u0005"+
+ "\u000f\u0000\u0000;:\u0001\u0000\u0000\u0000\u0001\u0000\u0000\u0000"+
+ "=;\u0001\u0000\u0000\u0000=>\u0001\u0000\u0000\u0000>@\u0001\u0000\u0000"+
+ "\u0000?=\u0001\u0000\u0000\u0000@B\u0003\u0004\u0002\u0000A9\u0001\u0000"+
+ "\u0000\u0000BE\u0001\u0000\u0000\u0000CA\u0001\u0000\u0000\u0000CD\u0001"+
+ "\u0000\u0000\u0000DX\u0001\u0000\u0000\u0000EC\u0001\u0000\u0000\u0000"+
+ "FQ\u0003\f\u0006\u0000GK\u0005\u0006\u0000\u0000HJ\u0005\u000f\u0000\u0000"+
+ "IH\u0001\u0000\u0000\u0000JM\u0001\u0000\u0000\u0000KI\u0001\u0000\u0000"+
+ "\u0000KL\u0001\u0000\u0000\u0000LN\u0001\u0000\u0000\u0000MK\u0001\u0000"+
+ "\u0000\u0000NP\u0003\u0004\u0002\u0000OG\u0001\u0000\u0000\u0000PS\u0001"+
+ "\u0000\u0000\u0000QO\u0001\u0000\u0000\u0000QR\u0001\u0000\u0000\u0000"+
+ "RX\u0001\u0000\u0000\u0000SQ\u0001\u0000\u0000\u0000TU\u0003\u0010\b\u0000"+
+ "UV\u0005\f\u0000\u0000VX\u0001\u0000\u0000\u0000W*\u0001\u0000\u0000\u0000"+
+ "W8\u0001\u0000\u0000\u0000WF\u0001\u0000\u0000\u0000WT\u0001\u0000\u0000"+
+ "\u0000X\u0005\u0001\u0000\u0000\u0000YZ\u0005\t\u0000\u0000Z\u0007\u0001"+
+ "\u0000\u0000\u0000[\\\u0005\r\u0000\u0000\\\t\u0001\u0000\u0000\u0000"+
+ "]h\u0003\f\u0006\u0000^b\u0005\u0006\u0000\u0000_a\u0005\u000f\u0000\u0000"+
+ "`_\u0001\u0000\u0000\u0000ad\u0001\u0000\u0000\u0000b`\u0001\u0000\u0000"+
+ "\u0000bc\u0001\u0000\u0000\u0000ce\u0001\u0000\u0000\u0000db\u0001\u0000"+
+ "\u0000\u0000eg\u0003\n\u0005\u0000f^\u0001\u0000\u0000\u0000gj\u0001\u0000"+
+ "\u0000\u0000hf\u0001\u0000\u0000\u0000hi\u0001\u0000\u0000\u0000io\u0001"+
+ "\u0000\u0000\u0000jh\u0001\u0000\u0000\u0000kl\u0003\u0010\b\u0000lm\u0005"+
+ "\f\u0000\u0000mo\u0001\u0000\u0000\u0000n]\u0001\u0000\u0000\u0000nk\u0001"+
+ "\u0000\u0000\u0000o\u000b\u0001\u0000\u0000\u0000pq\u0005\u0002\u0000"+
+ "\u0000qr\u0003\u0010\b\u0000rs\u0005\u0003\u0000\u0000sv\u0001\u0000\u0000"+
+ "\u0000tv\u0003\u0010\b\u0000up\u0001\u0000\u0000\u0000ut\u0001\u0000\u0000"+
+ "\u0000v\r\u0001\u0000\u0000\u0000wx\u0006\u0007\uffff\uffff\u0000x|\u0003"+
+ "\u0012\t\u0000yz\u0005\b\u0000\u0000z|\u0003\u000e\u0007\u0003{w\u0001"+
+ "\u0000\u0000\u0000{y\u0001\u0000\u0000\u0000|\u0085\u0001\u0000\u0000"+
+ "\u0000}~\n\u0002\u0000\u0000~\u007f\u0005\n\u0000\u0000\u007f\u0084\u0003"+
+ "\u000e\u0007\u0003\u0080\u0081\n\u0001\u0000\u0000\u0081\u0082\u0005\u000b"+
+ "\u0000\u0000\u0082\u0084\u0003\u000e\u0007\u0002\u0083}\u0001\u0000\u0000"+
+ "\u0000\u0083\u0080\u0001\u0000\u0000\u0000\u0084\u0087\u0001\u0000\u0000"+
+ "\u0000\u0085\u0083\u0001\u0000\u0000\u0000\u0085\u0086\u0001\u0000\u0000"+
+ "\u0000\u0086\u000f\u0001\u0000\u0000\u0000\u0087\u0085\u0001\u0000\u0000"+
+ "\u0000\u0088\u0089\u0006\b\uffff\uffff\u0000\u0089\u008d\u0003\u0012\t"+
+ "\u0000\u008a\u008b\u0005\b\u0000\u0000\u008b\u008d\u0003\u0010\b\u0003"+
+ "\u008c\u0088\u0001\u0000\u0000\u0000\u008c\u008a\u0001\u0000\u0000\u0000"+
+ "\u008d\u0096\u0001\u0000\u0000\u0000\u008e\u008f\n\u0002\u0000\u0000\u008f"+
+ "\u0090\u0005\n\u0000\u0000\u0090\u0095\u0003\u0010\b\u0003\u0091\u0092"+
+ "\n\u0001\u0000\u0000\u0092\u0093\u0005\u000b\u0000\u0000\u0093\u0095\u0003"+
+ "\u0010\b\u0002\u0094\u008e\u0001\u0000\u0000\u0000\u0094\u0091\u0001\u0000"+
+ "\u0000\u0000\u0095\u0098\u0001\u0000\u0000\u0000\u0096\u0094\u0001\u0000"+
+ "\u0000\u0000\u0096\u0097\u0001\u0000\u0000\u0000\u0097\u0011\u0001\u0000"+
+ "\u0000\u0000\u0098\u0096\u0001\u0000\u0000\u0000\u0099\u009b\u0007\u0000"+
+ "\u0000\u0000\u009a\u0099\u0001\u0000\u0000\u0000\u009b\u009c\u0001\u0000"+
+ "\u0000\u0000\u009c\u009a\u0001\u0000\u0000\u0000\u009c\u009d\u0001\u0000"+
+ "\u0000\u0000\u009d\u00a2\u0001\u0000\u0000\u0000\u009e\u009f\u0005\u0004"+
+ "\u0000\u0000\u009f\u00a1\u0005\u0005\u0000\u0000\u00a0\u009e\u0001\u0000"+
+ "\u0000\u0000\u00a1\u00a4\u0001\u0000\u0000\u0000\u00a2\u00a0\u0001\u0000"+
+ "\u0000\u0000\u00a2\u00a3\u0001\u0000\u0000\u0000\u00a3\u0013\u0001\u0000"+
+ "\u0000\u0000\u00a4\u00a2\u0001\u0000\u0000\u0000\u00a5\u00aa\u0005\u0010"+
+ "\u0000\u0000\u00a6\u00a7\u0005\t\u0000\u0000\u00a7\u00a9\u0005\u0010\u0000"+
+ "\u0000\u00a8\u00a6\u0001\u0000\u0000\u0000\u00a9\u00ac\u0001\u0000\u0000"+
+ "\u0000\u00aa\u00a8\u0001\u0000\u0000\u0000\u00aa\u00ab\u0001\u0000\u0000"+
+ "\u0000\u00ab\u00ae\u0001\u0000\u0000\u0000\u00ac\u00aa\u0001\u0000\u0000"+
+ "\u0000\u00ad\u00af\u0005\t\u0000\u0000\u00ae\u00ad\u0001\u0000\u0000\u0000"+
+ "\u00ae\u00af\u0001\u0000\u0000\u0000\u00af\u00bd\u0001\u0000\u0000\u0000"+
+ "\u00b0\u00b5\u0005\t\u0000\u0000\u00b1\u00b2\u0005\u0010\u0000\u0000\u00b2"+
+ "\u00b4\u0005\t\u0000\u0000\u00b3\u00b1\u0001\u0000\u0000\u0000\u00b4\u00b7"+
+ "\u0001\u0000\u0000\u0000\u00b5\u00b3\u0001\u0000\u0000\u0000\u00b5\u00b6"+
+ "\u0001\u0000\u0000\u0000\u00b6\u00b9\u0001\u0000\u0000\u0000\u00b7\u00b5"+
+ "\u0001\u0000\u0000\u0000\u00b8\u00ba\u0005\u0010\u0000\u0000\u00b9\u00b8"+
+ "\u0001\u0000\u0000\u0000\u00b9\u00ba\u0001\u0000\u0000\u0000\u00ba\u00bd"+
+ "\u0001\u0000\u0000\u0000\u00bb\u00bd\u0005\u0001\u0000\u0000\u00bc\u00a5"+
+ "\u0001\u0000\u0000\u0000\u00bc\u00b0\u0001\u0000\u0000\u0000\u00bc\u00bb"+
+ "\u0001\u0000\u0000\u0000\u00bd\u0015\u0001\u0000\u0000\u0000\u001b\u001a"+
+ "\u001f&/5=CKQWbhnu{\u0083\u0085\u008c\u0094\u0096\u009c\u00a2\u00aa\u00ae"+
+ "\u00b5\u00b9\u00bc";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseListener.java
index 656a1e6ef74..fa7c933d0eb 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseListener.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseListener.java
@@ -63,6 +63,18 @@ public class MethodSignatureParserBaseListener implements MethodSignatureParserL
* The default implementation does nothing.
*/
@Override public void exitFormalsPattern(MethodSignatureParser.FormalsPatternContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * The default implementation does nothing.
+ */
+ @Override public void enterWildcard(MethodSignatureParser.WildcardContext ctx) { }
+ /**
+ * {@inheritDoc}
+ *
+ * The default implementation does nothing.
+ */
+ @Override public void exitWildcard(MethodSignatureParser.WildcardContext ctx) { }
/**
* {@inheritDoc}
*
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseVisitor.java
index 82fc1d7db05..f0def86a7e3 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseVisitor.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserBaseVisitor.java
@@ -48,6 +48,13 @@ public class MethodSignatureParserBaseVisitor extends AbstractParseTreeVisito
* {@link #visitChildren} on {@code ctx}.
*/
@Override public T visitFormalsPattern(MethodSignatureParser.FormalsPatternContext ctx) { return visitChildren(ctx); }
+ /**
+ * {@inheritDoc}
+ *
+ * The default implementation returns the result of calling
+ * {@link #visitChildren} on {@code ctx}.
+ */
+ @Override public T visitWildcard(MethodSignatureParser.WildcardContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserListener.java
index c42b31be028..e93cb80c3a4 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserListener.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserListener.java
@@ -52,6 +52,16 @@ public interface MethodSignatureParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitFormalsPattern(MethodSignatureParser.FormalsPatternContext ctx);
+ /**
+ * Enter a parse tree produced by {@link MethodSignatureParser#wildcard}.
+ * @param ctx the parse tree
+ */
+ void enterWildcard(MethodSignatureParser.WildcardContext ctx);
+ /**
+ * Exit a parse tree produced by {@link MethodSignatureParser#wildcard}.
+ * @param ctx the parse tree
+ */
+ void exitWildcard(MethodSignatureParser.WildcardContext ctx);
/**
* Enter a parse tree produced by {@link MethodSignatureParser#dotDot}.
* @param ctx the parse tree
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserVisitor.java
index 33ea6300476..489fec68bd0 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserVisitor.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParserVisitor.java
@@ -43,6 +43,12 @@ public interface MethodSignatureParserVisitor extends ParseTreeVisitor {
* @return the visitor result
*/
T visitFormalsPattern(MethodSignatureParser.FormalsPatternContext ctx);
+ /**
+ * Visit a parse tree produced by {@link MethodSignatureParser#wildcard}.
+ * @param ctx the parse tree
+ * @return the visitor result
+ */
+ T visitWildcard(MethodSignatureParser.WildcardContext ctx);
/**
* Visit a parse tree produced by {@link MethodSignatureParser#dotDot}.
* @param ctx the parse tree
From d675b76376644bd25e7d2f199656b8718fbbedd5 Mon Sep 17 00:00:00 2001
From: Jente Sondervorst
Date: Wed, 30 Jul 2025 16:09:19 +0200
Subject: [PATCH 2/5] Added correct + more assertions resulting in another
fixed bug
---
.../openrewrite/java/MethodMatcherTest.java | 48 ++++++++++++++-----
.../org/openrewrite/java/MethodMatcher.java | 9 ++--
2 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
index bbf67b97670..6173f19f393 100644
--- a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
+++ b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
@@ -140,15 +140,49 @@ void matchesUnqualifiedJavaLangArguments() {
void matchesArgumentsWithWildcards() {
assertTrue(argRegex("A foo(java.util.*)").matcher("java.util.Map").matches());
assertTrue(argRegex("A foo(java..*)").matcher("java.util.Map").matches());
+ assertTrue(argRegex("A foo(*.util.*)").matcher("java.util.Map").matches());
+ assertTrue(argRegex("A foo(*..*)").matcher("java.util.Map").matches());
+ }
+
+ @Test
+ void matchesExactlyOneWithWildcard() {
+ assertTrue(argRegex("A foo(*)").matcher("int").matches());
+ assertTrue(argRegex("A foo(*, int)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(*, int)").matcher("double,int").matches());
+ assertTrue(argRegex("A foo(int, *)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(int, *)").matcher("int,double").matches());
+ assertTrue(argRegex("A foo(*, *)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(int, *, double)").matcher("int,int,double").matches());
+ assertTrue(argRegex("A foo(int, *, double)").matcher("int,double,double").matches());
+
+ assertFalse(argRegex("A foo(*)").matcher("").matches());
+ assertFalse(argRegex("A foo(*)").matcher("int,int").matches());
+ assertFalse(argRegex("A foo(*, int)").matcher("int").matches());
+ assertFalse(argRegex("A foo(*, int)").matcher("int,double").matches());
+ assertFalse(argRegex("A foo(int, *)").matcher("int").matches());
+ assertFalse(argRegex("A foo(int, *)").matcher("double,int").matches());
+ assertFalse(argRegex("A foo(*, *)").matcher("").matches());
+ assertFalse(argRegex("A foo(*, *)").matcher("int").matches());
+ assertFalse(argRegex("A foo(int, *, double)").matcher("int,double").matches());
+ assertFalse(argRegex("A foo(int, *, double)").matcher("double,int,double").matches());
}
@Test
void matchesArgumentsWithDotDot() {
assertTrue(argRegex("A foo(.., int)").matcher("int").matches());
assertTrue(argRegex("A foo(.., int)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(.., int)").matcher("double,int").matches());
+ assertFalse(argRegex("A foo(.., int)").matcher("int,double").matches());
assertTrue(argRegex("A foo(int, ..)").matcher("int").matches());
assertTrue(argRegex("A foo(int, ..)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(int, ..)").matcher("int,double").matches());
+ assertFalse(argRegex("A foo(int, ..)").matcher("double,int").matches());
+
+ assertTrue(argRegex("A foo(int, .., double)").matcher("int,double").matches());
+ assertTrue(argRegex("A foo(int, .., double)").matcher("int,int,double").matches());
+ assertTrue(argRegex("A foo(int, .., double)").matcher("int,double,double").matches());
+ assertFalse(argRegex("A foo(int, .., double)").matcher("double,int,double").matches());
assertTrue(argRegex("A foo(..)").matcher("").matches());
assertTrue(argRegex("A foo(..)").matcher("int").matches());
@@ -404,12 +438,10 @@ void matchUnknownTypesWildcardArguments() {
void matchUnknownTypesSingleWildcardArgument() {
var mi = asMethodInvocation("Assert.assertTrue(Foo.bar(), \"message\");");
assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, String)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, java.lang.String)").matches(mi, true));
assertTrue(new MethodMatcher("org.junit.Assert assertTrue(String, *)").matches(mi, true));
- }
-
- @Test
- void matchUnknownTypesMultipleWildcardArgument() {
- var mi = asMethodInvocation("Assert.assertTrue(Foo.bar(), \"message\");");
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(double, *)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(java.lang.String, *)").matches(mi, true));
assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, *)").matches(mi, true));
}
@@ -420,12 +452,6 @@ class MyTest {
void test() {
%s
}
-
- class Foo {
- static String bar() {
- return "bar";
- }
- }
}
""", code)
)
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
index 8ec1d7513a0..fefbdef40cc 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java
@@ -399,8 +399,8 @@ private boolean matchesAllowingUnknownTypes(J.MethodInvocation method) {
final String argumentSignature = argumentsFromExpressionTypes(method);
final Pattern relaxedArgumentPattern = Pattern.compile(
- argumentPattern.pattern().replaceAll("((?:[a-zA-Z0-9]+\\.?)+)",
- "($1|" + JavaType.Unknown.getInstance().getFullyQualifiedName() + ")"));
+ argumentPattern.pattern().replaceAll("((?:(?:[a-zA-Z0-9]+(?:\\[\\.\\$])?)+(,)?)+)",
+ "($1|" + JavaType.Unknown.getInstance().getFullyQualifiedName() + "$2)"));
return relaxedArgumentPattern.matcher(argumentSignature).matches();
}
@@ -583,7 +583,10 @@ public String visitFormalParametersPattern(MethodSignatureParser.FormalParameter
argumentPatterns.add("(" + argument.getRegex() + ",)?");
}
} else { // FormalType
- if (i > 0 && arguments.get(i - 1) != Argument.DOT_DOT) {
+ // We cannot start with a comma
+ if (i == 1 && arguments.get(0) == Argument.DOT_DOT) {
+ argumentPatterns.add(argument.getRegex());
+ } else if (i > 0) {
argumentPatterns.add("," + argument.getRegex());
} else {
argumentPatterns.add(argument.getRegex());
From e7171364ae6560385aaf27b077ab6e7f665f6ae4 Mon Sep 17 00:00:00 2001
From: Jente Sondervorst
Date: Wed, 30 Jul 2025 16:37:33 +0200
Subject: [PATCH 3/5] Added some more assertions
---
.../java/org/openrewrite/java/MethodMatcherTest.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
index 6173f19f393..19dce4239a7 100644
--- a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
+++ b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
@@ -147,13 +147,20 @@ void matchesArgumentsWithWildcards() {
@Test
void matchesExactlyOneWithWildcard() {
assertTrue(argRegex("A foo(*)").matcher("int").matches());
+ assertTrue(argRegex("A foo(*)").matcher("java.lang.String").matches());
assertTrue(argRegex("A foo(*, int)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(*,int)").matcher("int,int").matches());
assertTrue(argRegex("A foo(*, int)").matcher("double,int").matches());
+ assertTrue(argRegex("A foo(*, int)").matcher("java.lang.String,int").matches());
+ assertTrue(argRegex("A foo(*, String)").matcher("java.lang.String,java.lang.String").matches());
assertTrue(argRegex("A foo(int, *)").matcher("int,int").matches());
assertTrue(argRegex("A foo(int, *)").matcher("int,double").matches());
+ assertTrue(argRegex("A foo(int,*)").matcher("int,double").matches());
assertTrue(argRegex("A foo(*, *)").matcher("int,int").matches());
+ assertTrue(argRegex("A foo(*,*)").matcher("int,int").matches());
assertTrue(argRegex("A foo(int, *, double)").matcher("int,int,double").matches());
assertTrue(argRegex("A foo(int, *, double)").matcher("int,double,double").matches());
+ assertTrue(argRegex("A foo(int,*,double)").matcher("int,double,double").matches());
assertFalse(argRegex("A foo(*)").matcher("").matches());
assertFalse(argRegex("A foo(*)").matcher("int,int").matches());
@@ -187,6 +194,9 @@ void matchesArgumentsWithDotDot() {
assertTrue(argRegex("A foo(..)").matcher("").matches());
assertTrue(argRegex("A foo(..)").matcher("int").matches());
assertTrue(argRegex("A foo(..)").matcher("int,int").matches());
+
+ assertTrue(argRegex("A foo(.., int)").matcher("double,double,int").matches());
+ assertTrue(argRegex("A foo(int, .., double)").matcher("int,double,java.lang.String,int,double").matches());
}
@Test
From 13f00779d9360066a28820739bd1a2deb39cab85 Mon Sep 17 00:00:00 2001
From: Jente Sondervorst
Date: Wed, 30 Jul 2025 16:47:54 +0200
Subject: [PATCH 4/5] Run rewrite recipe
---
.../grammar/MethodSignatureParser.java | 86 +++++++++----------
1 file changed, 41 insertions(+), 45 deletions(-)
diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
index 121b667db79..77393e33a51 100644
--- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
+++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureParser.java
@@ -40,14 +40,14 @@ public class MethodSignatureParser extends Parser {
BANG=8, WILDCARD=9, AND=10, OR=11, ELLIPSIS=12, DOTDOT=13, POUND=14, SPACE=15,
Identifier=16;
public static final int
- RULE_methodPattern = 0, RULE_formalParametersPattern = 1, RULE_formalsPattern = 2,
- RULE_wildcard = 3, RULE_dotDot = 4, RULE_formalsPatternAfterDotDot = 5,
- RULE_optionalParensTypePattern = 6, RULE_targetTypePattern = 7, RULE_formalTypePattern = 8,
+ RULE_methodPattern = 0, RULE_formalParametersPattern = 1, RULE_formalsPattern = 2,
+ RULE_wildcard = 3, RULE_dotDot = 4, RULE_formalsPatternAfterDotDot = 5,
+ RULE_optionalParensTypePattern = 6, RULE_targetTypePattern = 7, RULE_formalTypePattern = 8,
RULE_classNameOrInterface = 9, RULE_simpleNamePattern = 10;
private static String[] makeRuleNames() {
return new String[] {
- "methodPattern", "formalParametersPattern", "formalsPattern", "wildcard",
- "dotDot", "formalsPatternAfterDotDot", "optionalParensTypePattern", "targetTypePattern",
+ "methodPattern", "formalParametersPattern", "formalsPattern", "wildcard",
+ "dotDot", "formalsPatternAfterDotDot", "optionalParensTypePattern", "targetTypePattern",
"formalTypePattern", "classNameOrInterface", "simpleNamePattern"
};
}
@@ -149,9 +149,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitMethodPattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitMethodPattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final MethodPatternContext methodPattern() throws RecognitionException {
@@ -240,9 +240,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitFormalParametersPattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitFormalParametersPattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final FormalParametersPatternContext formalParametersPattern() throws RecognitionException {
@@ -328,9 +328,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitFormalsPattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitFormalsPattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final FormalsPatternContext formalsPattern() throws RecognitionException {
@@ -451,7 +451,7 @@ public final FormalsPatternContext formalsPattern() throws RecognitionException
setState(78);
formalsPattern();
}
- }
+ }
}
setState(83);
_errHandler.sync(this);
@@ -498,9 +498,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitWildcard(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitWildcard(this);
+ return visitor.visitChildren(this);
+ }
}
public final WildcardContext wildcard() throws RecognitionException {
@@ -541,9 +541,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitDotDot(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitDotDot(this);
+ return visitor.visitChildren(this);
+ }
}
public final DotDotContext dotDot() throws RecognitionException {
@@ -604,9 +604,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitFormalsPatternAfterDotDot(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitFormalsPatternAfterDotDot(this);
+ return visitor.visitChildren(this);
+ }
}
public final FormalsPatternAfterDotDotContext formalsPatternAfterDotDot() throws RecognitionException {
@@ -700,9 +700,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitOptionalParensTypePattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitOptionalParensTypePattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final OptionalParensTypePatternContext optionalParensTypePattern() throws RecognitionException {
@@ -777,9 +777,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitTargetTypePattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitTargetTypePattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final TargetTypePatternContext targetTypePattern() throws RecognitionException {
@@ -790,7 +790,6 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
TargetTypePatternContext _localctx = new TargetTypePatternContext(_ctx, _parentState);
- TargetTypePatternContext _prevctx = _localctx;
int _startState = 14;
enterRecursionRule(_localctx, 14, RULE_targetTypePattern, _p);
try {
@@ -827,7 +826,6 @@ private TargetTypePatternContext targetTypePattern(int _p) throws RecognitionExc
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
- _prevctx = _localctx;
{
setState(131);
_errHandler.sync(this);
@@ -904,9 +902,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitFormalTypePattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitFormalTypePattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final FormalTypePatternContext formalTypePattern() throws RecognitionException {
@@ -917,7 +915,6 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
ParserRuleContext _parentctx = _ctx;
int _parentState = getState();
FormalTypePatternContext _localctx = new FormalTypePatternContext(_ctx, _parentState);
- FormalTypePatternContext _prevctx = _localctx;
int _startState = 16;
enterRecursionRule(_localctx, 16, RULE_formalTypePattern, _p);
try {
@@ -954,7 +951,6 @@ private FormalTypePatternContext formalTypePattern(int _p) throws RecognitionExc
while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
if ( _alt==1 ) {
if ( _parseListeners!=null ) triggerExitRuleEvent();
- _prevctx = _localctx;
{
setState(148);
_errHandler.sync(this);
@@ -1043,9 +1039,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitClassNameOrInterface(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitClassNameOrInterface(this);
+ return visitor.visitChildren(this);
+ }
}
public final ClassNameOrInterfaceContext classNameOrInterface() throws RecognitionException {
@@ -1056,7 +1052,7 @@ public final ClassNameOrInterfaceContext classNameOrInterface() throws Recogniti
int _alt;
enterOuterAlt(_localctx, 1);
{
- setState(154);
+ setState(154);
_errHandler.sync(this);
_alt = 1;
do {
@@ -1080,7 +1076,7 @@ public final ClassNameOrInterfaceContext classNameOrInterface() throws Recogniti
default:
throw new NoViableAltException(this);
}
- setState(156);
+ setState(156);
_errHandler.sync(this);
_alt = getInterpreter().adaptivePredict(_input,20,_ctx);
} while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER );
@@ -1140,9 +1136,9 @@ public void exitRule(ParseTreeListener listener) {
}
@Override
public T accept(ParseTreeVisitor extends T> visitor) {
- if ( visitor instanceof MethodSignatureParserVisitor ) return ((MethodSignatureParserVisitor extends T>)visitor).visitSimpleNamePattern(this);
- else return visitor.visitChildren(this);
- }
+ if (visitor instanceof MethodSignatureParserVisitor) return ((MethodSignatureParserVisitor extends T>) visitor).visitSimpleNamePattern(this);
+ return visitor.visitChildren(this);
+ }
}
public final SimpleNamePatternContext simpleNamePattern() throws RecognitionException {
From 07d31e5fefdf7b6cace57145c00a84632e9c4c50 Mon Sep 17 00:00:00 2001
From: Tim te Beek
Date: Mon, 4 Aug 2025 21:56:18 +0200
Subject: [PATCH 5/5] Show change in behavior when `Foo.bar()` type information
present
---
.../openrewrite/java/MethodMatcherTest.java | 29 ++++++++++++++++---
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
index 19dce4239a7..6042a903c7a 100644
--- a/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
+++ b/rewrite-java-test/src/test/java/org/openrewrite/java/MethodMatcherTest.java
@@ -15,6 +15,7 @@
*/
package org.openrewrite.java;
+import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
@@ -455,15 +456,35 @@ void matchUnknownTypesSingleWildcardArgument() {
assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, *)").matches(mi, true));
}
- static J.MethodInvocation asMethodInvocation(String code) {
- var cu = JavaParser.fromJavaVersion().build().parse(
- String.format("""
+ @Issue("https://github.com/openrewrite/rewrite/pull/5833")
+ @Test
+ void matchKnownTypesSingleWildcardArgument() {
+ var mi = asMethodInvocation("Assert.assertTrue(Foo.bar(), \"message\");", """
+ class Foo {
+ static String bar() {
+ return "bar";
+ }
+ }
+ """);
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, String)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, java.lang.String)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(String, *)").matches(mi, true));
+ assertFalse(new MethodMatcher("org.junit.Assert assertTrue(double, *)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(java.lang.String, *)").matches(mi, true));
+ assertTrue(new MethodMatcher("org.junit.Assert assertTrue(*, *)").matches(mi, true));
+ }
+
+ static J.MethodInvocation asMethodInvocation(String code, @Language("java") String... dependsOn) {
+ var cu = JavaParser.fromJavaVersion().dependsOn(dependsOn).build()
+ .parse(
+ """
+ import org.junit.Assert;
class MyTest {
void test() {
%s
}
}
- """, code)
+ """.formatted(code)
)
.findFirst()
.map(J.CompilationUnit.class::cast)