From ba69707bada394155c759974c232e3d14811be63 Mon Sep 17 00:00:00 2001 From: Jonathan Schneider Date: Fri, 29 Sep 2023 10:48:41 -0700 Subject: [PATCH] Named JavaTemplate parameters --- .../org/openrewrite/internal/StringUtils.java | 1 - .../java/JavaTemplateMatchTest.java | 42 +-- .../java/JavaTemplateNamedTest.java | 67 ++++ .../java/search/SemanticallyEqualTest.java | 47 ++- .../src/main/antlr/TemplateParameterLexer.g4 | 7 +- .../src/main/antlr/TemplateParameterParser.g4 | 15 +- .../org/openrewrite/java/JavaTemplate.java | 200 ------------ .../java/JavaTemplateSemanticallyEqual.java | 93 ++++-- .../grammar/AnnotationSignatureLexer.java | 13 +- .../grammar/AnnotationSignatureParser.java | 18 +- ...AnnotationSignatureParserBaseListener.java | 2 +- .../AnnotationSignatureParserBaseVisitor.java | 2 +- .../AnnotationSignatureParserListener.java | 2 +- .../AnnotationSignatureParserVisitor.java | 2 +- .../grammar/MethodSignatureLexer.java | 13 +- .../grammar/MethodSignatureParser.java | 18 +- .../MethodSignatureParserBaseListener.java | 2 +- .../MethodSignatureParserBaseVisitor.java | 2 +- .../MethodSignatureParserListener.java | 2 +- .../grammar/MethodSignatureParserVisitor.java | 2 +- .../grammar/TemplateParameterLexer.interp | 17 +- .../grammar/TemplateParameterLexer.java | 178 +++++----- .../grammar/TemplateParameterLexer.tokens | 23 +- .../grammar/TemplateParameterParser.interp | 15 +- .../grammar/TemplateParameterParser.java | 308 ++++++++++++++---- .../grammar/TemplateParameterParser.tokens | 23 +- .../TemplateParameterParserBaseListener.java | 38 ++- .../TemplateParameterParserBaseVisitor.java | 23 +- .../TemplateParameterParserListener.java | 32 +- .../TemplateParameterParserVisitor.java | 20 +- .../java/internal/template/Substitutions.java | 160 +++++---- .../openrewrite/java/template/Matcher.java | 25 -- .../openrewrite/java/template/Matches.java | 28 -- .../openrewrite/java/template/NotMatches.java | 28 -- .../openrewrite/java/template/Primitive.java | 26 -- .../java/template/package-info.java | 19 -- 36 files changed, 807 insertions(+), 706 deletions(-) create mode 100644 rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateNamedTest.java delete mode 100644 rewrite-java/src/main/java/org/openrewrite/java/template/Matcher.java delete mode 100644 rewrite-java/src/main/java/org/openrewrite/java/template/Matches.java delete mode 100644 rewrite-java/src/main/java/org/openrewrite/java/template/NotMatches.java delete mode 100644 rewrite-java/src/main/java/org/openrewrite/java/template/Primitive.java delete mode 100644 rewrite-java/src/main/java/org/openrewrite/java/template/package-info.java diff --git a/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java b/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java index c84f3fe7c0e..47cf15b95a0 100644 --- a/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java +++ b/rewrite-core/src/main/java/org/openrewrite/internal/StringUtils.java @@ -355,7 +355,6 @@ public static int indexOf(String text, Predicate test) { * @return the number of times the substring is found in the target. 0 if no occurrences are found. */ public static int countOccurrences(@NonNull String text, @NonNull String substring) { - if (text.isEmpty() || substring.isEmpty()) { return 0; } diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java index 29ff36230ba..35dff7db112 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateMatchTest.java @@ -16,7 +16,6 @@ package org.openrewrite.java; import org.junit.jupiter.api.Test; -import org.openrewrite.DocumentExample; import org.openrewrite.ExecutionContext; import org.openrewrite.java.tree.Expression; import org.openrewrite.java.tree.J; @@ -28,19 +27,15 @@ class JavaTemplateMatchTest implements RewriteTest { - // IMPORTANT: This test needs to stay at the top, so that the name of `JavaTemplateMatchTest$1_Equals1` matches the expectations - @DocumentExample - @SuppressWarnings("ConstantValue") + @SuppressWarnings({"ConstantValue", "ConstantConditions"}) @Test - void matchBinaryUsingCompile() { + void matchBinary() { rewriteRun( spec -> spec.recipe(toRecipe(() -> new JavaVisitor<>() { - // matches manually written class JavaTemplateMatchTest$1_Equals1 below - private final JavaTemplate template = JavaTemplate.compile(this, "Equals1", (Integer i) -> 1 == i).build(); - @Override public J visitBinary(J.Binary binary, ExecutionContext ctx) { - return template.matches(getCursor()) ? SearchResult.found(binary) : super.visitBinary(binary, ctx); + return JavaTemplate.matches("1 == #{any(int)}", getCursor()) ? + SearchResult.found(binary) : super.visitBinary(binary, ctx); } })), java( @@ -63,14 +58,14 @@ class Test { )); } - @SuppressWarnings("ConstantValue") + @SuppressWarnings("ConstantConditions") @Test - void matchBinary() { + void matchNamedParameter() { rewriteRun( spec -> spec.recipe(toRecipe(() -> new JavaVisitor<>() { @Override public J visitBinary(J.Binary binary, ExecutionContext ctx) { - return JavaTemplate.matches("1 == #{any(int)}", getCursor()) ? + return JavaTemplate.matches("#{n:any(int)} == #{n}", getCursor()) ? SearchResult.found(binary) : super.visitBinary(binary, ctx); } })), @@ -78,23 +73,19 @@ public J visitBinary(J.Binary binary, ExecutionContext ctx) { """ class Test { boolean b1 = 1 == 2; - boolean b2 = 1 == 3; - - boolean b3 = 2 == 1; + boolean b2 = 1 == 1; } """, """ class Test { - boolean b1 = /*~~>*/1 == 2; - boolean b2 = /*~~>*/1 == 3; - - boolean b3 = 2 == 1; + boolean b1 = 1 == 2; + boolean b2 = /*~~>*/1 == 1; } """ )); } - @SuppressWarnings("ConstantValue") + @SuppressWarnings({"ConstantValue", "ConstantConditions"}) @Test void extractParameterUsingMatcher() { rewriteRun( @@ -532,14 +523,3 @@ class Test { } } -/** - * This class looks like a class which would be generated by the `rewrite-templating` annotation processor - * and is used by the test {@link JavaTemplateMatchTest#matchBinaryUsingCompile()}. - */ -@SuppressWarnings("unused") -class JavaTemplateMatchTest$1_Equals1 { - static JavaTemplate.Builder getTemplate(JavaVisitor visitor) { - return JavaTemplate.builder("1 == #{any(int)}"); - } - -} diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateNamedTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateNamedTest.java new file mode 100644 index 00000000000..2a1eb937382 --- /dev/null +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/JavaTemplateNamedTest.java @@ -0,0 +1,67 @@ +/* + * Copyright 2023 the original author or authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * https://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openrewrite.java; + +import org.junit.jupiter.api.Test; +import org.openrewrite.ExecutionContext; +import org.openrewrite.java.tree.J; +import org.openrewrite.test.RewriteTest; + +import static org.openrewrite.java.Assertions.java; +import static org.openrewrite.test.RewriteTest.toRecipe; + +public class JavaTemplateNamedTest implements RewriteTest { + + @Test + void replaceSingleStatement() { + rewriteRun( + spec -> spec.recipe(toRecipe(() -> new JavaVisitor<>() { + @Override + public J visitAssert(J.Assert anAssert, ExecutionContext p) { + return JavaTemplate.builder( + """ + if(#{name:any(int)} != #{}) { + #{name}++; + }""" + ) + .build() + .apply(getCursor(), anAssert.getCoordinates().replace(), + ((J.Binary) anAssert.getCondition()).getLeft(), "1"); + } + })), + java( + """ + class Test { + int n; + void test() { + assert n == 0; + } + } + """, + """ + class Test { + int n; + void test() { + if (n != 1) { + n++; + } + } + } + """ + ) + ); + } +} diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/search/SemanticallyEqualTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/search/SemanticallyEqualTest.java index 13d22ad3289..0891839f8a1 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/search/SemanticallyEqualTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/search/SemanticallyEqualTest.java @@ -22,28 +22,49 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -public class SemanticallyEqualTest { +public class SemanticallyEqualTest { private final JavaParser javaParser = JavaParser.fromJavaVersion().build(); @Test void compareAbstractMethods() { - assertEqualToSelf(""" - abstract class A { - abstract void m(); - } - """); + assertEqualToSelf( + """ + abstract class A { + abstract void m(); + } + """ + ); } @Test void compareClassModifierLists() { - assertEqual(""" - public abstract class A { - } - """, """ - abstract public class A { - } - """); + assertEqual( + """ + public abstract class A { + } + """, + """ + abstract public class A { + } + """ + ); + } + + @Test + void compareLiterals() { + assertEqual( + """ + class A { + int n = 1; + } + """, + """ + class A { + int n = 1; + } + """ + ); } private void assertEqualToSelf(@Language("java") String a) { diff --git a/rewrite-java/src/main/antlr/TemplateParameterLexer.g4 b/rewrite-java/src/main/antlr/TemplateParameterLexer.g4 index d10291fb735..76ebd718835 100644 --- a/rewrite-java/src/main/antlr/TemplateParameterLexer.g4 +++ b/rewrite-java/src/main/antlr/TemplateParameterLexer.g4 @@ -2,12 +2,9 @@ lexer grammar TemplateParameterLexer; LPAREN : '('; RPAREN : ')'; -LBRACK : '['; -RBRACK : ']'; DOT : '.'; - +COLON : ':'; COMMA : ','; -SPACE : ' '; FullyQualifiedName : 'boolean' @@ -52,3 +49,5 @@ JavaLetterOrDigit [\uD800-\uDBFF] [\uDC00-\uDFFF] {Character.isJavaIdentifierPart(Character.toCodePoint((char)_input.LA(-2), (char)_input.LA(-1)))}? ; + +S : [ \t\r\n] -> skip ; diff --git a/rewrite-java/src/main/antlr/TemplateParameterParser.g4 b/rewrite-java/src/main/antlr/TemplateParameterParser.g4 index 127e6d6f2fb..e338698dbcb 100644 --- a/rewrite-java/src/main/antlr/TemplateParameterParser.g4 +++ b/rewrite-java/src/main/antlr/TemplateParameterParser.g4 @@ -3,7 +3,16 @@ parser grammar TemplateParameterParser; options { tokenVocab=TemplateParameterLexer; } matcherPattern - : matcherName LPAREN matcherParameter* RPAREN + : typedPattern + | parameterName + ; + +typedPattern + : (parameterName COLON)? patternType + ; + +patternType + : matcherName LPAREN ((matcherParameter COMMA)* matcherParameter)? RPAREN ; matcherParameter @@ -12,6 +21,10 @@ matcherParameter | Number ; +parameterName + : Identifier + ; + matcherName : Identifier ; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java index 0c1b994605a..ab383da372d 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplate.java @@ -27,8 +27,6 @@ import org.openrewrite.java.tree.JavaCoordinates; import org.openrewrite.template.SourceTemplate; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; @@ -59,10 +57,6 @@ public J2 apply(Cursor scope, JavaCoordinates coordinates, Object throw new IllegalArgumentException("`scope` must point to a J instance."); } - if (parameters.length != parameterCount) { - throw new IllegalArgumentException("This template requires " + parameterCount + " parameters."); - } - Substitutions substitutions = new Substitutions(code, parameters); String substitutedTemplate = substitutions.substitute(); onAfterVariableSubstitution.accept(substitutedTemplate); @@ -202,198 +196,4 @@ public JavaTemplate build() { onAfterVariableSubstitution, onBeforeParseTemplate); } } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P0 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P1 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P2 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P3 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P4 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P5 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P6 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P7 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P8 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P9 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, P10 p) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F0 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F1 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F2 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F3 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F4 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F5 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F6 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F7 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F8 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F9 f) { - return new PatternBuilder(name).build(owner); - } - - public static JavaTemplate.Builder compile(JavaVisitor owner, String name, F10 f) { - return new PatternBuilder(name).build(owner); - } - - @Value - @SuppressWarnings("unused") - static class PatternBuilder { - String name; - - public JavaTemplate.Builder build(JavaVisitor owner) { - try { - Class templateClass = Class.forName(owner.getClass().getName() + "_" + name, true, - owner.getClass().getClassLoader()); - Method getTemplate = templateClass.getDeclaredMethod("getTemplate", JavaVisitor.class); - return (JavaTemplate.Builder) getTemplate.invoke(null, owner); - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | - IllegalAccessException e) { - throw new RuntimeException(e); - } - } - } - - public interface P0 { - void accept() throws Exception; - } - - public interface P1 { - void accept(P1 p1) throws Exception; - } - - public interface P2 { - void accept(P1 p1, P2 p2) throws Exception; - } - - public interface P3 { - void accept(P1 p1, P2 p2, P3 p3) throws Exception; - } - - public interface P4 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4) throws Exception; - } - - public interface P5 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) throws Exception; - } - - public interface P6 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) throws Exception; - } - - public interface P7 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) throws Exception; - } - - public interface P8 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) throws Exception; - } - - public interface P9 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) throws Exception; - } - - public interface P10 { - void accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) throws Exception; - } - - public interface F0 { - R accept() throws Exception; - } - - public interface F1 { - R accept(P1 p1) throws Exception; - } - - public interface F2 { - R accept(P1 p1, P2 p2) throws Exception; - } - - public interface F3 { - R accept(P1 p1, P2 p2, P3 p3) throws Exception; - } - - public interface F4 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4) throws Exception; - } - - public interface F5 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) throws Exception; - } - - public interface F6 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) throws Exception; - } - - public interface F7 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) throws Exception; - } - - public interface F8 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) throws Exception; - } - - public interface F9 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) throws Exception; - } - - public interface F10 { - R accept(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) throws Exception; - } } diff --git a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplateSemanticallyEqual.java b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplateSemanticallyEqual.java index 7f02c4b037b..9b4f7c47697 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplateSemanticallyEqual.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/JavaTemplateSemanticallyEqual.java @@ -20,6 +20,7 @@ import org.antlr.v4.runtime.*; import org.openrewrite.Cursor; import org.openrewrite.internal.PropertyPlaceholderHelper; +import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.internal.grammar.TemplateParameterLexer; import org.openrewrite.java.internal.grammar.TemplateParameterParser; import org.openrewrite.java.search.SemanticallyEqual; @@ -27,10 +28,7 @@ import org.openrewrite.marker.Marker; import org.openrewrite.marker.Markers; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; +import java.util.*; import static org.openrewrite.Tree.randomId; @@ -68,6 +66,7 @@ private static J[] createTemplateParameters(String code) { List parameters = new ArrayList<>(); String substituted = code; + Map typedPatternByName = new HashMap<>(); while (true) { String previous = substituted; substituted = propertyPlaceholderHelper.replacePlaceholders(substituted, key -> { @@ -87,28 +86,24 @@ public void syntaxError(Recognizer recognizer, Object offendingSymbol, }); TemplateParameterParser.MatcherPatternContext ctx = parser.matcherPattern(); - String matcherName = ctx.matcherName().Identifier().getText(); - List params = ctx.matcherParameter(); - - if ("any".equals(matcherName)) { - String fqn; - - if (params.size() == 1) { - if (params.get(0).Identifier() != null) { - fqn = params.get(0).Identifier().getText(); - } else { - fqn = params.get(0).FullyQualifiedName().getText(); - } - } else { - fqn = "java.lang.Object"; + if (ctx.typedPattern() == null) { + String paramName = ctx.parameterName().Identifier().getText(); + s = typedPatternByName.get(paramName); + if (s == null) { + throw new IllegalArgumentException("The parameter " + paramName + " must be defined before it is referenced."); } + } else { + TemplateParameterParser.TypedPatternContext typedPattern = ctx.typedPattern(); + s = typedParameter(key, typedPattern); - s = fqn.replace("$", "."); + String name = null; + if (typedPattern.parameterName() != null) { + name = typedPattern.parameterName().Identifier().getText(); + typedPatternByName.put(name, s); + } - Markers markers = Markers.build(Collections.singleton(new TemplateParameter(randomId(), s))); + Markers markers = Markers.build(Collections.singleton(new TemplateParameter(randomId(), s, name))); parameters.add(new J.Empty(randomId(), Space.EMPTY, markers)); - } else { - throw new IllegalArgumentException("Invalid template matcher '" + key + "'"); } } else { throw new IllegalArgumentException("Only typed placeholders are allowed."); @@ -125,10 +120,34 @@ public void syntaxError(Recognizer recognizer, Object offendingSymbol, return parameters.toArray(new J[0]); } + private static String typedParameter(String key, TemplateParameterParser.TypedPatternContext typedPattern) { + String matcherName = typedPattern.patternType().matcherName().Identifier().getText(); + List params = typedPattern.patternType().matcherParameter(); + + if ("any".equals(matcherName)) { + String fqn; + + if (params.size() == 1) { + if (params.get(0).Identifier() != null) { + fqn = params.get(0).Identifier().getText(); + } else { + fqn = params.get(0).FullyQualifiedName().getText(); + } + } else { + fqn = "java.lang.Object"; + } + + return fqn.replace("$", "."); + } else { + throw new IllegalArgumentException("Invalid template matcher '" + key + "'"); + } + } + private static TemplateMatchResult matchTemplate(J templateTree, Cursor cursor) { JavaTemplateSemanticallyEqualVisitor semanticallyEqualVisitor = new JavaTemplateSemanticallyEqualVisitor(); semanticallyEqualVisitor.visit(templateTree, cursor.getValue(), cursor.getParentOrThrow()); - return new TemplateMatchResult(semanticallyEqualVisitor.isEqual(), semanticallyEqualVisitor.matchedParameters); + return new TemplateMatchResult(semanticallyEqualVisitor.isEqual(), new ArrayList<>( + semanticallyEqualVisitor.matchedParameters.keySet())); } @Value @@ -136,12 +155,14 @@ private static TemplateMatchResult matchTemplate(J templateTree, Cursor cursor) private static class TemplateParameter implements Marker { UUID id; String typeName; + + @Nullable + String name; } @SuppressWarnings("ConstantConditions") private static class JavaTemplateSemanticallyEqualVisitor extends SemanticallyEqualVisitor { - - final List matchedParameters = new ArrayList<>(); + final Map matchedParameters = new LinkedHashMap<>(); public JavaTemplateSemanticallyEqualVisitor() { super(true); @@ -150,16 +171,28 @@ public JavaTemplateSemanticallyEqualVisitor() { private boolean matchTemplateParameterPlaceholder(J.Empty empty, J j) { if (j instanceof TypedTree && !(j instanceof J.Primitive)) { TemplateParameter marker = (TemplateParameter) empty.getMarkers().getMarkers().get(0); - if ("java.lang.Object".equals(marker.typeName) - || TypeUtils.isAssignableTo(marker.typeName, ((TypedTree) j).getType())) { - return registerMatch(j); + + if (marker.name != null) { + for (Map.Entry matchedParameter : matchedParameters.entrySet()) { + if (matchedParameter.getValue().equals(marker.name)) { + if(!SemanticallyEqual.areEqual(matchedParameter.getKey(), j)) { + return false; + } + } + } + } + + if ("java.lang.Object".equals(marker.typeName) || + TypeUtils.isAssignableTo(marker.typeName, ((TypedTree) j).getType())) { + registerMatch(j, marker.name); + return true; } } return false; } - private boolean registerMatch(J j) { - return matchedParameters.add(j); + private void registerMatch(J j, @Nullable String name) { + matchedParameters.put(j, name); } @Override diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureLexer.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureLexer.java index d78f78e0922..d8f5167b9ab 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureLexer.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureLexer.java @@ -15,13 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class AnnotationSignatureLexer extends Lexer { @@ -466,4 +467,4 @@ private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParser.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParser.java index 25c799f6dca..b5509f2d7b3 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParser.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParser.java @@ -15,18 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.ParserATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; -import org.antlr.v4.runtime.tree.TerminalNode; - +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class AnnotationSignatureParser extends Parser { @@ -819,4 +815,4 @@ public final LiteralContext literal() throws RecognitionException { _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseListener.java index 42682126bfa..8981fb690ce 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseListener.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseListener.java @@ -172,4 +172,4 @@ public class AnnotationSignatureParserBaseListener implements AnnotationSignatur *

The default implementation does nothing.

*/ @Override public void visitErrorNode(ErrorNode node) { } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseVisitor.java index 72ba029e821..b5a9243d864 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserBaseVisitor.java @@ -97,4 +97,4 @@ public class AnnotationSignatureParserBaseVisitor extends AbstractParseTreeVi * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitLiteral(AnnotationSignatureParser.LiteralContext ctx) { return visitChildren(ctx); } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserListener.java index fbc14b536b0..2d2ffdec3d1 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserListener.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserListener.java @@ -122,4 +122,4 @@ public interface AnnotationSignatureParserListener extends ParseTreeListener { * @param ctx the parse tree */ void exitLiteral(AnnotationSignatureParser.LiteralContext ctx); -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserVisitor.java index fd48173e827..6c9ac7fef06 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/AnnotationSignatureParserVisitor.java @@ -85,4 +85,4 @@ public interface AnnotationSignatureParserVisitor extends ParseTreeVisitor * @return the visitor result */ T visitLiteral(AnnotationSignatureParser.LiteralContext ctx); -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureLexer.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureLexer.java index 19d1ff9dabe..d2c06236a3c 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureLexer.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/MethodSignatureLexer.java @@ -15,13 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class MethodSignatureLexer extends Lexer { @@ -225,4 +226,4 @@ private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ 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 6ee4625daf0..5780287cfc4 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 @@ -15,18 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.ParserATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; -import org.antlr.v4.runtime.tree.TerminalNode; - +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class MethodSignatureParser extends Parser { @@ -1305,4 +1301,4 @@ private boolean formalTypePattern_sempred(FormalTypePatternContext _localctx, in _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ No newline at end of file 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 ef78ae6eb75..7af9fbca205 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 @@ -172,4 +172,4 @@ public class MethodSignatureParserBaseListener implements MethodSignatureParserL *

The default implementation does nothing.

*/ @Override public void visitErrorNode(ErrorNode node) { } -} +} \ No newline at end of file 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 4a89c2f3200..35d2b2d4881 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 @@ -97,4 +97,4 @@ public class MethodSignatureParserBaseVisitor extends AbstractParseTreeVisito * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitSimpleNamePattern(MethodSignatureParser.SimpleNamePatternContext ctx) { return visitChildren(ctx); } -} +} \ No newline at end of file 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 e602579696a..3b234f8b3dc 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 @@ -122,4 +122,4 @@ public interface MethodSignatureParserListener extends ParseTreeListener { * @param ctx the parse tree */ void exitSimpleNamePattern(MethodSignatureParser.SimpleNamePatternContext ctx); -} +} \ No newline at end of file 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 8d1ff019f21..ff0b0e9c790 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 @@ -85,4 +85,4 @@ public interface MethodSignatureParserVisitor extends ParseTreeVisitor { * @return the visitor result */ T visitSimpleNamePattern(MethodSignatureParser.SimpleNamePatternContext ctx); -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.interp b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.interp index 6d8d8734c8c..363033850cf 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.interp +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.interp @@ -2,11 +2,10 @@ token literal names: null '(' ')' -'[' -']' '.' +':' ',' -' ' +null null null null @@ -15,28 +14,26 @@ token symbolic names: null LPAREN RPAREN -LBRACK -RBRACK DOT +COLON COMMA -SPACE FullyQualifiedName Number Identifier +S rule names: LPAREN RPAREN -LBRACK -RBRACK DOT +COLON COMMA -SPACE FullyQualifiedName Number Identifier JavaLetter JavaLetterOrDigit +S channel names: DEFAULT_TOKEN_CHANNEL @@ -46,4 +43,4 @@ mode names: DEFAULT_MODE atn: -[4, 0, 10, 127, 6, -1, 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, 2, 11, 7, 11, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 4, 7, 94, 8, 7, 11, 7, 12, 7, 95, 3, 7, 98, 8, 7, 1, 8, 4, 8, 101, 8, 8, 11, 8, 12, 8, 102, 1, 9, 1, 9, 5, 9, 107, 8, 9, 10, 9, 12, 9, 110, 9, 9, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 3, 10, 118, 8, 10, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 126, 8, 11, 0, 0, 12, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 0, 23, 0, 1, 0, 6, 1, 0, 48, 57, 4, 0, 36, 36, 65, 90, 95, 95, 97, 122, 2, 0, 0, 127, 55296, 56319, 1, 0, 55296, 56319, 1, 0, 56320, 57343, 5, 0, 36, 36, 48, 57, 65, 90, 95, 95, 97, 122, 141, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 1, 25, 1, 0, 0, 0, 3, 27, 1, 0, 0, 0, 5, 29, 1, 0, 0, 0, 7, 31, 1, 0, 0, 0, 9, 33, 1, 0, 0, 0, 11, 35, 1, 0, 0, 0, 13, 37, 1, 0, 0, 0, 15, 97, 1, 0, 0, 0, 17, 100, 1, 0, 0, 0, 19, 104, 1, 0, 0, 0, 21, 117, 1, 0, 0, 0, 23, 125, 1, 0, 0, 0, 25, 26, 5, 40, 0, 0, 26, 2, 1, 0, 0, 0, 27, 28, 5, 41, 0, 0, 28, 4, 1, 0, 0, 0, 29, 30, 5, 91, 0, 0, 30, 6, 1, 0, 0, 0, 31, 32, 5, 93, 0, 0, 32, 8, 1, 0, 0, 0, 33, 34, 5, 46, 0, 0, 34, 10, 1, 0, 0, 0, 35, 36, 5, 44, 0, 0, 36, 12, 1, 0, 0, 0, 37, 38, 5, 32, 0, 0, 38, 14, 1, 0, 0, 0, 39, 40, 5, 98, 0, 0, 40, 41, 5, 111, 0, 0, 41, 42, 5, 111, 0, 0, 42, 43, 5, 108, 0, 0, 43, 44, 5, 101, 0, 0, 44, 45, 5, 97, 0, 0, 45, 98, 5, 110, 0, 0, 46, 47, 5, 98, 0, 0, 47, 48, 5, 121, 0, 0, 48, 49, 5, 116, 0, 0, 49, 98, 5, 101, 0, 0, 50, 51, 5, 99, 0, 0, 51, 52, 5, 104, 0, 0, 52, 53, 5, 97, 0, 0, 53, 98, 5, 114, 0, 0, 54, 55, 5, 100, 0, 0, 55, 56, 5, 111, 0, 0, 56, 57, 5, 117, 0, 0, 57, 58, 5, 98, 0, 0, 58, 59, 5, 108, 0, 0, 59, 98, 5, 101, 0, 0, 60, 61, 5, 102, 0, 0, 61, 62, 5, 108, 0, 0, 62, 63, 5, 111, 0, 0, 63, 64, 5, 97, 0, 0, 64, 98, 5, 116, 0, 0, 65, 66, 5, 105, 0, 0, 66, 67, 5, 110, 0, 0, 67, 98, 5, 116, 0, 0, 68, 69, 5, 108, 0, 0, 69, 70, 5, 111, 0, 0, 70, 71, 5, 110, 0, 0, 71, 98, 5, 103, 0, 0, 72, 73, 5, 115, 0, 0, 73, 74, 5, 104, 0, 0, 74, 75, 5, 111, 0, 0, 75, 76, 5, 114, 0, 0, 76, 98, 5, 116, 0, 0, 77, 78, 5, 83, 0, 0, 78, 79, 5, 116, 0, 0, 79, 80, 5, 114, 0, 0, 80, 81, 5, 105, 0, 0, 81, 82, 5, 110, 0, 0, 82, 98, 5, 103, 0, 0, 83, 84, 5, 79, 0, 0, 84, 85, 5, 98, 0, 0, 85, 86, 5, 106, 0, 0, 86, 87, 5, 101, 0, 0, 87, 88, 5, 99, 0, 0, 88, 98, 5, 116, 0, 0, 89, 93, 3, 19, 9, 0, 90, 91, 3, 9, 4, 0, 91, 92, 3, 19, 9, 0, 92, 94, 1, 0, 0, 0, 93, 90, 1, 0, 0, 0, 94, 95, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 98, 1, 0, 0, 0, 97, 39, 1, 0, 0, 0, 97, 46, 1, 0, 0, 0, 97, 50, 1, 0, 0, 0, 97, 54, 1, 0, 0, 0, 97, 60, 1, 0, 0, 0, 97, 65, 1, 0, 0, 0, 97, 68, 1, 0, 0, 0, 97, 72, 1, 0, 0, 0, 97, 77, 1, 0, 0, 0, 97, 83, 1, 0, 0, 0, 97, 89, 1, 0, 0, 0, 98, 16, 1, 0, 0, 0, 99, 101, 7, 0, 0, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 18, 1, 0, 0, 0, 104, 108, 3, 21, 10, 0, 105, 107, 3, 23, 11, 0, 106, 105, 1, 0, 0, 0, 107, 110, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 108, 109, 1, 0, 0, 0, 109, 20, 1, 0, 0, 0, 110, 108, 1, 0, 0, 0, 111, 118, 7, 1, 0, 0, 112, 113, 8, 2, 0, 0, 113, 118, 4, 10, 0, 0, 114, 115, 7, 3, 0, 0, 115, 116, 7, 4, 0, 0, 116, 118, 4, 10, 1, 0, 117, 111, 1, 0, 0, 0, 117, 112, 1, 0, 0, 0, 117, 114, 1, 0, 0, 0, 118, 22, 1, 0, 0, 0, 119, 126, 7, 5, 0, 0, 120, 121, 8, 2, 0, 0, 121, 126, 4, 11, 2, 0, 122, 123, 7, 3, 0, 0, 123, 124, 7, 4, 0, 0, 124, 126, 4, 11, 3, 0, 125, 119, 1, 0, 0, 0, 125, 120, 1, 0, 0, 0, 125, 122, 1, 0, 0, 0, 126, 24, 1, 0, 0, 0, 7, 0, 95, 97, 102, 108, 117, 125, 0] \ No newline at end of file +[4, 0, 9, 125, 6, -1, 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, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 4, 5, 88, 8, 5, 11, 5, 12, 5, 89, 3, 5, 92, 8, 5, 1, 6, 4, 6, 95, 8, 6, 11, 6, 12, 6, 96, 1, 7, 1, 7, 5, 7, 101, 8, 7, 10, 7, 12, 7, 104, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 112, 8, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 3, 9, 120, 8, 9, 1, 10, 1, 10, 1, 10, 1, 10, 0, 0, 11, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 0, 19, 0, 21, 9, 1, 0, 7, 1, 0, 48, 57, 4, 0, 36, 36, 65, 90, 95, 95, 97, 122, 2, 0, 0, 127, 55296, 56319, 1, 0, 55296, 56319, 1, 0, 56320, 57343, 5, 0, 36, 36, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 139, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 1, 23, 1, 0, 0, 0, 3, 25, 1, 0, 0, 0, 5, 27, 1, 0, 0, 0, 7, 29, 1, 0, 0, 0, 9, 31, 1, 0, 0, 0, 11, 91, 1, 0, 0, 0, 13, 94, 1, 0, 0, 0, 15, 98, 1, 0, 0, 0, 17, 111, 1, 0, 0, 0, 19, 119, 1, 0, 0, 0, 21, 121, 1, 0, 0, 0, 23, 24, 5, 40, 0, 0, 24, 2, 1, 0, 0, 0, 25, 26, 5, 41, 0, 0, 26, 4, 1, 0, 0, 0, 27, 28, 5, 46, 0, 0, 28, 6, 1, 0, 0, 0, 29, 30, 5, 58, 0, 0, 30, 8, 1, 0, 0, 0, 31, 32, 5, 44, 0, 0, 32, 10, 1, 0, 0, 0, 33, 34, 5, 98, 0, 0, 34, 35, 5, 111, 0, 0, 35, 36, 5, 111, 0, 0, 36, 37, 5, 108, 0, 0, 37, 38, 5, 101, 0, 0, 38, 39, 5, 97, 0, 0, 39, 92, 5, 110, 0, 0, 40, 41, 5, 98, 0, 0, 41, 42, 5, 121, 0, 0, 42, 43, 5, 116, 0, 0, 43, 92, 5, 101, 0, 0, 44, 45, 5, 99, 0, 0, 45, 46, 5, 104, 0, 0, 46, 47, 5, 97, 0, 0, 47, 92, 5, 114, 0, 0, 48, 49, 5, 100, 0, 0, 49, 50, 5, 111, 0, 0, 50, 51, 5, 117, 0, 0, 51, 52, 5, 98, 0, 0, 52, 53, 5, 108, 0, 0, 53, 92, 5, 101, 0, 0, 54, 55, 5, 102, 0, 0, 55, 56, 5, 108, 0, 0, 56, 57, 5, 111, 0, 0, 57, 58, 5, 97, 0, 0, 58, 92, 5, 116, 0, 0, 59, 60, 5, 105, 0, 0, 60, 61, 5, 110, 0, 0, 61, 92, 5, 116, 0, 0, 62, 63, 5, 108, 0, 0, 63, 64, 5, 111, 0, 0, 64, 65, 5, 110, 0, 0, 65, 92, 5, 103, 0, 0, 66, 67, 5, 115, 0, 0, 67, 68, 5, 104, 0, 0, 68, 69, 5, 111, 0, 0, 69, 70, 5, 114, 0, 0, 70, 92, 5, 116, 0, 0, 71, 72, 5, 83, 0, 0, 72, 73, 5, 116, 0, 0, 73, 74, 5, 114, 0, 0, 74, 75, 5, 105, 0, 0, 75, 76, 5, 110, 0, 0, 76, 92, 5, 103, 0, 0, 77, 78, 5, 79, 0, 0, 78, 79, 5, 98, 0, 0, 79, 80, 5, 106, 0, 0, 80, 81, 5, 101, 0, 0, 81, 82, 5, 99, 0, 0, 82, 92, 5, 116, 0, 0, 83, 87, 3, 15, 7, 0, 84, 85, 3, 5, 2, 0, 85, 86, 3, 15, 7, 0, 86, 88, 1, 0, 0, 0, 87, 84, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 92, 1, 0, 0, 0, 91, 33, 1, 0, 0, 0, 91, 40, 1, 0, 0, 0, 91, 44, 1, 0, 0, 0, 91, 48, 1, 0, 0, 0, 91, 54, 1, 0, 0, 0, 91, 59, 1, 0, 0, 0, 91, 62, 1, 0, 0, 0, 91, 66, 1, 0, 0, 0, 91, 71, 1, 0, 0, 0, 91, 77, 1, 0, 0, 0, 91, 83, 1, 0, 0, 0, 92, 12, 1, 0, 0, 0, 93, 95, 7, 0, 0, 0, 94, 93, 1, 0, 0, 0, 95, 96, 1, 0, 0, 0, 96, 94, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 14, 1, 0, 0, 0, 98, 102, 3, 17, 8, 0, 99, 101, 3, 19, 9, 0, 100, 99, 1, 0, 0, 0, 101, 104, 1, 0, 0, 0, 102, 100, 1, 0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 16, 1, 0, 0, 0, 104, 102, 1, 0, 0, 0, 105, 112, 7, 1, 0, 0, 106, 107, 8, 2, 0, 0, 107, 112, 4, 8, 0, 0, 108, 109, 7, 3, 0, 0, 109, 110, 7, 4, 0, 0, 110, 112, 4, 8, 1, 0, 111, 105, 1, 0, 0, 0, 111, 106, 1, 0, 0, 0, 111, 108, 1, 0, 0, 0, 112, 18, 1, 0, 0, 0, 113, 120, 7, 5, 0, 0, 114, 115, 8, 2, 0, 0, 115, 120, 4, 9, 2, 0, 116, 117, 7, 3, 0, 0, 117, 118, 7, 4, 0, 0, 118, 120, 4, 9, 3, 0, 119, 113, 1, 0, 0, 0, 119, 114, 1, 0, 0, 0, 119, 116, 1, 0, 0, 0, 120, 20, 1, 0, 0, 0, 121, 122, 7, 6, 0, 0, 122, 123, 1, 0, 0, 0, 123, 124, 6, 10, 0, 0, 124, 22, 1, 0, 0, 0, 7, 0, 89, 91, 96, 102, 111, 119, 1, 6, 0, 0] \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.java index 6ce2ae45fed..6b321cb9924 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.java @@ -15,13 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class TemplateParameterLexer extends Lexer { @@ -31,8 +32,8 @@ public class TemplateParameterLexer extends Lexer { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - LPAREN=1, RPAREN=2, LBRACK=3, RBRACK=4, DOT=5, COMMA=6, SPACE=7, FullyQualifiedName=8, - Number=9, Identifier=10; + LPAREN=1, RPAREN=2, DOT=3, COLON=4, COMMA=5, FullyQualifiedName=6, Number=7, + Identifier=8, S=9; public static String[] channelNames = { "DEFAULT_TOKEN_CHANNEL", "HIDDEN" }; @@ -43,22 +44,22 @@ public class TemplateParameterLexer extends Lexer { private static String[] makeRuleNames() { return new String[] { - "LPAREN", "RPAREN", "LBRACK", "RBRACK", "DOT", "COMMA", "SPACE", "FullyQualifiedName", - "Number", "Identifier", "JavaLetter", "JavaLetterOrDigit" + "LPAREN", "RPAREN", "DOT", "COLON", "COMMA", "FullyQualifiedName", "Number", + "Identifier", "JavaLetter", "JavaLetterOrDigit", "S" }; } public static final String[] ruleNames = makeRuleNames(); private static String[] makeLiteralNames() { return new String[] { - null, "'('", "')'", "'['", "']'", "'.'", "','", "' '" + null, "'('", "')'", "'.'", "':'", "','" }; } private static final String[] _LITERAL_NAMES = makeLiteralNames(); private static String[] makeSymbolicNames() { return new String[] { - null, "LPAREN", "RPAREN", "LBRACK", "RBRACK", "DOT", "COMMA", "SPACE", - "FullyQualifiedName", "Number", "Identifier" + null, "LPAREN", "RPAREN", "DOT", "COLON", "COMMA", "FullyQualifiedName", + "Number", "Identifier", "S" }; } private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); @@ -122,9 +123,9 @@ public TemplateParameterLexer(CharStream input) { @Override public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { switch (ruleIndex) { - case 10: + case 8: return JavaLetter_sempred((RuleContext)_localctx, predIndex); - case 11: + case 9: return JavaLetterOrDigit_sempred((RuleContext)_localctx, predIndex); } return true; @@ -149,82 +150,81 @@ private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) } public static final String _serializedATN = - "\u0004\u0000\n\u007f\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ + "\u0004\u0000\t}\u0006\uffff\uffff\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\u0002\n\u0007\n\u0002\u000b"+ - "\u0007\u000b\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0002"+ - "\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0005"+ - "\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+ - "\u0001\u0007\u0001\u0007\u0001\u0007\u0004\u0007^\b\u0007\u000b\u0007"+ - "\f\u0007_\u0003\u0007b\b\u0007\u0001\b\u0004\be\b\b\u000b\b\f\bf\u0001"+ - "\t\u0001\t\u0005\tk\b\t\n\t\f\tn\t\t\u0001\n\u0001\n\u0001\n\u0001\n\u0001"+ - "\n\u0001\n\u0003\nv\b\n\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b"+ - "\u0001\u000b\u0001\u000b\u0003\u000b~\b\u000b\u0000\u0000\f\u0001\u0001"+ - "\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f"+ - "\b\u0011\t\u0013\n\u0015\u0000\u0017\u0000\u0001\u0000\u0006\u0001\u0000"+ - "09\u0004\u0000$$AZ__az\u0002\u0000\u0000\u007f\u8000\ud800\u8000\udbff"+ - "\u0001\u0000\u8000\ud800\u8000\udbff\u0001\u0000\u8000\udc00\u8000\udfff"+ - "\u0005\u0000$$09AZ__az\u008d\u0000\u0001\u0001\u0000\u0000\u0000\u0000"+ - "\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000"+ - "\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b"+ - "\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001"+ - "\u0000\u0000\u0000\u0000\u0011\u0001\u0000\u0000\u0000\u0000\u0013\u0001"+ - "\u0000\u0000\u0000\u0001\u0019\u0001\u0000\u0000\u0000\u0003\u001b\u0001"+ - "\u0000\u0000\u0000\u0005\u001d\u0001\u0000\u0000\u0000\u0007\u001f\u0001"+ - "\u0000\u0000\u0000\t!\u0001\u0000\u0000\u0000\u000b#\u0001\u0000\u0000"+ - "\u0000\r%\u0001\u0000\u0000\u0000\u000fa\u0001\u0000\u0000\u0000\u0011"+ - "d\u0001\u0000\u0000\u0000\u0013h\u0001\u0000\u0000\u0000\u0015u\u0001"+ - "\u0000\u0000\u0000\u0017}\u0001\u0000\u0000\u0000\u0019\u001a\u0005(\u0000"+ - "\u0000\u001a\u0002\u0001\u0000\u0000\u0000\u001b\u001c\u0005)\u0000\u0000"+ - "\u001c\u0004\u0001\u0000\u0000\u0000\u001d\u001e\u0005[\u0000\u0000\u001e"+ - "\u0006\u0001\u0000\u0000\u0000\u001f \u0005]\u0000\u0000 \b\u0001\u0000"+ - "\u0000\u0000!\"\u0005.\u0000\u0000\"\n\u0001\u0000\u0000\u0000#$\u0005"+ - ",\u0000\u0000$\f\u0001\u0000\u0000\u0000%&\u0005 \u0000\u0000&\u000e\u0001"+ - "\u0000\u0000\u0000\'(\u0005b\u0000\u0000()\u0005o\u0000\u0000)*\u0005"+ - "o\u0000\u0000*+\u0005l\u0000\u0000+,\u0005e\u0000\u0000,-\u0005a\u0000"+ - "\u0000-b\u0005n\u0000\u0000./\u0005b\u0000\u0000/0\u0005y\u0000\u0000"+ - "01\u0005t\u0000\u00001b\u0005e\u0000\u000023\u0005c\u0000\u000034\u0005"+ - "h\u0000\u000045\u0005a\u0000\u00005b\u0005r\u0000\u000067\u0005d\u0000"+ - "\u000078\u0005o\u0000\u000089\u0005u\u0000\u00009:\u0005b\u0000\u0000"+ - ":;\u0005l\u0000\u0000;b\u0005e\u0000\u0000<=\u0005f\u0000\u0000=>\u0005"+ - "l\u0000\u0000>?\u0005o\u0000\u0000?@\u0005a\u0000\u0000@b\u0005t\u0000"+ - "\u0000AB\u0005i\u0000\u0000BC\u0005n\u0000\u0000Cb\u0005t\u0000\u0000"+ - "DE\u0005l\u0000\u0000EF\u0005o\u0000\u0000FG\u0005n\u0000\u0000Gb\u0005"+ - "g\u0000\u0000HI\u0005s\u0000\u0000IJ\u0005h\u0000\u0000JK\u0005o\u0000"+ - "\u0000KL\u0005r\u0000\u0000Lb\u0005t\u0000\u0000MN\u0005S\u0000\u0000"+ - "NO\u0005t\u0000\u0000OP\u0005r\u0000\u0000PQ\u0005i\u0000\u0000QR\u0005"+ - "n\u0000\u0000Rb\u0005g\u0000\u0000ST\u0005O\u0000\u0000TU\u0005b\u0000"+ - "\u0000UV\u0005j\u0000\u0000VW\u0005e\u0000\u0000WX\u0005c\u0000\u0000"+ - "Xb\u0005t\u0000\u0000Y]\u0003\u0013\t\u0000Z[\u0003\t\u0004\u0000[\\\u0003"+ - "\u0013\t\u0000\\^\u0001\u0000\u0000\u0000]Z\u0001\u0000\u0000\u0000^_"+ - "\u0001\u0000\u0000\u0000_]\u0001\u0000\u0000\u0000_`\u0001\u0000\u0000"+ - "\u0000`b\u0001\u0000\u0000\u0000a\'\u0001\u0000\u0000\u0000a.\u0001\u0000"+ - "\u0000\u0000a2\u0001\u0000\u0000\u0000a6\u0001\u0000\u0000\u0000a<\u0001"+ - "\u0000\u0000\u0000aA\u0001\u0000\u0000\u0000aD\u0001\u0000\u0000\u0000"+ - "aH\u0001\u0000\u0000\u0000aM\u0001\u0000\u0000\u0000aS\u0001\u0000\u0000"+ - "\u0000aY\u0001\u0000\u0000\u0000b\u0010\u0001\u0000\u0000\u0000ce\u0007"+ - "\u0000\u0000\u0000dc\u0001\u0000\u0000\u0000ef\u0001\u0000\u0000\u0000"+ - "fd\u0001\u0000\u0000\u0000fg\u0001\u0000\u0000\u0000g\u0012\u0001\u0000"+ - "\u0000\u0000hl\u0003\u0015\n\u0000ik\u0003\u0017\u000b\u0000ji\u0001\u0000"+ - "\u0000\u0000kn\u0001\u0000\u0000\u0000lj\u0001\u0000\u0000\u0000lm\u0001"+ - "\u0000\u0000\u0000m\u0014\u0001\u0000\u0000\u0000nl\u0001\u0000\u0000"+ - "\u0000ov\u0007\u0001\u0000\u0000pq\b\u0002\u0000\u0000qv\u0004\n\u0000"+ - "\u0000rs\u0007\u0003\u0000\u0000st\u0007\u0004\u0000\u0000tv\u0004\n\u0001"+ - "\u0000uo\u0001\u0000\u0000\u0000up\u0001\u0000\u0000\u0000ur\u0001\u0000"+ - "\u0000\u0000v\u0016\u0001\u0000\u0000\u0000w~\u0007\u0005\u0000\u0000"+ - "xy\b\u0002\u0000\u0000y~\u0004\u000b\u0002\u0000z{\u0007\u0003\u0000\u0000"+ - "{|\u0007\u0004\u0000\u0000|~\u0004\u000b\u0003\u0000}w\u0001\u0000\u0000"+ - "\u0000}x\u0001\u0000\u0000\u0000}z\u0001\u0000\u0000\u0000~\u0018\u0001"+ - "\u0000\u0000\u0000\u0007\u0000_aflu}\u0000"; + "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0001\u0000"+ + "\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001\u0003"+ + "\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0001\u0005\u0001\u0005\u0004\u0005X\b\u0005\u000b\u0005"+ + "\f\u0005Y\u0003\u0005\\\b\u0005\u0001\u0006\u0004\u0006_\b\u0006\u000b"+ + "\u0006\f\u0006`\u0001\u0007\u0001\u0007\u0005\u0007e\b\u0007\n\u0007\f"+ + "\u0007h\t\u0007\u0001\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\b\u0003"+ + "\bp\b\b\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0001\t\u0003\tx\b\t\u0001"+ + "\n\u0001\n\u0001\n\u0001\n\u0000\u0000\u000b\u0001\u0001\u0003\u0002\u0005"+ + "\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\u0000\u0013"+ + "\u0000\u0015\t\u0001\u0000\u0007\u0001\u000009\u0004\u0000$$AZ__az\u0002"+ + "\u0000\u0000\u007f\u8000\ud800\u8000\udbff\u0001\u0000\u8000\ud800\u8000"+ + "\udbff\u0001\u0000\u8000\udc00\u8000\udfff\u0005\u0000$$09AZ__az\u0003"+ + "\u0000\t\n\r\r \u008b\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003"+ + "\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007"+ + "\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b\u0001"+ + "\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000"+ + "\u0000\u0000\u0000\u0015\u0001\u0000\u0000\u0000\u0001\u0017\u0001\u0000"+ + "\u0000\u0000\u0003\u0019\u0001\u0000\u0000\u0000\u0005\u001b\u0001\u0000"+ + "\u0000\u0000\u0007\u001d\u0001\u0000\u0000\u0000\t\u001f\u0001\u0000\u0000"+ + "\u0000\u000b[\u0001\u0000\u0000\u0000\r^\u0001\u0000\u0000\u0000\u000f"+ + "b\u0001\u0000\u0000\u0000\u0011o\u0001\u0000\u0000\u0000\u0013w\u0001"+ + "\u0000\u0000\u0000\u0015y\u0001\u0000\u0000\u0000\u0017\u0018\u0005(\u0000"+ + "\u0000\u0018\u0002\u0001\u0000\u0000\u0000\u0019\u001a\u0005)\u0000\u0000"+ + "\u001a\u0004\u0001\u0000\u0000\u0000\u001b\u001c\u0005.\u0000\u0000\u001c"+ + "\u0006\u0001\u0000\u0000\u0000\u001d\u001e\u0005:\u0000\u0000\u001e\b"+ + "\u0001\u0000\u0000\u0000\u001f \u0005,\u0000\u0000 \n\u0001\u0000\u0000"+ + "\u0000!\"\u0005b\u0000\u0000\"#\u0005o\u0000\u0000#$\u0005o\u0000\u0000"+ + "$%\u0005l\u0000\u0000%&\u0005e\u0000\u0000&\'\u0005a\u0000\u0000\'\\\u0005"+ + "n\u0000\u0000()\u0005b\u0000\u0000)*\u0005y\u0000\u0000*+\u0005t\u0000"+ + "\u0000+\\\u0005e\u0000\u0000,-\u0005c\u0000\u0000-.\u0005h\u0000\u0000"+ + "./\u0005a\u0000\u0000/\\\u0005r\u0000\u000001\u0005d\u0000\u000012\u0005"+ + "o\u0000\u000023\u0005u\u0000\u000034\u0005b\u0000\u000045\u0005l\u0000"+ + "\u00005\\\u0005e\u0000\u000067\u0005f\u0000\u000078\u0005l\u0000\u0000"+ + "89\u0005o\u0000\u00009:\u0005a\u0000\u0000:\\\u0005t\u0000\u0000;<\u0005"+ + "i\u0000\u0000<=\u0005n\u0000\u0000=\\\u0005t\u0000\u0000>?\u0005l\u0000"+ + "\u0000?@\u0005o\u0000\u0000@A\u0005n\u0000\u0000A\\\u0005g\u0000\u0000"+ + "BC\u0005s\u0000\u0000CD\u0005h\u0000\u0000DE\u0005o\u0000\u0000EF\u0005"+ + "r\u0000\u0000F\\\u0005t\u0000\u0000GH\u0005S\u0000\u0000HI\u0005t\u0000"+ + "\u0000IJ\u0005r\u0000\u0000JK\u0005i\u0000\u0000KL\u0005n\u0000\u0000"+ + "L\\\u0005g\u0000\u0000MN\u0005O\u0000\u0000NO\u0005b\u0000\u0000OP\u0005"+ + "j\u0000\u0000PQ\u0005e\u0000\u0000QR\u0005c\u0000\u0000R\\\u0005t\u0000"+ + "\u0000SW\u0003\u000f\u0007\u0000TU\u0003\u0005\u0002\u0000UV\u0003\u000f"+ + "\u0007\u0000VX\u0001\u0000\u0000\u0000WT\u0001\u0000\u0000\u0000XY\u0001"+ + "\u0000\u0000\u0000YW\u0001\u0000\u0000\u0000YZ\u0001\u0000\u0000\u0000"+ + "Z\\\u0001\u0000\u0000\u0000[!\u0001\u0000\u0000\u0000[(\u0001\u0000\u0000"+ + "\u0000[,\u0001\u0000\u0000\u0000[0\u0001\u0000\u0000\u0000[6\u0001\u0000"+ + "\u0000\u0000[;\u0001\u0000\u0000\u0000[>\u0001\u0000\u0000\u0000[B\u0001"+ + "\u0000\u0000\u0000[G\u0001\u0000\u0000\u0000[M\u0001\u0000\u0000\u0000"+ + "[S\u0001\u0000\u0000\u0000\\\f\u0001\u0000\u0000\u0000]_\u0007\u0000\u0000"+ + "\u0000^]\u0001\u0000\u0000\u0000_`\u0001\u0000\u0000\u0000`^\u0001\u0000"+ + "\u0000\u0000`a\u0001\u0000\u0000\u0000a\u000e\u0001\u0000\u0000\u0000"+ + "bf\u0003\u0011\b\u0000ce\u0003\u0013\t\u0000dc\u0001\u0000\u0000\u0000"+ + "eh\u0001\u0000\u0000\u0000fd\u0001\u0000\u0000\u0000fg\u0001\u0000\u0000"+ + "\u0000g\u0010\u0001\u0000\u0000\u0000hf\u0001\u0000\u0000\u0000ip\u0007"+ + "\u0001\u0000\u0000jk\b\u0002\u0000\u0000kp\u0004\b\u0000\u0000lm\u0007"+ + "\u0003\u0000\u0000mn\u0007\u0004\u0000\u0000np\u0004\b\u0001\u0000oi\u0001"+ + "\u0000\u0000\u0000oj\u0001\u0000\u0000\u0000ol\u0001\u0000\u0000\u0000"+ + "p\u0012\u0001\u0000\u0000\u0000qx\u0007\u0005\u0000\u0000rs\b\u0002\u0000"+ + "\u0000sx\u0004\t\u0002\u0000tu\u0007\u0003\u0000\u0000uv\u0007\u0004\u0000"+ + "\u0000vx\u0004\t\u0003\u0000wq\u0001\u0000\u0000\u0000wr\u0001\u0000\u0000"+ + "\u0000wt\u0001\u0000\u0000\u0000x\u0014\u0001\u0000\u0000\u0000yz\u0007"+ + "\u0006\u0000\u0000z{\u0001\u0000\u0000\u0000{|\u0006\n\u0000\u0000|\u0016"+ + "\u0001\u0000\u0000\u0000\u0007\u0000Y[`fow\u0001\u0006\u0000\u0000"; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { @@ -233,4 +233,4 @@ private boolean JavaLetterOrDigit_sempred(RuleContext _localctx, int predIndex) _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.tokens b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.tokens index c24e72bc9b4..aad1837fbc6 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.tokens +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterLexer.tokens @@ -1,17 +1,14 @@ LPAREN=1 RPAREN=2 -LBRACK=3 -RBRACK=4 -DOT=5 -COMMA=6 -SPACE=7 -FullyQualifiedName=8 -Number=9 -Identifier=10 +DOT=3 +COLON=4 +COMMA=5 +FullyQualifiedName=6 +Number=7 +Identifier=8 +S=9 '('=1 ')'=2 -'['=3 -']'=4 -'.'=5 -','=6 -' '=7 +'.'=3 +':'=4 +','=5 diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.interp b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.interp index a930f78304e..9196ed7bcea 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.interp +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.interp @@ -2,11 +2,10 @@ token literal names: null '(' ')' -'[' -']' '.' +':' ',' -' ' +null null null null @@ -15,20 +14,22 @@ token symbolic names: null LPAREN RPAREN -LBRACK -RBRACK DOT +COLON COMMA -SPACE FullyQualifiedName Number Identifier +S rule names: matcherPattern +typedPattern +patternType matcherParameter +parameterName matcherName atn: -[4, 1, 10, 21, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 1, 0, 1, 0, 1, 0, 5, 0, 10, 8, 0, 10, 0, 12, 0, 13, 9, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 0, 0, 3, 0, 2, 4, 0, 1, 1, 0, 8, 10, 18, 0, 6, 1, 0, 0, 0, 2, 16, 1, 0, 0, 0, 4, 18, 1, 0, 0, 0, 6, 7, 3, 4, 2, 0, 7, 11, 5, 1, 0, 0, 8, 10, 3, 2, 1, 0, 9, 8, 1, 0, 0, 0, 10, 13, 1, 0, 0, 0, 11, 9, 1, 0, 0, 0, 11, 12, 1, 0, 0, 0, 12, 14, 1, 0, 0, 0, 13, 11, 1, 0, 0, 0, 14, 15, 5, 2, 0, 0, 15, 1, 1, 0, 0, 0, 16, 17, 7, 0, 0, 0, 17, 3, 1, 0, 0, 0, 18, 19, 5, 10, 0, 0, 19, 5, 1, 0, 0, 0, 1, 11] \ No newline at end of file +[4, 1, 9, 45, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 1, 0, 1, 0, 3, 0, 15, 8, 0, 1, 1, 1, 1, 1, 1, 3, 1, 20, 8, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 29, 8, 2, 10, 2, 12, 2, 32, 9, 2, 1, 2, 3, 2, 35, 8, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 0, 0, 6, 0, 2, 4, 6, 8, 10, 0, 1, 1, 0, 6, 8, 42, 0, 14, 1, 0, 0, 0, 2, 19, 1, 0, 0, 0, 4, 23, 1, 0, 0, 0, 6, 38, 1, 0, 0, 0, 8, 40, 1, 0, 0, 0, 10, 42, 1, 0, 0, 0, 12, 15, 3, 2, 1, 0, 13, 15, 3, 8, 4, 0, 14, 12, 1, 0, 0, 0, 14, 13, 1, 0, 0, 0, 15, 1, 1, 0, 0, 0, 16, 17, 3, 8, 4, 0, 17, 18, 5, 4, 0, 0, 18, 20, 1, 0, 0, 0, 19, 16, 1, 0, 0, 0, 19, 20, 1, 0, 0, 0, 20, 21, 1, 0, 0, 0, 21, 22, 3, 4, 2, 0, 22, 3, 1, 0, 0, 0, 23, 24, 3, 10, 5, 0, 24, 34, 5, 1, 0, 0, 25, 26, 3, 6, 3, 0, 26, 27, 5, 5, 0, 0, 27, 29, 1, 0, 0, 0, 28, 25, 1, 0, 0, 0, 29, 32, 1, 0, 0, 0, 30, 28, 1, 0, 0, 0, 30, 31, 1, 0, 0, 0, 31, 33, 1, 0, 0, 0, 32, 30, 1, 0, 0, 0, 33, 35, 3, 6, 3, 0, 34, 30, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 37, 5, 2, 0, 0, 37, 5, 1, 0, 0, 0, 38, 39, 7, 0, 0, 0, 39, 7, 1, 0, 0, 0, 40, 41, 5, 8, 0, 0, 41, 9, 1, 0, 0, 0, 42, 43, 5, 8, 0, 0, 43, 11, 1, 0, 0, 0, 4, 14, 19, 30, 34] \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.java index a5dd3ffa9bc..170cb98ddaa 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.java @@ -15,18 +15,14 @@ */ // Generated from java-escape by ANTLR 4.11.1 package org.openrewrite.java.internal.grammar; - -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.ParserATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; +import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; -import org.antlr.v4.runtime.tree.TerminalNode; - +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) public class TemplateParameterParser extends Parser { @@ -36,27 +32,29 @@ public class TemplateParameterParser extends Parser { protected static final PredictionContextCache _sharedContextCache = new PredictionContextCache(); public static final int - LPAREN=1, RPAREN=2, LBRACK=3, RBRACK=4, DOT=5, COMMA=6, SPACE=7, FullyQualifiedName=8, - Number=9, Identifier=10; + LPAREN=1, RPAREN=2, DOT=3, COLON=4, COMMA=5, FullyQualifiedName=6, Number=7, + Identifier=8, S=9; public static final int - RULE_matcherPattern = 0, RULE_matcherParameter = 1, RULE_matcherName = 2; + RULE_matcherPattern = 0, RULE_typedPattern = 1, RULE_patternType = 2, + RULE_matcherParameter = 3, RULE_parameterName = 4, RULE_matcherName = 5; private static String[] makeRuleNames() { return new String[] { - "matcherPattern", "matcherParameter", "matcherName" + "matcherPattern", "typedPattern", "patternType", "matcherParameter", + "parameterName", "matcherName" }; } public static final String[] ruleNames = makeRuleNames(); private static String[] makeLiteralNames() { return new String[] { - null, "'('", "')'", "'['", "']'", "'.'", "','", "' '" + null, "'('", "')'", "'.'", "':'", "','" }; } private static final String[] _LITERAL_NAMES = makeLiteralNames(); private static String[] makeSymbolicNames() { return new String[] { - null, "LPAREN", "RPAREN", "LBRACK", "RBRACK", "DOT", "COMMA", "SPACE", - "FullyQualifiedName", "Number", "Identifier" + null, "LPAREN", "RPAREN", "DOT", "COLON", "COMMA", "FullyQualifiedName", + "Number", "Identifier", "S" }; } private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); @@ -112,6 +110,128 @@ public TemplateParameterParser(TokenStream input) { @SuppressWarnings("CheckReturnValue") public static class MatcherPatternContext extends ParserRuleContext { + public TypedPatternContext typedPattern() { + return getRuleContext(TypedPatternContext.class,0); + } + public ParameterNameContext parameterName() { + return getRuleContext(ParameterNameContext.class,0); + } + public MatcherPatternContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_matcherPattern; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).enterMatcherPattern(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).exitMatcherPattern(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof TemplateParameterParserVisitor ) return ((TemplateParameterParserVisitor)visitor).visitMatcherPattern(this); + else return visitor.visitChildren(this); + } + } + + public final MatcherPatternContext matcherPattern() throws RecognitionException { + MatcherPatternContext _localctx = new MatcherPatternContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_matcherPattern); + try { + setState(14); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(12); + typedPattern(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(13); + parameterName(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class TypedPatternContext extends ParserRuleContext { + public PatternTypeContext patternType() { + return getRuleContext(PatternTypeContext.class,0); + } + public ParameterNameContext parameterName() { + return getRuleContext(ParameterNameContext.class,0); + } + public TerminalNode COLON() { return getToken(TemplateParameterParser.COLON, 0); } + public TypedPatternContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_typedPattern; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).enterTypedPattern(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).exitTypedPattern(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof TemplateParameterParserVisitor ) return ((TemplateParameterParserVisitor)visitor).visitTypedPattern(this); + else return visitor.visitChildren(this); + } + } + + public final TypedPatternContext typedPattern() throws RecognitionException { + TypedPatternContext _localctx = new TypedPatternContext(_ctx, getState()); + enterRule(_localctx, 2, RULE_typedPattern); + try { + enterOuterAlt(_localctx, 1); + { + setState(19); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,1,_ctx) ) { + case 1: + { + setState(16); + parameterName(); + setState(17); + match(COLON); + } + break; + } + setState(21); + patternType(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class PatternTypeContext extends ParserRuleContext { public MatcherNameContext matcherName() { return getRuleContext(MatcherNameContext.class,0); } @@ -123,51 +243,70 @@ public List matcherParameter() { public MatcherParameterContext matcherParameter(int i) { return getRuleContext(MatcherParameterContext.class,i); } - public MatcherPatternContext(ParserRuleContext parent, int invokingState) { + public List COMMA() { return getTokens(TemplateParameterParser.COMMA); } + public TerminalNode COMMA(int i) { + return getToken(TemplateParameterParser.COMMA, i); + } + public PatternTypeContext(ParserRuleContext parent, int invokingState) { super(parent, invokingState); } - @Override public int getRuleIndex() { return RULE_matcherPattern; } + @Override public int getRuleIndex() { return RULE_patternType; } @Override public void enterRule(ParseTreeListener listener) { - if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).enterMatcherPattern(this); + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).enterPatternType(this); } @Override public void exitRule(ParseTreeListener listener) { - if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).exitMatcherPattern(this); + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).exitPatternType(this); } @Override public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof TemplateParameterParserVisitor ) return ((TemplateParameterParserVisitor)visitor).visitMatcherPattern(this); + if ( visitor instanceof TemplateParameterParserVisitor ) return ((TemplateParameterParserVisitor)visitor).visitPatternType(this); else return visitor.visitChildren(this); } } - public final MatcherPatternContext matcherPattern() throws RecognitionException { - MatcherPatternContext _localctx = new MatcherPatternContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_matcherPattern); + public final PatternTypeContext patternType() throws RecognitionException { + PatternTypeContext _localctx = new PatternTypeContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_patternType); int _la; try { + int _alt; enterOuterAlt(_localctx, 1); { - setState(6); + setState(23); matcherName(); - setState(7); + setState(24); match(LPAREN); - setState(11); + setState(34); _errHandler.sync(this); _la = _input.LA(1); - while (((_la) & ~0x3f) == 0 && ((1L << _la) & 1792L) != 0) { - { + if (((_la) & ~0x3f) == 0 && ((1L << _la) & 448L) != 0) { { - setState(8); - matcherParameter(); + setState(30); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,2,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + { + { + setState(25); + matcherParameter(); + setState(26); + match(COMMA); + } + } + } + setState(32); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,2,_ctx); } + setState(33); + matcherParameter(); } - setState(13); - _errHandler.sync(this); - _la = _input.LA(1); } - setState(14); + + setState(36); match(RPAREN); } } @@ -208,14 +347,14 @@ public T accept(ParseTreeVisitor visitor) { public final MatcherParameterContext matcherParameter() throws RecognitionException { MatcherParameterContext _localctx = new MatcherParameterContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_matcherParameter); + enterRule(_localctx, 6, RULE_matcherParameter); int _la; try { enterOuterAlt(_localctx, 1); { - setState(16); + setState(38); _la = _input.LA(1); - if ( !(((_la) & ~0x3f) == 0 && ((1L << _la) & 1792L) != 0) ) { + if ( !(((_la) & ~0x3f) == 0 && ((1L << _la) & 448L) != 0) ) { _errHandler.recoverInline(this); } else { @@ -236,6 +375,49 @@ public final MatcherParameterContext matcherParameter() throws RecognitionExcept return _localctx; } + @SuppressWarnings("CheckReturnValue") + public static class ParameterNameContext extends ParserRuleContext { + public TerminalNode Identifier() { return getToken(TemplateParameterParser.Identifier, 0); } + public ParameterNameContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_parameterName; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).enterParameterName(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof TemplateParameterParserListener ) ((TemplateParameterParserListener)listener).exitParameterName(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof TemplateParameterParserVisitor ) return ((TemplateParameterParserVisitor)visitor).visitParameterName(this); + else return visitor.visitChildren(this); + } + } + + public final ParameterNameContext parameterName() throws RecognitionException { + ParameterNameContext _localctx = new ParameterNameContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_parameterName); + try { + enterOuterAlt(_localctx, 1); + { + setState(40); + match(Identifier); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + @SuppressWarnings("CheckReturnValue") public static class MatcherNameContext extends ParserRuleContext { public TerminalNode Identifier() { return getToken(TemplateParameterParser.Identifier, 0); } @@ -260,11 +442,11 @@ public T accept(ParseTreeVisitor visitor) { public final MatcherNameContext matcherName() throws RecognitionException { MatcherNameContext _localctx = new MatcherNameContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_matcherName); + enterRule(_localctx, 10, RULE_matcherName); try { enterOuterAlt(_localctx, 1); { - setState(18); + setState(42); match(Identifier); } } @@ -280,20 +462,34 @@ public final MatcherNameContext matcherName() throws RecognitionException { } public static final String _serializedATN = - "\u0004\u0001\n\u0015\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ - "\u0002\u0007\u0002\u0001\u0000\u0001\u0000\u0001\u0000\u0005\u0000\n\b"+ - "\u0000\n\u0000\f\u0000\r\t\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001"+ - "\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0000\u0000\u0003\u0000\u0002"+ - "\u0004\u0000\u0001\u0001\u0000\b\n\u0012\u0000\u0006\u0001\u0000\u0000"+ - "\u0000\u0002\u0010\u0001\u0000\u0000\u0000\u0004\u0012\u0001\u0000\u0000"+ - "\u0000\u0006\u0007\u0003\u0004\u0002\u0000\u0007\u000b\u0005\u0001\u0000"+ - "\u0000\b\n\u0003\u0002\u0001\u0000\t\b\u0001\u0000\u0000\u0000\n\r\u0001"+ - "\u0000\u0000\u0000\u000b\t\u0001\u0000\u0000\u0000\u000b\f\u0001\u0000"+ - "\u0000\u0000\f\u000e\u0001\u0000\u0000\u0000\r\u000b\u0001\u0000\u0000"+ - "\u0000\u000e\u000f\u0005\u0002\u0000\u0000\u000f\u0001\u0001\u0000\u0000"+ - "\u0000\u0010\u0011\u0007\u0000\u0000\u0000\u0011\u0003\u0001\u0000\u0000"+ - "\u0000\u0012\u0013\u0005\n\u0000\u0000\u0013\u0005\u0001\u0000\u0000\u0000"+ - "\u0001\u000b"; + "\u0004\u0001\t-\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ + "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+ + "\u0005\u0007\u0005\u0001\u0000\u0001\u0000\u0003\u0000\u000f\b\u0000\u0001"+ + "\u0001\u0001\u0001\u0001\u0001\u0003\u0001\u0014\b\u0001\u0001\u0001\u0001"+ + "\u0001\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0005"+ + "\u0002\u001d\b\u0002\n\u0002\f\u0002 \t\u0002\u0001\u0002\u0003\u0002"+ + "#\b\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0004"+ + "\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0000\u0000\u0006\u0000"+ + "\u0002\u0004\u0006\b\n\u0000\u0001\u0001\u0000\u0006\b*\u0000\u000e\u0001"+ + "\u0000\u0000\u0000\u0002\u0013\u0001\u0000\u0000\u0000\u0004\u0017\u0001"+ + "\u0000\u0000\u0000\u0006&\u0001\u0000\u0000\u0000\b(\u0001\u0000\u0000"+ + "\u0000\n*\u0001\u0000\u0000\u0000\f\u000f\u0003\u0002\u0001\u0000\r\u000f"+ + "\u0003\b\u0004\u0000\u000e\f\u0001\u0000\u0000\u0000\u000e\r\u0001\u0000"+ + "\u0000\u0000\u000f\u0001\u0001\u0000\u0000\u0000\u0010\u0011\u0003\b\u0004"+ + "\u0000\u0011\u0012\u0005\u0004\u0000\u0000\u0012\u0014\u0001\u0000\u0000"+ + "\u0000\u0013\u0010\u0001\u0000\u0000\u0000\u0013\u0014\u0001\u0000\u0000"+ + "\u0000\u0014\u0015\u0001\u0000\u0000\u0000\u0015\u0016\u0003\u0004\u0002"+ + "\u0000\u0016\u0003\u0001\u0000\u0000\u0000\u0017\u0018\u0003\n\u0005\u0000"+ + "\u0018\"\u0005\u0001\u0000\u0000\u0019\u001a\u0003\u0006\u0003\u0000\u001a"+ + "\u001b\u0005\u0005\u0000\u0000\u001b\u001d\u0001\u0000\u0000\u0000\u001c"+ + "\u0019\u0001\u0000\u0000\u0000\u001d \u0001\u0000\u0000\u0000\u001e\u001c"+ + "\u0001\u0000\u0000\u0000\u001e\u001f\u0001\u0000\u0000\u0000\u001f!\u0001"+ + "\u0000\u0000\u0000 \u001e\u0001\u0000\u0000\u0000!#\u0003\u0006\u0003"+ + "\u0000\"\u001e\u0001\u0000\u0000\u0000\"#\u0001\u0000\u0000\u0000#$\u0001"+ + "\u0000\u0000\u0000$%\u0005\u0002\u0000\u0000%\u0005\u0001\u0000\u0000"+ + "\u0000&\'\u0007\u0000\u0000\u0000\'\u0007\u0001\u0000\u0000\u0000()\u0005"+ + "\b\u0000\u0000)\t\u0001\u0000\u0000\u0000*+\u0005\b\u0000\u0000+\u000b"+ + "\u0001\u0000\u0000\u0000\u0004\u000e\u0013\u001e\""; public static final ATN _ATN = new ATNDeserializer().deserialize(_serializedATN.toCharArray()); static { @@ -302,4 +498,4 @@ public final MatcherNameContext matcherName() throws RecognitionException { _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); } } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.tokens b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.tokens index c24e72bc9b4..aad1837fbc6 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.tokens +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParser.tokens @@ -1,17 +1,14 @@ LPAREN=1 RPAREN=2 -LBRACK=3 -RBRACK=4 -DOT=5 -COMMA=6 -SPACE=7 -FullyQualifiedName=8 -Number=9 -Identifier=10 +DOT=3 +COLON=4 +COMMA=5 +FullyQualifiedName=6 +Number=7 +Identifier=8 +S=9 '('=1 ')'=2 -'['=3 -']'=4 -'.'=5 -','=6 -' '=7 +'.'=3 +':'=4 +','=5 diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseListener.java index 2a8d6f843e6..7deb52093f2 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseListener.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseListener.java @@ -39,6 +39,30 @@ public class TemplateParameterParserBaseListener implements TemplateParameterPar *

The default implementation does nothing.

*/ @Override public void exitMatcherPattern(TemplateParameterParser.MatcherPatternContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterTypedPattern(TemplateParameterParser.TypedPatternContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitTypedPattern(TemplateParameterParser.TypedPatternContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterPatternType(TemplateParameterParser.PatternTypeContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitPatternType(TemplateParameterParser.PatternTypeContext ctx) { } /** * {@inheritDoc} * @@ -51,6 +75,18 @@ public class TemplateParameterParserBaseListener implements TemplateParameterPar *

The default implementation does nothing.

*/ @Override public void exitMatcherParameter(TemplateParameterParser.MatcherParameterContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterParameterName(TemplateParameterParser.ParameterNameContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitParameterName(TemplateParameterParser.ParameterNameContext ctx) { } /** * {@inheritDoc} * @@ -88,4 +124,4 @@ public class TemplateParameterParserBaseListener implements TemplateParameterPar *

The default implementation does nothing.

*/ @Override public void visitErrorNode(ErrorNode node) { } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseVisitor.java index 9c7bf807d9a..930f92cc2fa 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserBaseVisitor.java @@ -34,6 +34,20 @@ public class TemplateParameterParserBaseVisitor extends AbstractParseTreeVisi * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitMatcherPattern(TemplateParameterParser.MatcherPatternContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitTypedPattern(TemplateParameterParser.TypedPatternContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitPatternType(TemplateParameterParser.PatternTypeContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} * @@ -41,6 +55,13 @@ public class TemplateParameterParserBaseVisitor extends AbstractParseTreeVisi * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitMatcherParameter(TemplateParameterParser.MatcherParameterContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitParameterName(TemplateParameterParser.ParameterNameContext ctx) { return visitChildren(ctx); } /** * {@inheritDoc} * @@ -48,4 +69,4 @@ public class TemplateParameterParserBaseVisitor extends AbstractParseTreeVisi * {@link #visitChildren} on {@code ctx}.

*/ @Override public T visitMatcherName(TemplateParameterParser.MatcherNameContext ctx) { return visitChildren(ctx); } -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserListener.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserListener.java index 7648fc217ee..4838ede63ab 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserListener.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserListener.java @@ -32,6 +32,26 @@ public interface TemplateParameterParserListener extends ParseTreeListener { * @param ctx the parse tree */ void exitMatcherPattern(TemplateParameterParser.MatcherPatternContext ctx); + /** + * Enter a parse tree produced by {@link TemplateParameterParser#typedPattern}. + * @param ctx the parse tree + */ + void enterTypedPattern(TemplateParameterParser.TypedPatternContext ctx); + /** + * Exit a parse tree produced by {@link TemplateParameterParser#typedPattern}. + * @param ctx the parse tree + */ + void exitTypedPattern(TemplateParameterParser.TypedPatternContext ctx); + /** + * Enter a parse tree produced by {@link TemplateParameterParser#patternType}. + * @param ctx the parse tree + */ + void enterPatternType(TemplateParameterParser.PatternTypeContext ctx); + /** + * Exit a parse tree produced by {@link TemplateParameterParser#patternType}. + * @param ctx the parse tree + */ + void exitPatternType(TemplateParameterParser.PatternTypeContext ctx); /** * Enter a parse tree produced by {@link TemplateParameterParser#matcherParameter}. * @param ctx the parse tree @@ -42,6 +62,16 @@ public interface TemplateParameterParserListener extends ParseTreeListener { * @param ctx the parse tree */ void exitMatcherParameter(TemplateParameterParser.MatcherParameterContext ctx); + /** + * Enter a parse tree produced by {@link TemplateParameterParser#parameterName}. + * @param ctx the parse tree + */ + void enterParameterName(TemplateParameterParser.ParameterNameContext ctx); + /** + * Exit a parse tree produced by {@link TemplateParameterParser#parameterName}. + * @param ctx the parse tree + */ + void exitParameterName(TemplateParameterParser.ParameterNameContext ctx); /** * Enter a parse tree produced by {@link TemplateParameterParser#matcherName}. * @param ctx the parse tree @@ -52,4 +82,4 @@ public interface TemplateParameterParserListener extends ParseTreeListener { * @param ctx the parse tree */ void exitMatcherName(TemplateParameterParser.MatcherNameContext ctx); -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserVisitor.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserVisitor.java index e676ac3f93f..d74e66d76af 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserVisitor.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/grammar/TemplateParameterParserVisitor.java @@ -31,16 +31,34 @@ public interface TemplateParameterParserVisitor extends ParseTreeVisitor { * @return the visitor result */ T visitMatcherPattern(TemplateParameterParser.MatcherPatternContext ctx); + /** + * Visit a parse tree produced by {@link TemplateParameterParser#typedPattern}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitTypedPattern(TemplateParameterParser.TypedPatternContext ctx); + /** + * Visit a parse tree produced by {@link TemplateParameterParser#patternType}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitPatternType(TemplateParameterParser.PatternTypeContext ctx); /** * Visit a parse tree produced by {@link TemplateParameterParser#matcherParameter}. * @param ctx the parse tree * @return the visitor result */ T visitMatcherParameter(TemplateParameterParser.MatcherParameterContext ctx); + /** + * Visit a parse tree produced by {@link TemplateParameterParser#parameterName}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitParameterName(TemplateParameterParser.ParameterNameContext ctx); /** * Visit a parse tree produced by {@link TemplateParameterParser#matcherName}. * @param ctx the parse tree * @return the visitor result */ T visitMatcherName(TemplateParameterParser.MatcherNameContext ctx); -} +} \ No newline at end of file diff --git a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java index 1c685dfa682..5ab5d1b2822 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/internal/template/Substitutions.java @@ -25,7 +25,9 @@ import org.openrewrite.java.internal.grammar.TemplateParameterParser; import org.openrewrite.java.tree.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.StringJoiner; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; @@ -41,13 +43,14 @@ public class Substitutions { "#{", "}", null); public String substitute() { + AtomicInteger requiredParameters = new AtomicInteger(0); AtomicInteger index = new AtomicInteger(0); String substituted = code; while (true) { + Map typedPatternByName = new HashMap<>(); String previous = substituted; substituted = propertyPlaceholderHelper.replacePlaceholders(substituted, key -> { int i = index.getAndIncrement(); - Object parameter = parameters[i]; String s; if (!key.isEmpty()) { @@ -58,73 +61,23 @@ public String substitute() { parser.addErrorListener(new ThrowingErrorListener()); TemplateParameterParser.MatcherPatternContext ctx = parser.matcherPattern(); - String matcherName = ctx.matcherName().Identifier().getText(); - List params = ctx.matcherParameter(); - - if ("anyArray".equals(matcherName)) { - if (!(parameter instanceof TypedTree)) { - throw new IllegalArgumentException("anyArray can only be used on TypedTree parameters"); - } - - JavaType type = ((TypedTree) parameter).getType(); - JavaType.Array arrayType = TypeUtils.asArray(type); - if (arrayType == null) { - arrayType = TypeUtils.asArray(type); - if (arrayType == null) { - throw new IllegalArgumentException("anyArray can only be used on parameters containing JavaType.Array type attribution"); - } - } - - s = "(/*__p" + i + "__*/new "; - - StringBuilder extraDim = new StringBuilder(); - for (; arrayType.getElemType() instanceof JavaType.Array; arrayType = (JavaType.Array) arrayType.getElemType()) { - extraDim.append("[0]"); + TemplateParameterParser.TypedPatternContext typedPattern = ctx.typedPattern(); + if (typedPattern == null) { + String paramName = ctx.parameterName().Identifier().getText(); + s = typedPatternByName.get(paramName); + if (s == null) { + throw new IllegalArgumentException("The parameter " + paramName + " must be defined before it is referenced."); } - - if (arrayType.getElemType() instanceof JavaType.Primitive) { - s += ((JavaType.Primitive) arrayType.getElemType()).getKeyword(); - } else if (arrayType.getElemType() instanceof JavaType.FullyQualified) { - s += ((JavaType.FullyQualified) arrayType.getElemType()).getFullyQualifiedName().replace("$", "."); - } - - s += "[0]" + extraDim + ")"; - } else if ("any".equals(matcherName)) { - String fqn; - - if (params.size() == 1) { - if(params.get(0).Identifier() != null) { - fqn = params.get(0).Identifier().getText(); - } else { - fqn = params.get(0).FullyQualifiedName().getText(); - } - } else { - if (parameter instanceof J.NewClass && ((J.NewClass) parameter).getBody() != null - && ((J.NewClass) parameter).getClazz() != null) { - // for anonymous classes get the type from the supertype - fqn = getTypeName(((J.NewClass) parameter).getClazz().getType()); - } else if (!(parameter instanceof TypedTree)) { - // any should only be used on TypedTree parameters, but will give it best effort - fqn = "java.lang.Object"; - } else { - fqn = getTypeName(((TypedTree) parameter).getType()); - } - } - - fqn = fqn.replace("$", "."); - - JavaType.Primitive primitive = JavaType.Primitive.fromKeyword(fqn); - s = "__P__." + (primitive == null || primitive.equals(JavaType.Primitive.String) ? - "<" + fqn + ">/*__p" + i + "__*/p()" : - "/*__p" + i + "__*/" + fqn + "p()" - ); - - parameters[i] = ((J) parameter).withPrefix(Space.EMPTY); } else { - throw new IllegalArgumentException("Invalid template matcher '" + key + "'"); + s = substituteTypedPattern(key, i, typedPattern); + if (ctx.typedPattern().parameterName() != null) { + typedPatternByName.put(ctx.typedPattern().parameterName().Identifier().getText(), s); + } + requiredParameters.incrementAndGet(); } } else { - s = substituteUntyped(parameter, i); + s = substituteUntyped(parameters[i], i); + requiredParameters.incrementAndGet(); } return s; @@ -135,9 +88,84 @@ public String substitute() { } } + if (parameters.length != requiredParameters.get()) { + throw new IllegalArgumentException("This template requires " + requiredParameters.get() + " parameters."); + } + return substituted; } + private String substituteTypedPattern(String key, int index, TemplateParameterParser.TypedPatternContext typedPattern) { + Object parameter = parameters[index]; + String s; + String matcherName = typedPattern.patternType().matcherName().Identifier().getText(); + List params = typedPattern.patternType().matcherParameter(); + + if ("anyArray".equals(matcherName)) { + if (!(parameter instanceof TypedTree)) { + throw new IllegalArgumentException("anyArray can only be used on TypedTree parameters"); + } + + JavaType type = ((TypedTree) parameter).getType(); + JavaType.Array arrayType = TypeUtils.asArray(type); + if (arrayType == null) { + arrayType = TypeUtils.asArray(type); + if (arrayType == null) { + throw new IllegalArgumentException("anyArray can only be used on parameters containing JavaType.Array type attribution"); + } + } + + s = "(/*__p" + index + "__*/new "; + + StringBuilder extraDim = new StringBuilder(); + for (; arrayType.getElemType() instanceof JavaType.Array; arrayType = (JavaType.Array) arrayType.getElemType()) { + extraDim.append("[0]"); + } + + if (arrayType.getElemType() instanceof JavaType.Primitive) { + s += ((JavaType.Primitive) arrayType.getElemType()).getKeyword(); + } else if (arrayType.getElemType() instanceof JavaType.FullyQualified) { + s += ((JavaType.FullyQualified) arrayType.getElemType()).getFullyQualifiedName().replace("$", "."); + } + + s += "[0]" + extraDim + ")"; + } else if ("any".equals(matcherName)) { + String fqn; + + if (params.size() == 1) { + if (params.get(0).Identifier() != null) { + fqn = params.get(0).Identifier().getText(); + } else { + fqn = params.get(0).FullyQualifiedName().getText(); + } + } else { + if (parameter instanceof J.NewClass && ((J.NewClass) parameter).getBody() != null + && ((J.NewClass) parameter).getClazz() != null) { + // for anonymous classes get the type from the supertype + fqn = getTypeName(((J.NewClass) parameter).getClazz().getType()); + } else if (!(parameter instanceof TypedTree)) { + // any should only be used on TypedTree parameters, but will give it best effort + fqn = "java.lang.Object"; + } else { + fqn = getTypeName(((TypedTree) parameter).getType()); + } + } + + fqn = fqn.replace("$", "."); + + JavaType.Primitive primitive = JavaType.Primitive.fromKeyword(fqn); + s = "__P__." + (primitive == null || primitive.equals(JavaType.Primitive.String) ? + "<" + fqn + ">/*__p" + index + "__*/p()" : + "/*__p" + index + "__*/" + fqn + "p()" + ); + + parameters[index] = ((J) parameter).withPrefix(Space.EMPTY); + } else { + throw new IllegalArgumentException("Invalid template matcher '" + key + "'"); + } + return s; + } + private String getTypeName(@Nullable JavaType type) { if (type instanceof JavaType.Parameterized) { StringJoiner joiner = new StringJoiner(",", "<", ">"); @@ -169,7 +197,7 @@ private String substituteUntyped(Object parameter, int index) { return ((J) parameter).printTrimmed(); } else { throw new IllegalArgumentException("Template parameter " + index + " cannot be used in an untyped template substitution. " + - "Instead of \"#{}\", indicate the template parameter's type with \"#{any(" + typeHintFor(parameter) + ")}\"."); + "Instead of \"#{}\", indicate the template parameter's type with \"#{any(" + typeHintFor(parameter) + ")}\"."); } } else if (parameter instanceof JRightPadded) { return substituteUntyped(((JRightPadded) parameter).getElement(), index); @@ -180,7 +208,7 @@ private String substituteUntyped(Object parameter, int index) { } private static String typeHintFor(Object j) { - if(j instanceof TypedTree) { + if (j instanceof TypedTree) { return typeHintFor(((TypedTree) j).getType()); } return ""; diff --git a/rewrite-java/src/main/java/org/openrewrite/java/template/Matcher.java b/rewrite-java/src/main/java/org/openrewrite/java/template/Matcher.java deleted file mode 100644 index c2c377fc8b8..00000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/template/Matcher.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.template; - -import org.openrewrite.Incubating; -import org.openrewrite.java.tree.J; - -@Incubating(since = "8.3.0") -@FunctionalInterface -public interface Matcher { - boolean matches(T t); -} diff --git a/rewrite-java/src/main/java/org/openrewrite/java/template/Matches.java b/rewrite-java/src/main/java/org/openrewrite/java/template/Matches.java deleted file mode 100644 index 348333353a5..00000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/template/Matches.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.template; - -import org.openrewrite.Incubating; -import org.openrewrite.java.tree.Expression; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -@Incubating(since = "8.3.0") -@Target(ElementType.PARAMETER) -public @interface Matches { - Class> value(); -} diff --git a/rewrite-java/src/main/java/org/openrewrite/java/template/NotMatches.java b/rewrite-java/src/main/java/org/openrewrite/java/template/NotMatches.java deleted file mode 100644 index 17935203b7c..00000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/template/NotMatches.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.template; - -import org.openrewrite.Incubating; -import org.openrewrite.java.tree.Expression; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -@Incubating(since = "8.3.0") -@Target(ElementType.PARAMETER) -public @interface NotMatches { - Class> value(); -} diff --git a/rewrite-java/src/main/java/org/openrewrite/java/template/Primitive.java b/rewrite-java/src/main/java/org/openrewrite/java/template/Primitive.java deleted file mode 100644 index c8df4f20556..00000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/template/Primitive.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2023 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openrewrite.java.template; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target(ElementType.PARAMETER) -@Retention(RetentionPolicy.SOURCE) -public @interface Primitive { -} diff --git a/rewrite-java/src/main/java/org/openrewrite/java/template/package-info.java b/rewrite-java/src/main/java/org/openrewrite/java/template/package-info.java deleted file mode 100644 index 1d435666527..00000000000 --- a/rewrite-java/src/main/java/org/openrewrite/java/template/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2020 the original author or authors. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@NonNullApi -package org.openrewrite.java.template; - -import org.openrewrite.internal.lang.NonNullApi;