diff --git a/config/checker-framework-suppressions/checker-index-suppressions.xml b/config/checker-framework-suppressions/checker-index-suppressions.xml index 752717ffdde..78c29ff7e83 100644 --- a/config/checker-framework-suppressions/checker-index-suppressions.xml +++ b/config/checker-framework-suppressions/checker-index-suppressions.xml @@ -33,28 +33,6 @@ - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter beginIndex of String.substring. - EMBEDDED_EXPRESSION_END.length(), -
- found : @LTEqLengthOf("com.puppycrawl.tools.checkstyle.JavaAstVisitor.EMBEDDED_EXPRESSION_END") int - required: @LTEqLengthOf("tokenText") int -
-
- - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter beginIndex of String.substring. - EMBEDDED_EXPRESSION_END.length(), -
- found : @LTEqLengthOf("com.puppycrawl.tools.checkstyle.JavaAstVisitor.EMBEDDED_EXPRESSION_END") int - required: @LTEqLengthOf("tokenText") int -
-
- src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java argument @@ -66,17 +44,6 @@ - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter beginIndex of String.substring. - QUOTE.length(), tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length()); -
- found : @LTEqLengthOf("com.puppycrawl.tools.checkstyle.JavaAstVisitor.QUOTE") int - required: @LTEqLengthOf("tokenText") int -
-
- src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java argument @@ -88,39 +55,6 @@ - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter endIndex of String.substring. - tokenTextLength - QUOTE.length() -
- found : @GTENegativeOne int - required: @NonNegative int -
-
- - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter endIndex of String.substring. - QUOTE.length(), tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length()); -
- found : int - required: @NonNegative int -
-
- - - src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java - argument - incompatible argument for parameter endIndex of String.substring. - tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length() -
- found : int - required: @NonNegative int -
-
- src/main/java/com/puppycrawl/tools/checkstyle/JavadocDetailNodeParser.java argument diff --git a/config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml b/config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml index 23d46a4170e..b979991f072 100644 --- a/config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml +++ b/config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml @@ -5369,13 +5369,6 @@ - - src/main/java/com/puppycrawl/tools/checkstyle/grammar/CompositeLexerContextCache.java - dereference.of.nullable - dereference of possibly-null reference currentContext - if (currentContext.getCurlyBraceDepth() == 0) { - - src/main/java/com/puppycrawl/tools/checkstyle/gui/BaseCellEditor.java return diff --git a/config/import-control.xml b/config/import-control.xml index 82907b2dbbc..222543be061 100644 --- a/config/import-control.xml +++ b/config/import-control.xml @@ -309,6 +309,7 @@ + diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java b/src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java index 958134a6dd2..cdbf62ab677 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/JavaAstVisitor.java @@ -107,12 +107,6 @@ public final class JavaAstVisitor extends JavaLanguageParserBaseVisitor startExpression = Optional.ofNullable(ctx.expr()) + final Optional expression = Optional.ofNullable(ctx.expr()) .map(this::visit); - if (startExpression.isPresent()) { - final DetailAstImpl imaginaryExpr = + if (expression.isPresent()) { + final DetailAstImpl imaginaryExpression = createImaginary(TokenTypes.EMBEDDED_EXPRESSION); - imaginaryExpr.addChild(startExpression.orElseThrow()); - begin.addChild(imaginaryExpr); + imaginaryExpression.addChild(expression.orElseThrow()); + stringTemplateBegin.addChild(imaginaryExpression); } ctx.stringTemplateMiddle().stream() .map(this::buildStringTemplateMiddle) - .collect(Collectors.toUnmodifiableList()) - .forEach(begin::addChild); - - final DetailAstImpl end = buildStringTemplateEnd(ctx); - begin.addChild(end); - return begin; - } - - /** - * Builds the beginning of a string template AST. - * - * @param ctx the StringTemplateContext to build AST from - * @return string template AST - */ - private static DetailAstImpl buildStringTemplateBeginning( - JavaLanguageParser.StringTemplateContext ctx) { - - // token looks like '"' StringFragment '\{' - final TerminalNode context = ctx.STRING_TEMPLATE_BEGIN(); - final Token token = context.getSymbol(); - final String tokenText = context.getText(); - final int tokenStartIndex = token.getCharPositionInLine(); - final int tokenLineNumber = token.getLine(); - final int tokenTextLength = tokenText.length(); - - final DetailAstImpl stringTemplateBegin = createImaginary( - TokenTypes.STRING_TEMPLATE_BEGIN, QUOTE, - tokenLineNumber, tokenStartIndex - ); + .forEach(stringTemplateBegin::addChild); - // remove delimiters '"' and '\{' - final String stringFragment = tokenText.substring( - QUOTE.length(), tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length()); - - final DetailAstImpl stringTemplateContent = createImaginary( - TokenTypes.STRING_TEMPLATE_CONTENT, stringFragment, - tokenLineNumber, tokenStartIndex + QUOTE.length() - ); - stringTemplateBegin.addChild(stringTemplateContent); - - final DetailAstImpl embeddedBegin = createImaginary( - TokenTypes.EMBEDDED_EXPRESSION_BEGIN, EMBEDDED_EXPRESSION_BEGIN, - tokenLineNumber, - tokenStartIndex + tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length() - ); - stringTemplateBegin.addChild(embeddedBegin); + final DetailAstImpl stringTemplateEnd = visit(ctx.stringTemplateEnd()); + stringTemplateBegin.addChild(stringTemplateEnd); return stringTemplateBegin; } /** - * Builds the middle of a string template AST. + * Builds a string template middle AST. * - * @param middleContext the StringTemplateMiddleContext to build AST from + * @param ctx the StringTemplateMiddleContext to build AST from * @return DetailAstImpl of string template middle */ private DetailAstImpl buildStringTemplateMiddle( - JavaLanguageParser.StringTemplateMiddleContext middleContext) { - - // token looks like '}' StringFragment '\{' - final TerminalNode context = middleContext.STRING_TEMPLATE_MID(); - final Token token = context.getSymbol(); - final int tokenStartIndex = token.getCharPositionInLine(); - final int tokenLineNumber = token.getLine(); - final String tokenText = context.getText(); - final int tokenTextLength = tokenText.length(); - - final DetailAstImpl embeddedExpressionEnd = createImaginary( - TokenTypes.EMBEDDED_EXPRESSION_END, EMBEDDED_EXPRESSION_END, - tokenLineNumber, tokenStartIndex - ); - - // remove delimiters '}' and '\\' '{' - final String stringFragment = tokenText.substring( - EMBEDDED_EXPRESSION_END.length(), - tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length() - ); - - final DetailAstImpl content = createImaginary( - TokenTypes.STRING_TEMPLATE_CONTENT, stringFragment, - tokenLineNumber, tokenStartIndex + EMBEDDED_EXPRESSION_END.length() - ); - embeddedExpressionEnd.addNextSibling(content); + JavaLanguageParser.StringTemplateMiddleContext ctx) { + final DetailAstImpl stringTemplateMiddle = + visit(ctx.stringTemplateMid()); - final DetailAstImpl embeddedBegin = createImaginary( - TokenTypes.EMBEDDED_EXPRESSION_BEGIN, EMBEDDED_EXPRESSION_BEGIN, - tokenLineNumber, - tokenStartIndex + tokenTextLength - EMBEDDED_EXPRESSION_BEGIN.length() - ); - content.addNextSibling(embeddedBegin); - - final Optional embeddedExpression = Optional.ofNullable(middleContext.expr()) + final Optional expression = Optional.ofNullable(ctx.expr()) .map(this::visit); - if (embeddedExpression.isPresent()) { - final DetailAstImpl imaginaryExpr = + if (expression.isPresent()) { + final DetailAstImpl imaginaryExpression = createImaginary(TokenTypes.EMBEDDED_EXPRESSION); - imaginaryExpr.addChild(embeddedExpression.orElseThrow()); - embeddedExpressionEnd.addNextSibling(imaginaryExpr); + imaginaryExpression.addChild(expression.orElseThrow()); + addLastSibling(stringTemplateMiddle, imaginaryExpression); } - return embeddedExpressionEnd; + return stringTemplateMiddle; } - /** - * Builds the end of a string template AST. - * - * @param ctx the StringTemplateContext to build AST from - * @return DetailAstImpl of string template end - */ - private static DetailAstImpl buildStringTemplateEnd( - JavaLanguageParser.StringTemplateContext ctx) { - - // token looks like '}' StringFragment '"' - final TerminalNode context = ctx.STRING_TEMPLATE_END(); - final Token token = context.getSymbol(); - final String tokenText = context.getText(); - final int tokenStartIndex = token.getCharPositionInLine(); - final int tokenLineNumber = token.getLine(); - final int tokenTextLength = tokenText.length(); - - final DetailAstImpl embeddedExpressionEnd = createImaginary( - TokenTypes.EMBEDDED_EXPRESSION_END, EMBEDDED_EXPRESSION_END, - tokenLineNumber, tokenStartIndex - ); - - // remove delimiters '}' and '"' - final String stringFragment = tokenText.substring( - EMBEDDED_EXPRESSION_END.length(), - tokenTextLength - QUOTE.length() - ); + @Override + public DetailAstImpl visitStringTemplateBegin( + JavaLanguageParser.StringTemplateBeginContext ctx) { + final DetailAstImpl stringTemplateBegin = + create(ctx.STRING_TEMPLATE_BEGIN()); + final Optional stringTemplateContent = + Optional.ofNullable(ctx.STRING_TEMPLATE_CONTENT()) + .map(this::create); + stringTemplateContent.ifPresent(stringTemplateBegin::addChild); + final DetailAstImpl embeddedExpressionBegin = create(ctx.EMBEDDED_EXPRESSION_BEGIN()); + stringTemplateBegin.addChild(embeddedExpressionBegin); + return stringTemplateBegin; + } - final DetailAstImpl endContent = createImaginary( - TokenTypes.STRING_TEMPLATE_CONTENT, stringFragment, - tokenLineNumber, - tokenStartIndex + EMBEDDED_EXPRESSION_END.length() - ); - embeddedExpressionEnd.addNextSibling(endContent); + @Override + public DetailAstImpl visitStringTemplateMid(JavaLanguageParser.StringTemplateMidContext ctx) { + final DetailAstImpl embeddedExpressionEnd = create(ctx.EMBEDDED_EXPRESSION_END()); + final Optional stringTemplateContent = + Optional.ofNullable(ctx.STRING_TEMPLATE_CONTENT()) + .map(this::create); + stringTemplateContent.ifPresent(self -> addLastSibling(embeddedExpressionEnd, self)); + final DetailAstImpl embeddedExpressionBegin = create(ctx.EMBEDDED_EXPRESSION_BEGIN()); + addLastSibling(embeddedExpressionEnd, embeddedExpressionBegin); + return embeddedExpressionEnd; + } - final DetailAstImpl stringTemplateEnd = createImaginary( - TokenTypes.STRING_TEMPLATE_END, QUOTE, - tokenLineNumber, - tokenStartIndex + tokenTextLength - QUOTE.length() - ); - endContent.addNextSibling(stringTemplateEnd); + @Override + public DetailAstImpl visitStringTemplateEnd(JavaLanguageParser.StringTemplateEndContext ctx) { + final DetailAstImpl embeddedExpressionEnd = create(ctx.EMBEDDED_EXPRESSION_END()); + final Optional stringTemplateContent = + Optional.ofNullable(ctx.STRING_TEMPLATE_CONTENT()) + .map(this::create); + stringTemplateContent.ifPresent(self -> addLastSibling(embeddedExpressionEnd, self)); + final DetailAstImpl stringTemplateEnd = create(ctx.STRING_TEMPLATE_END()); + addLastSibling(embeddedExpressionEnd, stringTemplateEnd); return embeddedExpressionEnd; } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java index 95b033126f5..0054904a50d 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/TokenTypes.java @@ -6554,7 +6554,7 @@ public final class TokenTypes { * template may have more than one node of this type. *

For example:

*
-     *     String s = STR."Hello, \{firstName + " " + lastName}!";
+     *     String s = STR."Hello, \{firstName + " " + lastName}";
      * 
*

parses as:

*
@@ -6577,7 +6577,6 @@ public final class TokenTypes {
      *                  |       |   `--STRING_LITERAL -> " "
      *                  |       `--IDENT -> lastName
      *                  |--EMBEDDED_EXPRESSION_END -> }
-     *                  |--STRING_TEMPLATE_CONTENT -> !
      *                  `--STRING_TEMPLATE_END -> "
      * 
* diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/grammar/CompositeLexerContextCache.java b/src/main/java/com/puppycrawl/tools/checkstyle/grammar/CompositeLexerContextCache.java index df8ae466952..1fee7970d4e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/grammar/CompositeLexerContextCache.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/grammar/CompositeLexerContextCache.java @@ -24,6 +24,8 @@ import org.antlr.v4.runtime.Lexer; +import com.puppycrawl.tools.checkstyle.grammar.java.JavaLanguageLexer; + /** * This class is used to keep track of the lexer context to help us determine * when to switch lexer modes. @@ -55,6 +57,7 @@ public void enterTemplateContext(int mode) { final StringTemplateContext newContext = new StringTemplateContext(mode, 0); stringTemplateContextStack.push(newContext); + lexer.pushMode(mode); } /** @@ -62,6 +65,7 @@ public void enterTemplateContext(int mode) { */ public void exitTemplateContext() { stringTemplateContextStack.pop(); + lexer.popMode(); } /** @@ -83,7 +87,7 @@ public void updateLeftCurlyBraceContext() { */ public void updateRightCurlyBraceContext() { if (isInStringTemplateContext()) { - final StringTemplateContext currentContext = stringTemplateContextStack.peek(); + final StringTemplateContext currentContext = stringTemplateContextStack.pop(); if (currentContext.getCurlyBraceDepth() == 0) { // This right curly brace is the start delimiter // of a template middle or end. We consume @@ -91,7 +95,9 @@ public void updateRightCurlyBraceContext() { // in the appropriate lexer mode rule, enter // the corresponding lexer mode, and keep consuming // the rest of the template middle or end. - pushToModeStackWithMore(currentContext.getMode()); + stringTemplateContextStack.push(currentContext); + lexer.setType(JavaLanguageLexer.EMBEDDED_EXPRESSION_END); + lexer.pushMode(currentContext.getMode()); } else { // We've consumed a right curly brace within an embedded expression. @@ -104,17 +110,6 @@ public void updateRightCurlyBraceContext() { } } - /** - * Push a mode to the mode stack and consume more input - * to complete the current token. - * - * @param mode the mode to push to the mode stack - */ - private void pushToModeStackWithMore(int mode) { - lexer.more(); - lexer.pushMode(mode); - } - /** * Check if we are in a string template context. * diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageLexer.g4 b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageLexer.g4 index 95354f2cc77..11ce6dff5ce 100644 --- a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageLexer.g4 +++ b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageLexer.g4 @@ -254,11 +254,12 @@ LITERAL_FALSE: 'false'; CHAR_LITERAL: '\'' (EscapeSequence | ~['\\\r\n]) '\''; -fragment StringFragment: (EscapeSequence | ~["\\\r\n])*; +fragment StringFragment: (EscapeSequence | ~["\\\r\n]); -STRING_LITERAL: '"' StringFragment '"'; +STRING_LITERAL: '"' StringFragment* '"'; -STRING_TEMPLATE_BEGIN: '"' StringFragment '\\' '{' +STRING_TEMPLATE_BEGIN: '"' + { _input.LA(1) != '"' }? { contextCache.enterTemplateContext(StringTemplate); } ; @@ -470,10 +471,8 @@ mode TextBlock; // String template lexical mode mode StringTemplate; - STRING_TEMPLATE_MID: StringFragment '\\' '{' - -> pushMode(DEFAULT_MODE), type(STRING_TEMPLATE_MID); + STRING_TEMPLATE_CONTENT: StringFragment+; + EMBEDDED_EXPRESSION_BEGIN: '\\' '{' -> pushMode(DEFAULT_MODE); - STRING_TEMPLATE_END: StringFragment '"' - { contextCache.exitTemplateContext(); } - -> popMode, type(STRING_TEMPLATE_END); + STRING_TEMPLATE_END: '"' { contextCache.exitTemplateContext(); }; diff --git a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 index 8e121bb82a3..c9fe0c4fdd0 100644 --- a/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 +++ b/src/main/resources/com/puppycrawl/tools/checkstyle/grammar/java/JavaLanguageParser.g4 @@ -768,11 +768,29 @@ template ; stringTemplate - : STRING_TEMPLATE_BEGIN expr? stringTemplateMiddle* STRING_TEMPLATE_END + : stringTemplateBegin expr? stringTemplateMiddle* stringTemplateEnd ; stringTemplateMiddle - : STRING_TEMPLATE_MID expr? + : stringTemplateMid expr? + ; + +stringTemplateBegin + : STRING_TEMPLATE_BEGIN + STRING_TEMPLATE_CONTENT? + EMBEDDED_EXPRESSION_BEGIN + ; + +stringTemplateMid + : EMBEDDED_EXPRESSION_END + STRING_TEMPLATE_CONTENT? + EMBEDDED_EXPRESSION_BEGIN + ; + +stringTemplateEnd + : EMBEDDED_EXPRESSION_END + STRING_TEMPLATE_CONTENT? + STRING_TEMPLATE_END ; classType diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/grammar/java21/Java21AstRegressionTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/grammar/java21/Java21AstRegressionTest.java index 237a21e192a..0b13380d500 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/grammar/java21/Java21AstRegressionTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/grammar/java21/Java21AstRegressionTest.java @@ -46,6 +46,15 @@ public void testBasicStringTemplate() throws Exception { "InputStringTemplateBasic.java")); } + /** + * The purpose of this test is to exercise the + * {@link com.puppycrawl.tools.checkstyle.grammar.CompositeLexerContextCache}: + * getting some curly brace contexts on the stack, making sure that each + * element in the stack has some depth. This ensures that we can handle + * many nested curly braces within an embedded template expression. + * + * @throws Exception upon failure + */ @Test public void testStringTemplateNested() throws Exception { verifyAst( @@ -97,6 +106,17 @@ public void testTextBlockConsecutiveEscapes() throws Exception { "InputTextBlockConsecutiveEscapes.java")); } + @Test + public void testStringTemplateMultiLineWithComments() throws Exception { + verifyAst( + getNonCompilablePath( + "ExpectedStringTemplateMultiLineWithComments.txt"), + getNonCompilablePath( + "InputStringTemplateMultiLineWithComments.java"), + JavaParser.Options.WITH_COMMENTS + ); + } + /** * Unusual test case, but important to prevent regressions. We need to * make sure that we only consume legal escapes in text blocks, and diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasic.txt b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasic.txt index 605e052c881..bda890d21a2 100644 --- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasic.txt +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasic.txt @@ -81,10 +81,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [16:26] | | |--IDENT -> STR [16:23] | | `--STRING_TEMPLATE_BEGIN -> " [16:27] - | | |--STRING_TEMPLATE_CONTENT -> [16:28] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [16:28] | | |--EMBEDDED_EXPRESSION_END -> } [16:32] - | | |--STRING_TEMPLATE_CONTENT -> [16:33] | | `--STRING_TEMPLATE_END -> " [16:33] | `--SEMI -> ; [16:34] |--VARIABLE_DEF -> VARIABLE_DEF [19:4] @@ -115,7 +113,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [22:24] | | |--IDENT -> STR [22:21] | | `--STRING_TEMPLATE_BEGIN -> " [22:26] - | | |--STRING_TEMPLATE_CONTENT -> [22:27] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [22:27] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [22:31] | | | `--METHOD_CALL -> ( [22:31] @@ -130,7 +127,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [22:37] | | | `--RPAREN -> ) [22:38] | | |--EMBEDDED_EXPRESSION_END -> } [22:40] - | | |--STRING_TEMPLATE_CONTENT -> [22:41] | | `--STRING_TEMPLATE_END -> " [22:41] | `--SEMI -> ; [22:42] |--VARIABLE_DEF -> VARIABLE_DEF [25:4] @@ -144,22 +140,18 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [25:24] | | | |--IDENT -> STR [25:21] | | | `--STRING_TEMPLATE_BEGIN -> " [25:26] - | | | |--STRING_TEMPLATE_CONTENT -> [25:27] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:27] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:30] | | | | `--IDENT -> x [25:30] | | | |--EMBEDDED_EXPRESSION_END -> } [25:32] - | | | |--STRING_TEMPLATE_CONTENT -> [25:33] | | | `--STRING_TEMPLATE_END -> " [25:33] | | `--DOT -> . [25:41] | | |--IDENT -> STR [25:38] | | `--STRING_TEMPLATE_BEGIN -> " [25:43] - | | |--STRING_TEMPLATE_CONTENT -> [25:44] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:44] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:47] | | | `--IDENT -> y [25:47] | | |--EMBEDDED_EXPRESSION_END -> } [25:49] - | | |--STRING_TEMPLATE_CONTENT -> [25:50] | | `--STRING_TEMPLATE_END -> " [25:50] | `--SEMI -> ; [25:51] |--VARIABLE_DEF -> VARIABLE_DEF [28:4] @@ -173,7 +165,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [28:24] | | | |--IDENT -> STR [28:21] | | | `--STRING_TEMPLATE_BEGIN -> " [28:26] - | | | |--STRING_TEMPLATE_CONTENT -> [28:27] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:27] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:31] | | | | `--METHOD_CALL -> ( [28:31] @@ -188,12 +179,10 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | | `--RPAREN -> ) [28:37] | | | | `--RPAREN -> ) [28:38] | | | |--EMBEDDED_EXPRESSION_END -> } [28:40] - | | | |--STRING_TEMPLATE_CONTENT -> [28:41] | | | `--STRING_TEMPLATE_END -> " [28:41] | | `--DOT -> . [28:49] | | |--IDENT -> STR [28:46] | | `--STRING_TEMPLATE_BEGIN -> " [28:51] - | | |--STRING_TEMPLATE_CONTENT -> [28:52] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:52] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:56] | | | `--METHOD_CALL -> ( [28:56] @@ -208,7 +197,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [28:62] | | | `--RPAREN -> ) [28:63] | | |--EMBEDDED_EXPRESSION_END -> } [28:65] - | | |--STRING_TEMPLATE_CONTENT -> [28:66] | | `--STRING_TEMPLATE_END -> " [28:66] | `--SEMI -> ; [28:67] |--VARIABLE_DEF -> VARIABLE_DEF [31:4] @@ -222,22 +210,18 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [31:24] | | | |--IDENT -> STR [31:21] | | | `--STRING_TEMPLATE_BEGIN -> " [31:26] - | | | |--STRING_TEMPLATE_CONTENT -> [31:27] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:27] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:30] | | | | `--IDENT -> x [31:30] | | | |--EMBEDDED_EXPRESSION_END -> } [31:32] - | | | |--STRING_TEMPLATE_CONTENT -> [31:33] | | | `--STRING_TEMPLATE_END -> " [31:33] | | `--DOT -> . [31:41] | | |--IDENT -> STR [31:38] | | `--STRING_TEMPLATE_BEGIN -> " [31:43] - | | |--STRING_TEMPLATE_CONTENT -> [31:44] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:44] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:47] | | | `--IDENT -> y [31:47] | | |--EMBEDDED_EXPRESSION_END -> } [31:49] - | | |--STRING_TEMPLATE_CONTENT -> [31:50] | | `--STRING_TEMPLATE_END -> " [31:50] | `--SEMI -> ; [31:51] |--VARIABLE_DEF -> VARIABLE_DEF [34:4] @@ -250,14 +234,12 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [34:24] | | |--IDENT -> STR [34:21] | | `--STRING_TEMPLATE_BEGIN -> " [34:26] - | | |--STRING_TEMPLATE_CONTENT -> [34:27] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [34:27] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [34:32] | | | `--PLUS -> + [34:32] | | | |--IDENT -> x [34:30] | | | `--IDENT -> y [34:34] | | |--EMBEDDED_EXPRESSION_END -> } [34:36] - | | |--STRING_TEMPLATE_CONTENT -> [34:37] | | `--STRING_TEMPLATE_END -> " [34:37] | `--SEMI -> ; [34:38] |--VARIABLE_DEF -> VARIABLE_DEF [37:4] @@ -377,6 +359,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [46:31] | | | `--RPAREN -> ) [46:32] | | |--EMBEDDED_EXPRESSION_END -> } [47:12] + | | |--STRING_TEMPLATE_CONTENT -> there [47:13] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [47:20] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [49:12] | | | `--PLUS -> + [49:12] | | | |--PLUS -> + [48:22] @@ -412,10 +396,7 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | |--EMBEDDED_EXPRESSION_END -> } [49:25] | | | |--STRING_TEMPLATE_CONTENT -> x [49:26] | | | `--STRING_TEMPLATE_END -> " [49:27] - | | |--STRING_TEMPLATE_CONTENT -> there [47:13] - | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [47:20] | | |--EMBEDDED_EXPRESSION_END -> } [50:12] - | | |--STRING_TEMPLATE_CONTENT -> [50:13] | | `--STRING_TEMPLATE_END -> " [50:13] | `--SEMI -> ; [50:14] |--VARIABLE_DEF -> VARIABLE_DEF [52:4] @@ -522,10 +503,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--NUM_INT -> 0 [62:17] | | | `--RPAREN -> ) [62:18] | | `--STRING_TEMPLATE_BEGIN -> " [62:20] - | | |--STRING_TEMPLATE_CONTENT -> [62:21] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [62:21] | | |--EMBEDDED_EXPRESSION_END -> } [62:25] - | | |--STRING_TEMPLATE_CONTENT -> [62:26] | | `--STRING_TEMPLATE_END -> " [62:26] | |--SEMI -> ; [62:27] | |--EXPR -> EXPR [63:19] @@ -563,15 +542,15 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:26] | | | `--IDENT -> x [64:26] | | |--EMBEDDED_EXPRESSION_END -> } [64:28] - | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:33] - | | | `--IDENT -> y [64:33] | | |--STRING_TEMPLATE_CONTENT -> . [64:29] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:30] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:33] + | | | `--IDENT -> y [64:33] | | |--EMBEDDED_EXPRESSION_END -> } [64:35] - | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:40] - | | | `--IDENT -> x [64:40] | | |--STRING_TEMPLATE_CONTENT -> . [64:36] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:37] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:40] + | | | `--IDENT -> x [64:40] | | |--EMBEDDED_EXPRESSION_END -> } [64:42] | | |--STRING_TEMPLATE_CONTENT -> . [64:43] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:44] @@ -579,7 +558,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--STRING_TEMPLATE_CONTENT -> . [64:47] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:48] | | |--EMBEDDED_EXPRESSION_END -> } [64:50] - | | |--STRING_TEMPLATE_CONTENT -> [64:51] | | `--STRING_TEMPLATE_END -> " [64:51] | |--SEMI -> ; [64:52] | `--RCURLY -> } [65:4] diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasicWithTabs.txt b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasicWithTabs.txt index b732010600f..ecbb0b3520b 100644 --- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasicWithTabs.txt +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateBasicWithTabs.txt @@ -81,10 +81,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [16:23] | | |--IDENT -> STR [16:20] | | `--STRING_TEMPLATE_BEGIN -> " [16:24] - | | |--STRING_TEMPLATE_CONTENT -> [16:25] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [16:25] | | |--EMBEDDED_EXPRESSION_END -> } [16:29] - | | |--STRING_TEMPLATE_CONTENT -> [16:30] | | `--STRING_TEMPLATE_END -> " [16:30] | `--SEMI -> ; [16:31] |--VARIABLE_DEF -> VARIABLE_DEF [19:1] @@ -115,7 +113,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [22:21] | | |--IDENT -> STR [22:18] | | `--STRING_TEMPLATE_BEGIN -> " [22:23] - | | |--STRING_TEMPLATE_CONTENT -> [22:24] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [22:24] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [22:28] | | | `--METHOD_CALL -> ( [22:28] @@ -130,7 +127,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [22:34] | | | `--RPAREN -> ) [22:35] | | |--EMBEDDED_EXPRESSION_END -> } [22:37] - | | |--STRING_TEMPLATE_CONTENT -> [22:38] | | `--STRING_TEMPLATE_END -> " [22:38] | `--SEMI -> ; [22:39] |--VARIABLE_DEF -> VARIABLE_DEF [25:1] @@ -144,22 +140,18 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [25:21] | | | |--IDENT -> STR [25:18] | | | `--STRING_TEMPLATE_BEGIN -> " [25:23] - | | | |--STRING_TEMPLATE_CONTENT -> [25:24] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:24] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:27] | | | | `--IDENT -> x [25:27] | | | |--EMBEDDED_EXPRESSION_END -> } [25:29] - | | | |--STRING_TEMPLATE_CONTENT -> [25:30] | | | `--STRING_TEMPLATE_END -> " [25:30] | | `--DOT -> . [25:38] | | |--IDENT -> STR [25:35] | | `--STRING_TEMPLATE_BEGIN -> " [25:40] - | | |--STRING_TEMPLATE_CONTENT -> [25:41] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:41] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:44] | | | `--IDENT -> y [25:44] | | |--EMBEDDED_EXPRESSION_END -> } [25:46] - | | |--STRING_TEMPLATE_CONTENT -> [25:47] | | `--STRING_TEMPLATE_END -> " [25:47] | `--SEMI -> ; [25:48] |--VARIABLE_DEF -> VARIABLE_DEF [28:1] @@ -173,7 +165,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [28:21] | | | |--IDENT -> STR [28:18] | | | `--STRING_TEMPLATE_BEGIN -> " [28:23] - | | | |--STRING_TEMPLATE_CONTENT -> [28:24] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:24] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:28] | | | | `--METHOD_CALL -> ( [28:28] @@ -188,12 +179,10 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | | `--RPAREN -> ) [28:34] | | | | `--RPAREN -> ) [28:35] | | | |--EMBEDDED_EXPRESSION_END -> } [28:37] - | | | |--STRING_TEMPLATE_CONTENT -> [28:38] | | | `--STRING_TEMPLATE_END -> " [28:38] | | `--DOT -> . [28:46] | | |--IDENT -> STR [28:43] | | `--STRING_TEMPLATE_BEGIN -> " [28:48] - | | |--STRING_TEMPLATE_CONTENT -> [28:49] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:49] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:53] | | | `--METHOD_CALL -> ( [28:53] @@ -208,7 +197,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [28:59] | | | `--RPAREN -> ) [28:60] | | |--EMBEDDED_EXPRESSION_END -> } [28:62] - | | |--STRING_TEMPLATE_CONTENT -> [28:63] | | `--STRING_TEMPLATE_END -> " [28:63] | `--SEMI -> ; [28:64] |--VARIABLE_DEF -> VARIABLE_DEF [31:1] @@ -222,22 +210,18 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--DOT -> . [31:21] | | | |--IDENT -> STR [31:18] | | | `--STRING_TEMPLATE_BEGIN -> " [31:23] - | | | |--STRING_TEMPLATE_CONTENT -> [31:24] | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:24] | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:27] | | | | `--IDENT -> x [31:27] | | | |--EMBEDDED_EXPRESSION_END -> } [31:29] - | | | |--STRING_TEMPLATE_CONTENT -> [31:30] | | | `--STRING_TEMPLATE_END -> " [31:30] | | `--DOT -> . [31:38] | | |--IDENT -> STR [31:35] | | `--STRING_TEMPLATE_BEGIN -> " [31:40] - | | |--STRING_TEMPLATE_CONTENT -> [31:41] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:41] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:44] | | | `--IDENT -> y [31:44] | | |--EMBEDDED_EXPRESSION_END -> } [31:46] - | | |--STRING_TEMPLATE_CONTENT -> [31:47] | | `--STRING_TEMPLATE_END -> " [31:47] | `--SEMI -> ; [31:48] |--VARIABLE_DEF -> VARIABLE_DEF [34:1] @@ -250,14 +234,12 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | `--DOT -> . [34:21] | | |--IDENT -> STR [34:18] | | `--STRING_TEMPLATE_BEGIN -> " [34:23] - | | |--STRING_TEMPLATE_CONTENT -> [34:24] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [34:24] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [34:29] | | | `--PLUS -> + [34:29] | | | |--IDENT -> x [34:27] | | | `--IDENT -> y [34:31] | | |--EMBEDDED_EXPRESSION_END -> } [34:33] - | | |--STRING_TEMPLATE_CONTENT -> [34:34] | | `--STRING_TEMPLATE_END -> " [34:34] | `--SEMI -> ; [34:35] |--VARIABLE_DEF -> VARIABLE_DEF [37:1] @@ -377,6 +359,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--RPAREN -> ) [46:22] | | | `--RPAREN -> ) [46:23] | | |--EMBEDDED_EXPRESSION_END -> } [47:3] + | | |--STRING_TEMPLATE_CONTENT -> there [47:4] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [47:11] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [49:3] | | | `--PLUS -> + [49:3] | | | |--PLUS -> + [48:13] @@ -412,10 +396,7 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | |--EMBEDDED_EXPRESSION_END -> } [49:16] | | | |--STRING_TEMPLATE_CONTENT -> x [49:17] | | | `--STRING_TEMPLATE_END -> " [49:18] - | | |--STRING_TEMPLATE_CONTENT -> there [47:4] - | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [47:11] | | |--EMBEDDED_EXPRESSION_END -> } [50:3] - | | |--STRING_TEMPLATE_CONTENT -> [50:4] | | `--STRING_TEMPLATE_END -> " [50:4] | `--SEMI -> ; [50:5] |--VARIABLE_DEF -> VARIABLE_DEF [52:1] @@ -522,10 +503,8 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | `--NUM_INT -> 0 [62:11] | | | `--RPAREN -> ) [62:12] | | `--STRING_TEMPLATE_BEGIN -> " [62:14] - | | |--STRING_TEMPLATE_CONTENT -> [62:15] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [62:15] | | |--EMBEDDED_EXPRESSION_END -> } [62:19] - | | |--STRING_TEMPLATE_CONTENT -> [62:20] | | `--STRING_TEMPLATE_END -> " [62:20] | |--SEMI -> ; [62:21] | |--EXPR -> EXPR [63:13] @@ -563,15 +542,15 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:20] | | | `--IDENT -> x [64:20] | | |--EMBEDDED_EXPRESSION_END -> } [64:22] - | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:27] - | | | `--IDENT -> y [64:27] | | |--STRING_TEMPLATE_CONTENT -> . [64:23] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:24] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:27] + | | | `--IDENT -> y [64:27] | | |--EMBEDDED_EXPRESSION_END -> } [64:29] - | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:34] - | | | `--IDENT -> x [64:34] | | |--STRING_TEMPLATE_CONTENT -> . [64:30] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:31] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:34] + | | | `--IDENT -> x [64:34] | | |--EMBEDDED_EXPRESSION_END -> } [64:36] | | |--STRING_TEMPLATE_CONTENT -> . [64:37] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:38] @@ -579,7 +558,6 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | |--STRING_TEMPLATE_CONTENT -> . [64:41] | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:42] | | |--EMBEDDED_EXPRESSION_END -> } [64:44] - | | |--STRING_TEMPLATE_CONTENT -> [64:45] | | `--STRING_TEMPLATE_END -> " [64:45] | |--SEMI -> ; [64:46] | `--RCURLY -> } [65:1] diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateMultiLineWithComments.txt b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateMultiLineWithComments.txt new file mode 100644 index 00000000000..ccf1062f6b3 --- /dev/null +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateMultiLineWithComments.txt @@ -0,0 +1,628 @@ +COMPILATION_UNIT -> COMPILATION_UNIT [2:0] +|--SINGLE_LINE_COMMENT -> // [1:0] +| `--COMMENT_CONTENT -> non-compiled with javac: Compilable with Java21\n [1:2] +|--PACKAGE_DEF -> package [2:0] +| |--ANNOTATIONS -> ANNOTATIONS [2:47] +| |--DOT -> . [2:47] +| | |--DOT -> . [2:39] +| | | |--DOT -> . [2:28] +| | | | |--DOT -> . [2:22] +| | | | | |--DOT -> . [2:11] +| | | | | | |--IDENT -> com [2:8] +| | | | | | `--IDENT -> puppycrawl [2:12] +| | | | | `--IDENT -> tools [2:23] +| | | | `--IDENT -> checkstyle [2:29] +| | | `--IDENT -> grammar [2:40] +| | `--IDENT -> java21 [2:48] +| `--SEMI -> ; [2:54] +|--IMPORT -> import [4:0] +| |--DOT -> . [4:16] +| | |--DOT -> . [4:11] +| | | |--IDENT -> java [4:7] +| | | `--IDENT -> util [4:12] +| | `--IDENT -> List [4:17] +| `--SEMI -> ; [4:21] +`--CLASS_DEF -> CLASS_DEF [6:0] + |--MODIFIERS -> MODIFIERS [6:0] + | `--LITERAL_PUBLIC -> public [6:0] + |--LITERAL_CLASS -> class [6:7] + |--IDENT -> InputStringTemplateMultiLineWithComments [6:13] + `--OBJBLOCK -> OBJBLOCK [6:54] + |--LCURLY -> { [6:54] + |--VARIABLE_DEF -> VARIABLE_DEF [7:4] + | |--MODIFIERS -> MODIFIERS [7:4] + | |--TYPE -> TYPE [7:4] + | | `--LITERAL_INT -> int [7:4] + | |--IDENT -> x [7:8] + | |--ASSIGN -> = [7:10] + | | `--EXPR -> EXPR [7:12] + | | `--NUM_INT -> 10 [7:12] + | `--SEMI -> ; [7:14] + |--VARIABLE_DEF -> VARIABLE_DEF [8:4] + | |--MODIFIERS -> MODIFIERS [8:4] + | |--TYPE -> TYPE [8:4] + | | `--LITERAL_INT -> int [8:4] + | |--IDENT -> y [8:8] + | |--ASSIGN -> = [8:10] + | | `--EXPR -> EXPR [8:12] + | | `--NUM_INT -> 20 [8:12] + | `--SEMI -> ; [8:14] + |--VARIABLE_DEF -> VARIABLE_DEF [11:4] + | |--MODIFIERS -> MODIFIERS [11:4] + | |--TYPE -> TYPE [11:4] + | | |--SINGLE_LINE_COMMENT -> // [10:4] + | | | `--COMMENT_CONTENT -> most basic example, empty string template expression\n [10:6] + | | `--IDENT -> String [11:4] + | |--IDENT -> result1 [11:11] + | |--ASSIGN -> = [11:19] + | | `--EXPR -> EXPR [11:24] + | | `--DOT -> . [11:24] + | | |--IDENT -> STR [11:21] + | | `--STRING_TEMPLATE_BEGIN -> " [11:25] + | | |--STRING_TEMPLATE_CONTENT -> [11:26] + | | `--STRING_TEMPLATE_END -> " [11:26] + | `--SEMI -> ; [11:27] + |--VARIABLE_DEF -> VARIABLE_DEF [13:4] + | |--MODIFIERS -> MODIFIERS [13:4] + | |--TYPE -> TYPE [13:4] + | | `--IDENT -> String [13:4] + | |--IDENT -> result1_1 [13:11] + | |--ASSIGN -> = [13:21] + | | `--EXPR -> EXPR [13:26] + | | `--DOT -> . [13:26] + | | |--IDENT -> STR [13:23] + | | `--STRING_TEMPLATE_BEGIN -> " [13:27] + | | |--STRING_TEMPLATE_CONTENT -> Hello world! [13:28] + | | `--STRING_TEMPLATE_END -> " [13:40] + | `--SEMI -> ; [13:41] + |--VARIABLE_DEF -> VARIABLE_DEF [16:4] + | |--MODIFIERS -> MODIFIERS [16:4] + | |--TYPE -> TYPE [16:4] + | | |--SINGLE_LINE_COMMENT -> // [15:4] + | | | `--COMMENT_CONTENT -> no content, no expression\n [15:6] + | | `--IDENT -> String [16:4] + | |--IDENT -> result1_2 [16:11] + | |--ASSIGN -> = [16:21] + | | `--EXPR -> EXPR [16:26] + | | `--DOT -> . [16:26] + | | |--IDENT -> STR [16:23] + | | `--STRING_TEMPLATE_BEGIN -> " [16:27] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [16:28] + | | |--EMBEDDED_EXPRESSION_END -> } [16:32] + | | `--STRING_TEMPLATE_END -> " [16:33] + | `--SEMI -> ; [16:34] + |--VARIABLE_DEF -> VARIABLE_DEF [19:4] + | |--MODIFIERS -> MODIFIERS [19:4] + | |--TYPE -> TYPE [19:4] + | | |--SINGLE_LINE_COMMENT -> // [18:4] + | | | `--COMMENT_CONTENT -> simple single value interpolation\n [18:6] + | | `--IDENT -> String [19:4] + | |--IDENT -> result2 [19:11] + | |--ASSIGN -> = [19:19] + | | `--EXPR -> EXPR [19:24] + | | `--DOT -> . [19:24] + | | |--IDENT -> STR [19:21] + | | `--STRING_TEMPLATE_BEGIN -> " [19:26] + | | |--STRING_TEMPLATE_CONTENT -> x [19:27] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [19:28] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [19:31] + | | | `--IDENT -> x [19:31] + | | |--EMBEDDED_EXPRESSION_END -> } [19:33] + | | |--STRING_TEMPLATE_CONTENT -> x [19:34] + | | `--STRING_TEMPLATE_END -> " [19:35] + | `--SEMI -> ; [19:36] + |--VARIABLE_DEF -> VARIABLE_DEF [22:4] + | |--MODIFIERS -> MODIFIERS [22:4] + | |--TYPE -> TYPE [22:4] + | | |--SINGLE_LINE_COMMENT -> // [19:38] + | | | `--COMMENT_CONTENT -> comment\n [19:40] + | | |--SINGLE_LINE_COMMENT -> // [21:4] + | | | `--COMMENT_CONTENT -> simple single value interpolation with a method call\n [21:6] + | | `--IDENT -> String [22:4] + | |--IDENT -> result3 [22:11] + | |--ASSIGN -> = [22:19] + | | `--EXPR -> EXPR [22:24] + | | `--DOT -> . [22:24] + | | |--IDENT -> STR [22:21] + | | `--STRING_TEMPLATE_BEGIN -> " [22:26] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [22:27] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [22:31] + | | | `--METHOD_CALL -> ( [22:31] + | | | |--IDENT -> y [22:30] + | | | |--ELIST -> ELIST [22:33] + | | | | `--EXPR -> EXPR [22:33] + | | | | `--METHOD_CALL -> ( [22:33] + | | | | |--IDENT -> y [22:32] + | | | | |--ELIST -> ELIST [22:34] + | | | | | `--EXPR -> EXPR [22:34] + | | | | | `--STRING_LITERAL -> "y" [22:34] + | | | | `--RPAREN -> ) [22:37] + | | | `--RPAREN -> ) [22:38] + | | |--EMBEDDED_EXPRESSION_END -> } [22:40] + | | `--STRING_TEMPLATE_END -> " [22:41] + | `--SEMI -> ; [22:42] + |--VARIABLE_DEF -> VARIABLE_DEF [25:4] + | |--MODIFIERS -> MODIFIERS [25:4] + | |--TYPE -> TYPE [25:4] + | | |--SINGLE_LINE_COMMENT -> // [24:4] + | | | `--COMMENT_CONTENT -> bit more complex example, multiple interpolations\n [24:6] + | | `--IDENT -> String [25:4] + | |--IDENT -> result4 [25:11] + | |--ASSIGN -> = [25:19] + | | `--EXPR -> EXPR [25:36] + | | `--PLUS -> + [25:36] + | | |--DOT -> . [25:24] + | | | |--IDENT -> STR [25:21] + | | | `--STRING_TEMPLATE_BEGIN -> " [25:26] + | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:27] + | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:30] + | | | | `--IDENT -> x [25:30] + | | | |--EMBEDDED_EXPRESSION_END -> } [25:32] + | | | `--STRING_TEMPLATE_END -> " [25:33] + | | `--DOT -> . [25:41] + | | |--IDENT -> STR [25:38] + | | `--STRING_TEMPLATE_BEGIN -> " [25:43] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [25:44] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [25:47] + | | | `--IDENT -> y [25:47] + | | |--EMBEDDED_EXPRESSION_END -> } [25:49] + | | `--STRING_TEMPLATE_END -> " [25:50] + | `--SEMI -> ; [25:51] + |--VARIABLE_DEF -> VARIABLE_DEF [28:4] + | |--MODIFIERS -> MODIFIERS [28:4] + | |--TYPE -> TYPE [28:4] + | | |--SINGLE_LINE_COMMENT -> // [27:4] + | | | `--COMMENT_CONTENT -> bit more complex example, multiple interpolations with method calls\n [27:6] + | | `--IDENT -> String [28:4] + | |--IDENT -> result5 [28:11] + | |--ASSIGN -> = [28:19] + | | `--EXPR -> EXPR [28:44] + | | `--PLUS -> + [28:44] + | | |--DOT -> . [28:24] + | | | |--IDENT -> STR [28:21] + | | | `--STRING_TEMPLATE_BEGIN -> " [28:26] + | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:27] + | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:31] + | | | | `--METHOD_CALL -> ( [28:31] + | | | | |--IDENT -> y [28:30] + | | | | |--ELIST -> ELIST [28:33] + | | | | | `--EXPR -> EXPR [28:33] + | | | | | `--METHOD_CALL -> ( [28:33] + | | | | | |--IDENT -> y [28:32] + | | | | | |--ELIST -> ELIST [28:34] + | | | | | | `--EXPR -> EXPR [28:34] + | | | | | | `--STRING_LITERAL -> "y" [28:34] + | | | | | `--RPAREN -> ) [28:37] + | | | | `--RPAREN -> ) [28:38] + | | | |--EMBEDDED_EXPRESSION_END -> } [28:40] + | | | `--STRING_TEMPLATE_END -> " [28:41] + | | `--DOT -> . [28:49] + | | |--IDENT -> STR [28:46] + | | `--STRING_TEMPLATE_BEGIN -> " [28:51] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [28:52] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [28:56] + | | | `--METHOD_CALL -> ( [28:56] + | | | |--IDENT -> y [28:55] + | | | |--ELIST -> ELIST [28:58] + | | | | `--EXPR -> EXPR [28:58] + | | | | `--METHOD_CALL -> ( [28:58] + | | | | |--IDENT -> y [28:57] + | | | | |--ELIST -> ELIST [28:59] + | | | | | `--EXPR -> EXPR [28:59] + | | | | | `--STRING_LITERAL -> "y" [28:59] + | | | | |--BLOCK_COMMENT_BEGIN -> /* [28:62] + | | | | | |--COMMENT_CONTENT -> yep, comment here, too [28:64] + | | | | | `--BLOCK_COMMENT_END -> */ [28:85] + | | | | `--RPAREN -> ) [28:88] + | | | `--RPAREN -> ) [28:89] + | | |--EMBEDDED_EXPRESSION_END -> } [28:91] + | | `--STRING_TEMPLATE_END -> " [28:92] + | `--SEMI -> ; [28:93] + |--VARIABLE_DEF -> VARIABLE_DEF [31:4] + | |--MODIFIERS -> MODIFIERS [31:4] + | |--TYPE -> TYPE [31:4] + | | |--SINGLE_LINE_COMMENT -> // [30:4] + | | | `--COMMENT_CONTENT -> string template concatenation\n [30:6] + | | `--IDENT -> String [31:4] + | |--IDENT -> result6 [31:11] + | |--ASSIGN -> = [31:19] + | | `--EXPR -> EXPR [31:36] + | | `--PLUS -> + [31:36] + | | |--DOT -> . [31:24] + | | | |--IDENT -> STR [31:21] + | | | `--STRING_TEMPLATE_BEGIN -> " [31:26] + | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:27] + | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:30] + | | | | `--IDENT -> x [31:30] + | | | |--EMBEDDED_EXPRESSION_END -> } [31:32] + | | | `--STRING_TEMPLATE_END -> " [31:33] + | | `--DOT -> . [31:58] + | | |--BLOCK_COMMENT_BEGIN -> /* [31:38] + | | | |--COMMENT_CONTENT -> comment here [31:40] + | | | `--BLOCK_COMMENT_END -> */ [31:51] + | | |--IDENT -> STR [31:55] + | | `--STRING_TEMPLATE_BEGIN -> " [31:60] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [31:61] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [31:64] + | | | `--IDENT -> y [31:64] + | | |--EMBEDDED_EXPRESSION_END -> } [31:66] + | | `--STRING_TEMPLATE_END -> " [31:67] + | `--SEMI -> ; [31:68] + |--VARIABLE_DEF -> VARIABLE_DEF [34:4] + | |--MODIFIERS -> MODIFIERS [34:4] + | |--TYPE -> TYPE [34:4] + | | |--SINGLE_LINE_COMMENT -> // [33:4] + | | | `--COMMENT_CONTENT -> concatentation in embedded expression\n [33:6] + | | `--IDENT -> String [34:4] + | |--IDENT -> result7 [34:11] + | |--ASSIGN -> = [34:19] + | | `--EXPR -> EXPR [34:24] + | | `--DOT -> . [34:24] + | | |--IDENT -> STR [34:21] + | | `--STRING_TEMPLATE_BEGIN -> " [34:26] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [34:27] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [34:32] + | | | `--PLUS -> + [34:32] + | | | |--IDENT -> x [34:30] + | | | `--IDENT -> y [34:34] + | | |--BLOCK_COMMENT_BEGIN -> /* [34:36] + | | | |--COMMENT_CONTENT -> comment here too [34:38] + | | | `--BLOCK_COMMENT_END -> */ [34:53] + | | |--EMBEDDED_EXPRESSION_END -> } [34:57] + | | `--STRING_TEMPLATE_END -> " [34:58] + | `--SEMI -> ; [34:59] + |--VARIABLE_DEF -> VARIABLE_DEF [37:4] + | |--MODIFIERS -> MODIFIERS [37:4] + | |--TYPE -> TYPE [37:4] + | | |--SINGLE_LINE_COMMENT -> // [36:4] + | | | `--COMMENT_CONTENT -> concatentation in embedded expression with method calls\n [36:6] + | | `--IDENT -> String [37:4] + | |--IDENT -> result8 [37:11] + | |--ASSIGN -> = [37:19] + | | `--EXPR -> EXPR [37:24] + | | `--DOT -> . [37:24] + | | |--IDENT -> STR [37:21] + | | |--BLOCK_COMMENT_BEGIN -> /* [37:25] + | | | |--COMMENT_CONTENT -> comment here [37:27] + | | | `--BLOCK_COMMENT_END -> */ [37:38] + | | `--STRING_TEMPLATE_BEGIN -> " [37:42] + | | |--STRING_TEMPLATE_CONTENT -> hey [37:43] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [37:47] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [37:60] + | | | `--PLUS -> + [37:60] + | | | |--METHOD_CALL -> ( [37:51] + | | | | |--IDENT -> y [37:50] + | | | | |--ELIST -> ELIST [37:53] + | | | | | `--EXPR -> EXPR [37:53] + | | | | | `--METHOD_CALL -> ( [37:53] + | | | | | |--IDENT -> y [37:52] + | | | | | |--ELIST -> ELIST [37:54] + | | | | | | `--EXPR -> EXPR [37:54] + | | | | | | `--STRING_LITERAL -> "y" [37:54] + | | | | | `--RPAREN -> ) [37:57] + | | | | `--RPAREN -> ) [37:58] + | | | `--METHOD_CALL -> ( [37:63] + | | | |--IDENT -> y [37:62] + | | | |--ELIST -> ELIST [37:65] + | | | | `--EXPR -> EXPR [37:65] + | | | | `--METHOD_CALL -> ( [37:65] + | | | | |--IDENT -> y [37:64] + | | | | |--ELIST -> ELIST [37:66] + | | | | | `--EXPR -> EXPR [37:66] + | | | | | `--STRING_LITERAL -> "y" [37:66] + | | | | `--RPAREN -> ) [37:69] + | | | `--RPAREN -> ) [37:70] + | | |--EMBEDDED_EXPRESSION_END -> } [37:72] + | | |--STRING_TEMPLATE_CONTENT -> there [37:73] + | | `--STRING_TEMPLATE_END -> " [37:79] + | `--SEMI -> ; [37:80] + |--VARIABLE_DEF -> VARIABLE_DEF [40:4] + | |--MODIFIERS -> MODIFIERS [40:4] + | |--TYPE -> TYPE [40:4] + | | |--SINGLE_LINE_COMMENT -> // [39:4] + | | | `--COMMENT_CONTENT -> multiple lines\n [39:6] + | | `--IDENT -> String [40:4] + | |--IDENT -> result9 [40:11] + | |--ASSIGN -> = [40:19] + | | `--EXPR -> EXPR [40:24] + | | `--DOT -> . [40:24] + | | |--IDENT -> STR [40:21] + | | `--STRING_TEMPLATE_BEGIN -> " [40:26] + | | |--STRING_TEMPLATE_CONTENT -> hey [40:27] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [40:31] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [41:22] + | | | `--PLUS -> + [41:22] + | | | |--METHOD_CALL -> ( [41:13] + | | | | |--SINGLE_LINE_COMMENT -> // [40:34] + | | | | | `--COMMENT_CONTENT -> comment here\n [40:36] + | | | | |--IDENT -> y [41:12] + | | | | |--ELIST -> ELIST [41:15] + | | | | | `--EXPR -> EXPR [41:15] + | | | | | `--METHOD_CALL -> ( [41:15] + | | | | | |--IDENT -> y [41:14] + | | | | | |--ELIST -> ELIST [41:16] + | | | | | | `--EXPR -> EXPR [41:16] + | | | | | | `--STRING_LITERAL -> "y" [41:16] + | | | | | `--RPAREN -> ) [41:19] + | | | | `--RPAREN -> ) [41:20] + | | | `--METHOD_CALL -> ( [41:25] + | | | |--IDENT -> y [41:24] + | | | |--ELIST -> ELIST [41:27] + | | | | `--EXPR -> EXPR [41:27] + | | | | `--METHOD_CALL -> ( [41:27] + | | | | |--IDENT -> y [41:26] + | | | | |--ELIST -> ELIST [41:28] + | | | | | `--EXPR -> EXPR [41:28] + | | | | | `--STRING_LITERAL -> "y" [41:28] + | | | | `--RPAREN -> ) [41:31] + | | | `--RPAREN -> ) [41:32] + | | |--EMBEDDED_EXPRESSION_END -> } [42:12] + | | |--STRING_TEMPLATE_CONTENT -> there [42:13] + | | `--STRING_TEMPLATE_END -> " [42:19] + | `--SEMI -> ; [42:20] + |--VARIABLE_DEF -> VARIABLE_DEF [45:4] + | |--MODIFIERS -> MODIFIERS [45:4] + | |--TYPE -> TYPE [45:4] + | | |--SINGLE_LINE_COMMENT -> // [44:4] + | | | `--COMMENT_CONTENT -> multiple lines with many expressions and comments\n [44:6] + | | `--IDENT -> String [45:4] + | |--IDENT -> result10 [45:11] + | |--ASSIGN -> = [45:20] + | | `--EXPR -> EXPR [45:25] + | | `--DOT -> . [45:25] + | | |--IDENT -> STR [45:22] + | | `--STRING_TEMPLATE_BEGIN -> " [45:27] + | | |--STRING_TEMPLATE_CONTENT -> hey [45:28] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [45:32] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [46:22] + | | | `--PLUS -> + [46:22] + | | | |--METHOD_CALL -> ( [46:13] + | | | | |--BLOCK_COMMENT_BEGIN -> /* [45:35] + | | | | | |--COMMENT_CONTENT -> ****comment here [45:37] + | | | | | `--BLOCK_COMMENT_END -> */ [45:52] + | | | | |--SINGLE_LINE_COMMENT -> // [45:56] + | | | | | `--COMMENT_CONTENT -> comment here\n [45:58] + | | | | |--IDENT -> y [46:12] + | | | | |--ELIST -> ELIST [46:15] + | | | | | `--EXPR -> EXPR [46:15] + | | | | | `--METHOD_CALL -> ( [46:15] + | | | | | |--IDENT -> y [46:14] + | | | | | |--ELIST -> ELIST [46:16] + | | | | | | `--EXPR -> EXPR [46:16] + | | | | | | `--STRING_LITERAL -> "y" [46:16] + | | | | | `--RPAREN -> ) [46:19] + | | | | `--RPAREN -> ) [46:20] + | | | `--METHOD_CALL -> ( [46:25] + | | | |--IDENT -> y [46:24] + | | | |--ELIST -> ELIST [46:27] + | | | | `--EXPR -> EXPR [46:27] + | | | | `--METHOD_CALL -> ( [46:27] + | | | | |--IDENT -> y [46:26] + | | | | |--ELIST -> ELIST [46:28] + | | | | | `--EXPR -> EXPR [46:28] + | | | | | `--STRING_LITERAL -> "y" [46:28] + | | | | `--RPAREN -> ) [46:31] + | | | `--RPAREN -> ) [46:32] + | | |--BLOCK_COMMENT_BEGIN -> /* [46:34] + | | | |--COMMENT_CONTENT -> comment here [46:36] + | | | `--BLOCK_COMMENT_END -> */ [46:49] + | | |--EMBEDDED_EXPRESSION_END -> } [47:12] + | | |--STRING_TEMPLATE_CONTENT -> there [47:13] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [47:20] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [49:12] + | | | |--SINGLE_LINE_COMMENT -> // [48:34] + | | | | `--COMMENT_CONTENT -> comment there\n [48:36] + | | | `--PLUS -> + [49:12] + | | | |--PLUS -> + [48:22] + | | | | |--METHOD_CALL -> ( [48:13] + | | | | | |--BLOCK_COMMENT_BEGIN -> /* [47:23] + | | | | | | |--COMMENT_CONTENT -> [47:25] + | | | | | | `--BLOCK_COMMENT_END -> */ [47:24] + | | | | | |--SINGLE_LINE_COMMENT -> // [47:28] + | | | | | | `--COMMENT_CONTENT -> comment here\n [47:30] + | | | | | |--IDENT -> y [48:12] + | | | | | |--ELIST -> ELIST [48:15] + | | | | | | `--EXPR -> EXPR [48:15] + | | | | | | `--METHOD_CALL -> ( [48:15] + | | | | | | |--IDENT -> y [48:14] + | | | | | | |--ELIST -> ELIST [48:16] + | | | | | | | `--EXPR -> EXPR [48:16] + | | | | | | | `--STRING_LITERAL -> "y" [48:16] + | | | | | | `--RPAREN -> ) [48:19] + | | | | | `--RPAREN -> ) [48:20] + | | | | `--METHOD_CALL -> ( [48:25] + | | | | |--IDENT -> y [48:24] + | | | | |--ELIST -> ELIST [48:27] + | | | | | `--EXPR -> EXPR [48:27] + | | | | | `--METHOD_CALL -> ( [48:27] + | | | | | |--IDENT -> y [48:26] + | | | | | |--ELIST -> ELIST [48:28] + | | | | | | `--EXPR -> EXPR [48:28] + | | | | | | `--STRING_LITERAL -> "y" [48:28] + | | | | | `--RPAREN -> ) [48:31] + | | | | `--RPAREN -> ) [48:32] + | | | `--DOT -> . [49:17] + | | | |--IDENT -> STR [49:14] + | | | `--STRING_TEMPLATE_BEGIN -> " [49:18] + | | | |--STRING_TEMPLATE_CONTENT -> x [49:19] + | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [49:20] + | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [49:23] + | | | | `--IDENT -> x [49:23] + | | | |--EMBEDDED_EXPRESSION_END -> } [49:25] + | | | |--STRING_TEMPLATE_CONTENT -> x [49:26] + | | | `--STRING_TEMPLATE_END -> " [49:27] + | | |--SINGLE_LINE_COMMENT -> // [49:29] + | | | `--COMMENT_CONTENT -> comment everywhere\n [49:31] + | | |--EMBEDDED_EXPRESSION_END -> } [50:12] + | | `--STRING_TEMPLATE_END -> " [50:13] + | `--SEMI -> ; [50:14] + |--VARIABLE_DEF -> VARIABLE_DEF [52:4] + | |--MODIFIERS -> MODIFIERS [52:4] + | |--TYPE -> TYPE [52:4] + | | `--IDENT -> String [52:4] + | |--IDENT -> name [52:11] + | |--ASSIGN -> = [52:16] + | | `--EXPR -> EXPR [52:18] + | | `--STRING_LITERAL -> "world" [52:18] + | `--SEMI -> ; [52:25] + |--VARIABLE_DEF -> VARIABLE_DEF [53:4] + | |--MODIFIERS -> MODIFIERS [53:4] + | |--TYPE -> TYPE [53:4] + | | `--IDENT -> String [53:4] + | |--IDENT -> s [53:11] + | |--ASSIGN -> = [53:13] + | | `--EXPR -> EXPR [53:18] + | | `--DOT -> . [53:18] + | | |--IDENT -> STR [53:15] + | | `--STRING_TEMPLATE_BEGIN -> " [53:19] + | | |--STRING_TEMPLATE_CONTENT -> Hello, [53:20] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [53:27] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [53:30] + | | | `--IDENT -> name [53:30] + | | |--EMBEDDED_EXPRESSION_END -> } [53:35] + | | |--STRING_TEMPLATE_CONTENT -> ! [53:36] + | | `--STRING_TEMPLATE_END -> " [53:37] + | `--SEMI -> ; [53:38] + |--METHOD_DEF -> METHOD_DEF [55:4] + | |--MODIFIERS -> MODIFIERS [55:4] + | | |--LITERAL_PRIVATE -> private [55:4] + | | `--LITERAL_STATIC -> static [55:12] + | |--TYPE -> TYPE [55:19] + | | `--IDENT -> String [55:19] + | |--IDENT -> y [55:26] + | |--LPAREN -> ( [55:27] + | |--PARAMETERS -> PARAMETERS [55:28] + | | `--PARAMETER_DEF -> PARAMETER_DEF [55:28] + | | |--MODIFIERS -> MODIFIERS [55:28] + | | |--TYPE -> TYPE [55:28] + | | | `--IDENT -> String [55:28] + | | `--IDENT -> y [55:35] + | |--RPAREN -> ) [55:36] + | `--SLIST -> { [55:38] + | |--LITERAL_RETURN -> return [56:8] + | | |--EXPR -> EXPR [56:15] + | | | `--STRING_LITERAL -> "y" [56:15] + | | `--SEMI -> ; [56:18] + | `--RCURLY -> } [57:4] + |--METHOD_DEF -> METHOD_DEF [60:4] + | |--MODIFIERS -> MODIFIERS [60:4] + | |--TYPE -> TYPE [60:4] + | | |--SINGLE_LINE_COMMENT -> // [59:4] + | | | `--COMMENT_CONTENT -> Verify proper behavior of TransType w.r.t. templated Strings\n [59:6] + | | `--LITERAL_VOID -> void [60:4] + | |--IDENT -> x [60:9] + | |--LPAREN -> ( [60:10] + | |--PARAMETERS -> PARAMETERS [60:11] + | | `--PARAMETER_DEF -> PARAMETER_DEF [60:11] + | | |--MODIFIERS -> MODIFIERS [60:11] + | | |--TYPE -> TYPE [60:11] + | | | |--IDENT -> List [60:11] + | | | `--TYPE_ARGUMENTS -> TYPE_ARGUMENTS [60:15] + | | | |--GENERIC_START -> < [60:15] + | | | |--TYPE_ARGUMENT -> TYPE_ARGUMENT [60:16] + | | | | |--WILDCARD_TYPE -> ? [60:16] + | | | | `--TYPE_UPPER_BOUNDS -> extends [60:18] + | | | | `--DOT -> . [60:40] + | | | | |--IDENT -> StringTemplate [60:26] + | | | | |--IDENT -> Processor [60:41] + | | | | `--TYPE_ARGUMENTS -> TYPE_ARGUMENTS [60:50] + | | | | |--GENERIC_START -> < [60:50] + | | | | |--TYPE_ARGUMENT -> TYPE_ARGUMENT [60:51] + | | | | | `--IDENT -> String [60:51] + | | | | |--COMMA -> , [60:57] + | | | | |--TYPE_ARGUMENT -> TYPE_ARGUMENT [60:59] + | | | | | `--IDENT -> RuntimeException [60:59] + | | | | `--GENERIC_END -> > [60:75] + | | | `--GENERIC_END -> > [60:76] + | | `--IDENT -> list [60:78] + | |--RPAREN -> ) [60:82] + | `--SLIST -> { [60:84] + | |--EXPR -> EXPR [61:19] + | | `--DOT -> . [61:19] + | | |--METHOD_CALL -> ( [61:16] + | | | |--DOT -> . [61:12] + | | | | |--IDENT -> list [61:8] + | | | | `--IDENT -> get [61:13] + | | | |--ELIST -> ELIST [61:17] + | | | | `--EXPR -> EXPR [61:17] + | | | | `--NUM_INT -> 0 [61:17] + | | | `--RPAREN -> ) [61:18] + | | `--STRING_TEMPLATE_BEGIN -> " [61:20] + | | |--STRING_TEMPLATE_CONTENT -> [61:21] + | | `--STRING_TEMPLATE_END -> " [61:21] + | |--SEMI -> ; [61:22] + | |--EXPR -> EXPR [62:19] + | | `--DOT -> . [62:19] + | | |--METHOD_CALL -> ( [62:16] + | | | |--DOT -> . [62:12] + | | | | |--IDENT -> list [62:8] + | | | | `--IDENT -> get [62:13] + | | | |--ELIST -> ELIST [62:17] + | | | | `--EXPR -> EXPR [62:17] + | | | | `--NUM_INT -> 0 [62:17] + | | | `--RPAREN -> ) [62:18] + | | `--STRING_TEMPLATE_BEGIN -> " [62:20] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [62:21] + | | |--EMBEDDED_EXPRESSION_END -> } [62:25] + | | `--STRING_TEMPLATE_END -> " [62:26] + | |--SEMI -> ; [62:27] + | |--EXPR -> EXPR [63:19] + | | `--DOT -> . [63:19] + | | |--METHOD_CALL -> ( [63:16] + | | | |--DOT -> . [63:12] + | | | | |--IDENT -> list [63:8] + | | | | `--IDENT -> get [63:13] + | | | |--ELIST -> ELIST [63:17] + | | | | `--EXPR -> EXPR [63:17] + | | | | `--NUM_INT -> 0 [63:17] + | | | `--RPAREN -> ) [63:18] + | | `--STRING_TEMPLATE_BEGIN -> " [63:21] + | | |--STRING_TEMPLATE_CONTENT -> x [63:22] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [63:23] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [63:26] + | | | `--IDENT -> x [63:26] + | | |--EMBEDDED_EXPRESSION_END -> } [63:28] + | | |--STRING_TEMPLATE_CONTENT -> x [63:29] + | | `--STRING_TEMPLATE_END -> " [63:30] + | |--SEMI -> ; [63:31] + | |--EXPR -> EXPR [64:19] + | | `--DOT -> . [64:19] + | | |--METHOD_CALL -> ( [64:16] + | | | |--DOT -> . [64:12] + | | | | |--SINGLE_LINE_COMMENT -> // [63:33] + | | | | | `--COMMENT_CONTENT -> comments in here\n [63:35] + | | | | |--IDENT -> list [64:8] + | | | | `--IDENT -> get [64:13] + | | | |--ELIST -> ELIST [64:17] + | | | | `--EXPR -> EXPR [64:17] + | | | | `--NUM_INT -> 0 [64:17] + | | | `--RPAREN -> ) [64:18] + | | `--STRING_TEMPLATE_BEGIN -> " [64:21] + | | |--STRING_TEMPLATE_CONTENT -> . [64:22] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:23] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:26] + | | | `--IDENT -> x [64:26] + | | |--EMBEDDED_EXPRESSION_END -> } [64:28] + | | |--STRING_TEMPLATE_CONTENT -> . [64:29] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:30] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:33] + | | | `--IDENT -> y [64:33] + | | |--EMBEDDED_EXPRESSION_END -> } [64:35] + | | |--STRING_TEMPLATE_CONTENT -> . [64:36] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:37] + | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [64:40] + | | | `--IDENT -> x [64:40] + | | |--BLOCK_COMMENT_BEGIN -> /* [64:42] + | | | |--COMMENT_CONTENT -> comments in here, as well [64:44] + | | | `--BLOCK_COMMENT_END -> */ [64:68] + | | |--EMBEDDED_EXPRESSION_END -> } [64:72] + | | |--STRING_TEMPLATE_CONTENT -> . [64:73] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:74] + | | |--EMBEDDED_EXPRESSION_END -> } [64:76] + | | |--STRING_TEMPLATE_CONTENT -> . [64:77] + | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [64:78] + | | |--EMBEDDED_EXPRESSION_END -> } [64:80] + | | `--STRING_TEMPLATE_END -> " [64:81] + | |--SEMI -> ; [64:82] + | `--RCURLY -> } [65:4] + `--RCURLY -> } [66:0] diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateNested.txt b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateNested.txt index d459f1e28a0..e3b4ed36a19 100644 --- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateNested.txt +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/ExpectedStringTemplateNested.txt @@ -77,63 +77,124 @@ COMPILATION_UNIT -> COMPILATION_UNIT [2:0] | | | | | | | | |--RPAREN -> ) [10:36] | | | | | | | | `--SLIST -> { [10:41] | | | | | | | | |--LITERAL_RETURN -> return [11:20] - | | | | | | | | | |--EXPR -> EXPR [11:48] - | | | | | | | | | | `--PLUS -> + [11:48] - | | | | | | | | | | |--PLUS -> + [11:42] + | | | | | | | | | |--EXPR -> EXPR [17:38] + | | | | | | | | | | `--PLUS -> + [17:38] + | | | | | | | | | | |--PLUS -> + [17:32] | | | | | | | | | | | |--DOT -> . [11:30] | | | | | | | | | | | | |--IDENT -> STR [11:27] | | | | | | | | | | | | `--STRING_TEMPLATE_BEGIN -> " [11:31] | | | | | | | | | | | | |--STRING_TEMPLATE_CONTENT -> x [11:32] | | | | | | | | | | | | |--EMBEDDED_EXPRESSION_BEGIN -> \{ [11:33] - | | | | | | | | | | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [11:36] - | | | | | | | | | | | | | `--IDENT -> x [11:36] - | | | | | | | | | | | | |--EMBEDDED_EXPRESSION_END -> } [11:38] - | | | | | | | | | | | | |--STRING_TEMPLATE_CONTENT -> x [11:39] - | | | | | | | | | | | | `--STRING_TEMPLATE_END -> " [11:40] - | | | | | | | | | | | `--STRING_LITERAL -> "{" [11:44] - | | | | | | | | | | `--STRING_LITERAL -> "}}}" [11:50] - | | | | | | | | | `--SEMI -> ; [11:55] - | | | | | | | | `--RCURLY -> } [12:16] - | | | | | | | `--RPAREN -> ) [12:17] - | | | | | | |--EMBEDDED_EXPRESSION_END -> } [12:19] - | | | | | | |--STRING_TEMPLATE_CONTENT -> x [12:20] - | | | | | | `--STRING_TEMPLATE_END -> " [12:21] - | | | | | `--SEMI -> ; [12:22] - | | | | `--RCURLY -> } [13:12] - | | | `--RPAREN -> ) [13:13] - | | |--EMBEDDED_EXPRESSION_END -> } [13:14] - | | |--STRING_TEMPLATE_CONTENT -> x [13:15] - | | `--STRING_TEMPLATE_END -> " [13:16] - | `--SEMI -> ; [13:17] - |--METHOD_DEF -> METHOD_DEF [15:4] - | |--MODIFIERS -> MODIFIERS [15:4] - | | |--LITERAL_PRIVATE -> private [15:4] - | | `--LITERAL_STATIC -> static [15:12] - | |--TYPE -> TYPE [15:19] - | | `--IDENT -> String [15:19] - | |--IDENT -> sp [15:26] - | |--LPAREN -> ( [15:28] - | |--PARAMETERS -> PARAMETERS [15:29] - | | `--PARAMETER_DEF -> PARAMETER_DEF [15:29] - | | |--MODIFIERS -> MODIFIERS [15:29] - | | |--TYPE -> TYPE [15:29] - | | | |--IDENT -> Supplier [15:29] - | | | `--TYPE_ARGUMENTS -> TYPE_ARGUMENTS [15:37] - | | | |--GENERIC_START -> < [15:37] - | | | |--TYPE_ARGUMENT -> TYPE_ARGUMENT [15:38] - | | | | `--IDENT -> String [15:38] - | | | `--GENERIC_END -> > [15:44] - | | `--IDENT -> y [15:46] - | |--RPAREN -> ) [15:47] - | `--SLIST -> { [15:49] - | |--LITERAL_RETURN -> return [16:8] - | | |--EXPR -> EXPR [16:20] - | | | `--METHOD_CALL -> ( [16:20] - | | | |--DOT -> . [16:16] - | | | | |--IDENT -> y [16:15] - | | | | `--IDENT -> get [16:17] - | | | |--ELIST -> ELIST [16:21] - | | | `--RPAREN -> ) [16:21] - | | `--SEMI -> ; [16:22] - | `--RCURLY -> } [17:4] - `--RCURLY -> } [18:0] + | | | | | | | | | | | | |--EMBEDDED_EXPRESSION -> EMBEDDED_EXPRESSION [12:30] + | | | | | | | | | | | | | `--METHOD_CALL -> ( [12:30] + | | | | | | | | | | | | | |--IDENT -> sp [12:28] + | | | | | | | | | | | | | |--ELIST -> ELIST [12:34] + | | | | | | | | | | | | | | `--LAMBDA -> -> [12:34] + | | | | | | | | | | | | | | |--LPAREN -> ( [12:31] + | | | | | | | | | | | | | | |--PARAMETERS -> PARAMETERS [12:32] + | | | | | | | | | | | | | | |--RPAREN -> ) [12:32] + | | | | | | | | | | | | | | `--SLIST -> { [12:37] + | | | | | | | | | | | | | | |--LITERAL_RETURN -> return [13:8] + | | | | | | | | | | | | | | | |--EXPR -> EXPR [13:17] + | | | | | | | | | | | | | | | | `--METHOD_CALL -> ( [13:17] + | | | | | | | | | | | | | | | | |--IDENT -> sp [13:15] + | | | | | | | | | | | | | | | | |--ELIST -> ELIST [13:21] + | | | | | | | | | | | | | | | | | `--LAMBDA -> -> [13:21] + | | | | | | | | | | | | | | | | | |--LPAREN -> ( [13:18] + | | | | | | | | | | | | | | | | | |--PARAMETERS -> PARAMETERS [13:19] + | | | | | | | | | | | | | | | | | |--RPAREN -> ) [13:19] + | | | | | | | | | | | | | | | | | `--SLIST -> { [13:24] + | | | | | | | | | | | | | | | | | |--LITERAL_RETURN -> return [14:12] + | | | | | | | | | | | | | | | | | | |--EXPR -> EXPR [14:21] + | | | | | | | | | | | | | | | | | | | `--METHOD_CALL -> ( [14:21] + | | | | | | | | | | | | | | | | | | | |--IDENT -> sp [14:19] + | | | | | | | | | | | | | | | | | | | |--ELIST -> ELIST [14:25] + | | | | | | | | | | | | | | | | | | | | `--LAMBDA -> -> [14:25] + | | | | | | | | | | | | | | | | | | | | |--LPAREN -> ( [14:22] + | | | | | | | | | | | | | | | | | | | | |--PARAMETERS -> PARAMETERS [14:23] + | | | | | | | | | | | | | | | | | | | | |--RPAREN -> ) [14:23] + | | | | | | | | | | | | | | | | | | | | `--SLIST -> { [14:28] + | | | | | | | | | | | | | | | | | | | | |--LITERAL_RETURN -> return [15:16] + | | | | | | | | | | | | | | | | | | | | | |--EXPR -> EXPR [15:25] + | | | | | | | | | | | | | | | | | | | | | | `--METHOD_CALL -> ( [15:25] + | | | | | | | | | | | | | | | | | | | | | | |--IDENT -> sp [15:23] + | | | | | | | | | | | | | | | | | | | | | | |--ELIST -> ELIST [15:29] + | | | | | | | | | | | | | | | | | | | | | | | `--LAMBDA -> -> [15:29] + | | | | | | | | | | | | | | | | | | | | | | | |--LPAREN -> ( [15:26] + | | | | | | | | | | | | | | | | | | | | | | | |--PARAMETERS -> PARAMETERS [15:27] + | | | | | | | | | | | | | | | | | | | | | | | |--RPAREN -> ) [15:27] + | | | | | | | | | | | | | | | | | | | | | | | `--SLIST -> { [15:32] + | | | | | | | | | | | | | | | | | | | | | | | |--LITERAL_RETURN -> return [16:20] + | | | | | | | | | | | | | | | | | | | | | | | | |--EXPR -> EXPR [16:29] + | | | | | | | | | | | | | | | | | | | | | | | | | `--METHOD_CALL -> ( [16:29] + | | | | | | | | | | | | | | | | | | | | | | | | | |--IDENT -> sp [16:27] + | | | | | | | | | | | | | | | | | | | | | | | | | |--ELIST -> ELIST [16:33] + | | | | | | | | | | | | | | | | | | | | | | | | | | `--LAMBDA -> -> [16:33] + | | | | | | | | | | | | | | | | | | | | | | | | | | |--LPAREN -> ( [16:30] + | | | | | | | | | | | | | | | | | | | | | | | | | | |--PARAMETERS -> PARAMETERS [16:31] + | | | | | | | | | | | | | | | | | | | | | | | | | | |--RPAREN -> ) [16:31] + | | | | | | | | | | | | | | | | | | | | | | | | | | `--EXPR -> EXPR [16:36] + | | | | | | | | | | | | | | | | | | | | | | | | | | `--STRING_LITERAL -> "" [16:36] + | | | | | | | | | | | | | | | | | | | | | | | | | `--RPAREN -> ) [16:38] + | | | | | | | | | | | | | | | | | | | | | | | | `--SEMI -> ; [16:39] + | | | | | | | | | | | | | | | | | | | | | | | `--RCURLY -> } [16:40] + | | | | | | | | | | | | | | | | | | | | | | `--RPAREN -> ) [16:41] + | | | | | | | | | | | | | | | | | | | | | `--SEMI -> ; [16:42] + | | | | | | | | | | | | | | | | | | | | `--RCURLY -> } [16:43] + | | | | | | | | | | | | | | | | | | | `--RPAREN -> ) [16:44] + | | | | | | | | | | | | | | | | | | `--SEMI -> ; [16:45] + | | | | | | | | | | | | | | | | | `--RCURLY -> } [16:46] + | | | | | | | | | | | | | | | | `--RPAREN -> ) [16:47] + | | | | | | | | | | | | | | | `--SEMI -> ; [16:48] + | | | | | | | | | | | | | | `--RCURLY -> } [16:49] + | | | | | | | | | | | | | `--RPAREN -> ) [16:50] + | | | | | | | | | | | | |--EMBEDDED_EXPRESSION_END -> } [17:28] + | | | | | | | | | | | | |--STRING_TEMPLATE_CONTENT -> x [17:29] + | | | | | | | | | | | | `--STRING_TEMPLATE_END -> " [17:30] + | | | | | | | | | | | `--STRING_LITERAL -> "{" [17:34] + | | | | | | | | | | `--STRING_LITERAL -> "}}}" [17:40] + | | | | | | | | | `--SEMI -> ; [17:45] + | | | | | | | | `--RCURLY -> } [18:16] + | | | | | | | `--RPAREN -> ) [18:17] + | | | | | | |--EMBEDDED_EXPRESSION_END -> } [18:19] + | | | | | | |--STRING_TEMPLATE_CONTENT -> x [18:20] + | | | | | | `--STRING_TEMPLATE_END -> " [18:21] + | | | | | `--SEMI -> ; [18:22] + | | | | `--RCURLY -> } [19:12] + | | | `--RPAREN -> ) [19:13] + | | |--EMBEDDED_EXPRESSION_END -> } [19:14] + | | |--STRING_TEMPLATE_CONTENT -> x [19:15] + | | `--STRING_TEMPLATE_END -> " [19:16] + | `--SEMI -> ; [19:17] + |--METHOD_DEF -> METHOD_DEF [21:4] + | |--MODIFIERS -> MODIFIERS [21:4] + | | |--LITERAL_PRIVATE -> private [21:4] + | | `--LITERAL_STATIC -> static [21:12] + | |--TYPE -> TYPE [21:19] + | | `--IDENT -> String [21:19] + | |--IDENT -> sp [21:26] + | |--LPAREN -> ( [21:28] + | |--PARAMETERS -> PARAMETERS [21:29] + | | `--PARAMETER_DEF -> PARAMETER_DEF [21:29] + | | |--MODIFIERS -> MODIFIERS [21:29] + | | |--TYPE -> TYPE [21:29] + | | | |--IDENT -> Supplier [21:29] + | | | `--TYPE_ARGUMENTS -> TYPE_ARGUMENTS [21:37] + | | | |--GENERIC_START -> < [21:37] + | | | |--TYPE_ARGUMENT -> TYPE_ARGUMENT [21:38] + | | | | `--IDENT -> String [21:38] + | | | `--GENERIC_END -> > [21:44] + | | `--IDENT -> y [21:46] + | |--RPAREN -> ) [21:47] + | `--SLIST -> { [21:49] + | |--LITERAL_RETURN -> return [22:8] + | | |--EXPR -> EXPR [22:20] + | | | `--METHOD_CALL -> ( [22:20] + | | | |--DOT -> . [22:16] + | | | | |--IDENT -> y [22:15] + | | | | `--IDENT -> get [22:17] + | | | |--ELIST -> ELIST [22:21] + | | | `--RPAREN -> ) [22:21] + | | `--SEMI -> ; [22:22] + | `--RCURLY -> } [23:4] + `--RCURLY -> } [24:0] diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateMultiLineWithComments.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateMultiLineWithComments.java new file mode 100644 index 00000000000..84f80e2b8e6 --- /dev/null +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateMultiLineWithComments.java @@ -0,0 +1,66 @@ +//non-compiled with javac: Compilable with Java21 +package com.puppycrawl.tools.checkstyle.grammar.java21; + +import java.util.List; + +public class InputStringTemplateMultiLineWithComments { + int x = 10; + int y = 20; + + // most basic example, empty string template expression + String result1 = STR.""; + + String result1_1 = STR."Hello world!"; + + // no content, no expression + String result1_2 = STR."\{ }"; + + // simple single value interpolation + String result2 = STR. "x\{ x }x"; // comment + + // simple single value interpolation with a method call + String result3 = STR. "\{ y(y("y")) }"; + + // bit more complex example, multiple interpolations + String result4 = STR. "\{ x }" + STR. "\{ y }"; + + // bit more complex example, multiple interpolations with method calls + String result5 = STR. "\{ y(y("y")) }" + STR. "\{ y(y("y"/*yep, comment here, too*/)) }"; + + // string template concatenation + String result6 = STR. "\{ x }" + /*comment here*/ STR. "\{ y }"; + + // concatentation in embedded expression + String result7 = STR. "\{ x + y /*comment here too*/ }"; + + // concatentation in embedded expression with method calls + String result8 = STR./*comment here*/ "hey \{ y(y("y")) + y(y("y")) } there"; + + // multiple lines + String result9 = STR. "hey \{ // comment here + y(y("y")) + y(y("y")) + } there"; + + // multiple lines with many expressions and comments + String result10 = STR. "hey \{ /*****comment here*/ // comment here + y(y("y")) + y(y("y")) /* comment here */ + } there \{ /**/ // comment here + y(y("y")) + y(y("y")) // comment there + + STR."x\{ x }x" // comment everywhere + }"; + + String name = "world"; + String s = STR."Hello, \{ name }!"; + + private static String y(String y) { + return "y"; + } + + // Verify proper behavior of TransType w.r.t. templated Strings + void x(List> list) { + list.get(0).""; + list.get(0)."\{ }"; + list.get(0). "x\{ x }x"; // comments in here + list.get(0). ".\{ x }.\{ y }.\{ x /*comments in here, as well*/ }.\{}.\{}"; + } +} diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateNested.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateNested.java index 7a1bffb8e6d..1fca229fe27 100644 --- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateNested.java +++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/grammar/java21/InputStringTemplateNested.java @@ -8,7 +8,13 @@ public class InputStringTemplateNested { final String s = STR."x\{ sp(() -> { return STR."x\{ sp(() -> { - return STR."x\{ x }x" + "{" + "}}}"; + return STR."x\{ + sp(() -> { + return sp(() -> { + return sp(() -> { + return sp(() -> { + return sp(() -> "");});});});}) + }x" + "{" + "}}}"; }) }x"; })}x";