You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2026/09/12 08:21:26 UTC
(groovy) 01/01: GROOVY-12401: Improve remaining parser diagnostics and authored AST source positions
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch GROOVY-12401
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 0d31ea81fd8049e62fa7445f64800d1e245c70bd
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Sep 12 17:08:09 2026 +0900
GROOVY-12401: Improve remaining parser diagnostics and authored AST source positions
---
ARCHITECTURE.md | 22 +-
.../apache/groovy/parser/antlr4/AstBuilder.java | 124 ++++-
.../groovy/parser/antlr4/ModifierManager.java | 7 +-
.../internal/AbstractFriendlyErrorStrategy.java | 500 ++++++++++++++++++++-
.../parser/antlr4/internal/package-info.java | 11 +-
.../parser/antlr4/util/PositionConfigureUtils.java | 47 +-
.../java/org/codehaus/groovy/syntax/Numbers.java | 4 +-
src/test/groovy/bugs/Groovy4252Bug.groovy | 9 +-
src/test/groovy/bugs/Groovy8046.groovy | 6 +-
src/test/groovy/bugs/Groovy8446.groovy | 2 +-
src/test/groovy/bugs/Groovy9141.groovy | 4 +-
.../groovy/gls/generics/GenericsUsageTest.groovy | 22 +-
.../groovy/groovy/MethodInBadPositionTest.groovy | 4 +-
.../parser/antlr4/ParserNegativeSyntaxTest.groovy | 235 ++++++----
.../parser/antlr4/ParserPositiveSyntaxTest.groovy | 466 ++++++++++++++-----
.../antlr4/PositionConfigureUtilsTest.groovy | 182 +++++++-
.../apache/groovy/parser/antlr4/TestUtils.groovy | 2 +-
.../groovy/parser/antlr4/util/AstXmlDumper.groovy | 18 +
.../classgen/Jep361SwitchExpressionTest.groovy | 2 +-
.../parser/antlr4/internal/ErrorStrategyTest.java | 381 +++++++++++++++-
20 files changed, 1780 insertions(+), 268 deletions(-)
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 896f1d7f3b..c658e5b9e0 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -116,7 +116,14 @@ verbatim keeps the reference precise; paraphrasing tends to drift.
`AbstractFriendlyErrorStrategy`). `MissingDelimiterDiagnostic` may
relocate the caret for an unclosed `)` / `]` / `}` (Groovy 4 `?[` is
the same opener family as `[`); reserved keywords, a leading `?[`
- that has no path to attach to, and sole-expected punctuation only
+ that has no path to attach to, array-creation mistakes (`new T[]`,
+ `new T[][n]`, `new T[n] {…}`), an unclosed type argument, a method
+ header in a statement position, an unmatched `do` when `while` is
+ expected (a later `while` names a multi-statement body that needs
+ `{ }` rather than a missing keyword), enum constants that need `;`
+ before members, a misplaced
+ `import`, annotation-style `default` after an interface method header,
+ named unexpected closers/semicolons, and sole-expected punctuation only
refine the fallback sentence.
Locate/refine stay in a defensive try; listener dispatch is a single
call afterwards. Lexer unexpected-character / GString-dollar display
@@ -150,6 +157,19 @@ verbatim keeps the reference precise; paraphrasing tends to drift.
obtained from `ClassHelper`, not constructed directly. Constructing
fresh `ClassNode`s for `int`, `String`, `Object`, etc. is a frequent
source of equality and resolution bugs.
+- Authored AST nodes carry source positions (`lineNumber` /
+ `columnNumber` / `lastLineNumber` / `lastColumnNumber`; 1-based,
+ exclusive end column). Stamp them through
+ `PositionConfigureUtils` — do not copy an unpositioned node's end
+ onto an authored parent (`DefaultGroovyMethods.asBoolean(Object)` is
+ non-null, so a synthetic `ConstantExpression` would otherwise wipe
+ `lastLineNumber`). `-1`
+ is reserved for synthetic or generated nodes: `ModuleNode`, a
+ script's wrapping `BlockStatement`, the implicit `return null`
+ singleton, `EmptyExpression.INSTANCE` / `EmptyStatement.INSTANCE`,
+ TWR desugaring (`__$$tN`), `@Trait`, and `<clinit>`. Tooling tells
+ authored from generated by `lineNumber > 0`
+ (`SecureASTCustomizer.isFromSource`).
- Visitors: `GroovyCodeVisitor` (expression + statement),
`GroovyClassVisitor` (class members), with `ClassCodeVisitorSupport`
/ `CodeVisitorSupport` as bases, and
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 8363a81ef0..503080d954 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -624,6 +624,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
ExpressionContext expressionCtx = ctx.expression();
closureListExpression.addExpression(expressionCtx != null ? (Expression) this.visit(expressionCtx) : EmptyExpression.INSTANCE);
closureListExpression.addExpression(this.visitForUpdate(ctx.forUpdate()));
+ // for-control span, including `;;`; empty init/cond/update slots stay at -1
+ configureAST(closureListExpression, ctx);
return (body) -> new ForStatement(closureListExpression, body);
}
@@ -850,11 +852,21 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
int defaultStatementListSize = defaultStatementList.size();
if (defaultStatementListSize > 1) {
- throw createParsingFailedException("a switch must only have one default branch", defaultStatementList.get(0));
+ Statement duplicate = defaultStatementList.get(1);
+ Token keyword = duplicate.getNodeMetaData(SWITCH_DEFAULT_KEYWORD);
+ if (keyword != null) {
+ throw createParsingFailedException("A switch can have only one default branch", keyword);
+ }
+ throw createParsingFailedException("A switch can have only one default branch", duplicate);
}
if (defaultStatementListSize > 0 && last(statementList) instanceof CaseStatement) {
- throw createParsingFailedException("a default branch must only appear as the last branch of a switch", defaultStatementList.get(0));
+ Statement deflt = defaultStatementList.get(0);
+ Token keyword = deflt.getNodeMetaData(SWITCH_DEFAULT_KEYWORD);
+ if (keyword != null) {
+ throw createParsingFailedException("A default branch must appear as the last branch of a switch", keyword);
+ }
+ throw createParsingFailedException("A default branch must appear as the last branch of a switch", deflt);
}
return configureAST(
@@ -895,6 +907,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
case DEFAULT:
statement = this.visitBlockStatements(ctx.blockStatements());
statement.putNodeMetaData(IS_SWITCH_DEFAULT, Boolean.TRUE);
+ statement.putNodeMetaData(SWITCH_DEFAULT_KEYWORD, tuple.getV1());
statementList.add(statement);
break;
}
@@ -1110,7 +1123,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
return block;
}
if (statements.size() > 1) {
- throw createParsingFailedException("Expect only 1 statement, but " + statements.size() + " statements found", ctx.blockStatements());
+ throw createParsingFailedException("Arrow switch cases must contain a single statement, but " + statements.size() + " were found", ctx.blockStatements());
}
Statement body = unwrapSingletonBlock(statements.get(0));
@@ -1396,7 +1409,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
boolean hasRecordHeader = asBoolean(ctx.formalParameters());
if (isRecord) {
if (!hasRecordHeader) {
- throw createParsingFailedException("header declaration of record is expected", ctx.identifier());
+ throw createParsingFailedException("Record '" + className + "' is missing a header, for example: record " + className + "(...)", ctx.identifier());
}
if (asBoolean(ctx.EXTENDS())) {
throw createParsingFailedException("No extends clause allowed for record declaration", ctx.EXTENDS());
@@ -1409,7 +1422,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
} else {
if (hasRecordHeader) {
- throw createParsingFailedException("header declaration is only allowed for record declaration", ctx.formalParameters());
+ throw createParsingFailedException("Only records can have a compact header, for example: record " + className + "(...)", ctx.formalParameters());
}
}
@@ -1865,7 +1878,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
ClassNode classNode = ctx.getNodeMetaData(CLASS_DECLARATION_CLASS_NODE);
if (classNode.getAnnotations().stream().noneMatch(a -> a.getClassNode().getName().equals(RECORD_TYPE_NAME))) {
- throw createParsingFailedException("Only record can have compact constructor", ctx);
+ throw createParsingFailedException("Compact constructors are only allowed in records", ctx);
}
if (new ModifierManager(this, ctx.getNodeMetaData(COMPACT_CONSTRUCTOR_DECLARATION_MODIFIERS)).containsAny(VAL, VAR)) {
@@ -1971,7 +1984,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (2 == ctx.t) {
if (asBoolean(ctx.methodBody())) {
- throw createParsingFailedException("Abstract method should not have method body", ctx);
+ throw createParsingFailedException("Abstract method cannot have a body", ctx);
}
}
@@ -1982,28 +1995,28 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (9 == ctx.ct) { // script
if (isAbstractMethod || !hasMethodBody) { // method should not be declared abstract in the script
- throw createParsingFailedException("You cannot define " + (isAbstractMethod ? "an abstract" : "a") + " method[" + methodNode.getName() + "] " + (!hasMethodBody ? "without method body " : "") + "in the script. Try " + (isAbstractMethod ? "removing the 'abstract'" : "") + (isAbstractMethod && !hasMethodBody ? " and" : "") + (!hasMethodBody ? " adding a method body" : ""), methodNode);
+ throw createParsingFailedException(scriptMethodError(methodNode, isAbstractMethod, hasMethodBody), methodNode);
}
} else {
if (4 == ctx.ct) { // trait
if (isAbstractMethod && hasMethodBody) {
- throw createParsingFailedException("Abstract method should not have method body", ctx);
+ throw createParsingFailedException("Abstract method cannot have a body", ctx);
}
}
if (3 == ctx.ct) { // annotation
if (hasMethodBody) {
- throw createParsingFailedException("Annotation type element should not have body", ctx);
+ throw createParsingFailedException("Annotation type elements cannot have a body", ctx);
}
}
if (!isAbstractMethod && !hasMethodBody) { // non-abstract method without body in the non-script(e.g. class, enum, trait) is not allowed!
- throw createParsingFailedException("You defined a method[" + methodNode.getName() + "] without a body. Try adding a method body, or declare it abstract", methodNode);
+ throw createParsingFailedException("Method '" + methodNode.getName() + "' is missing a body. Add a method body, or declare it abstract", methodNode);
}
boolean isInterfaceOrAbstractClass = asBoolean(classNode) && classNode.isAbstract() && !classNode.isAnnotationDefinition();
if (isInterfaceOrAbstractClass && !modifierManager.containsAny(DEFAULT, PRIVATE) && isAbstractMethod && hasMethodBody) {
- throw createParsingFailedException("You defined an abstract method[" + methodNode.getName() + "] with a body. Try removing the method body" + (classNode.isInterface() ? ", or declare it default or private" : ""), methodNode);
+ throw createParsingFailedException("Abstract method '" + methodNode.getName() + "' cannot have a body. Remove the method body" + (classNode.isInterface() ? ", or declare it default or private" : ""), methodNode);
}
}
@@ -2014,6 +2027,46 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
}
+ /**
+ * {@code new Super() { Super() {} }} — constructor-shaped member of an
+ * anonymous class. {@code new Super() { bar() {} }} is a method, not a
+ * constructor (anonymous {@code CLASS_NAME} is {@code Outer$1}).
+ */
+ private static boolean isAnonymousConstructorDeclaration(final ClassNode classNode, final String methodName) {
+ if (!(classNode instanceof InnerClassNode inner) || !inner.isAnonymous()) {
+ return false;
+ }
+ ClassNode superClass = inner.getUnresolvedSuperClass();
+ if (superClass != null && methodName.equals(superClass.getNameWithoutPackage())) {
+ return true;
+ }
+ ClassNode[] interfaces = inner.getInterfaces();
+ if (interfaces != null) {
+ for (ClassNode iface : interfaces) {
+ if (iface != null && methodName.equals(iface.getNameWithoutPackage())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Scripts cannot declare abstract methods or methods without a body.
+ * Wording follows javac's "missing method body, or declare abstract",
+ * adapted to script scope where {@code abstract} is never legal.
+ */
+ private static String scriptMethodError(final MethodNode methodNode, final boolean isAbstractMethod, final boolean hasMethodBody) {
+ String name = methodNode.getName();
+ if (isAbstractMethod && !hasMethodBody) {
+ return "Scripts cannot declare abstract method '" + name + "'. Remove 'abstract' and add a method body";
+ }
+ if (isAbstractMethod) {
+ return "Scripts cannot declare abstract method '" + name + "'. Remove 'abstract'";
+ }
+ return "Scripts cannot declare method '" + name + "' without a body. Add a method body";
+ }
+
private MethodNode createScriptMethodNode(final ModifierManager modifierManager, final String methodName, final ClassNode returnType, final Parameter[] parameters, final ClassNode[] exceptions, final Statement code) {
MethodNode methodNode = new MethodNode(
methodName,
@@ -2039,6 +2092,9 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
methodNode = createConstructorNodeForClass(methodName, parameters, exceptions, code, classNode, modifiers);
} else {
if (!hasReturnType && hasMethodBody && (0 == modifierManager.getModifierCount())) {
+ if (isAnonymousConstructorDeclaration(classNode, methodName)) {
+ throw createParsingFailedException("Anonymous classes cannot declare constructors", ctx);
+ }
throw createParsingFailedException("Invalid method declaration: " + methodName, ctx);
}
methodNode = createMethodNodeForClass(ctx, modifierManager, methodName, returnType, parameters, exceptions, code, classNode, modifiers);
@@ -2055,7 +2111,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
Expression defaultValue = this.visitElementValue(elementValue);
if (returnType.isArray() && defaultValue instanceof ClosureExpression closure // GROOVY-11492
&& ClosureUtils.hasImplicitParameter(closure) && closure.getCode() instanceof BlockStatement block) {
- defaultValue = listX(block.getStatements().stream().map(s -> ((ExpressionStatement) s).getExpression()).toList());
+ // listX is unpositioned; copy the authored `{ }` / `{ "foo" }` span
+ defaultValue = configureAST(listX(block.getStatements().stream().map(s -> ((ExpressionStatement) s).getExpression()).toList()), closure);
}
code = configureAST(stmt(defaultValue), elementValue);
}
@@ -2108,7 +2165,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (asBoolean(ctx.VOID())) {
if (ctx.ct == 3) { // annotation
- throw createParsingFailedException("annotation method cannot have void return type", ctx);
+ throw createParsingFailedException("Annotation type elements cannot have a void return type", ctx);
}
return configureAST(ClassHelper.VOID_TYPE.getPlainNodeReference(false), ctx.VOID());
@@ -2494,7 +2551,15 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
if ((hasArgumentList || hasCommandArgument) && !isInsideParentheses(baseExpr)
- && baseExpr instanceof BinaryExpression && !"[".equals(((BinaryExpression) baseExpr).getOperation().getText())) {
+ && baseExpr instanceof BinaryExpression bin
+ && !"[".equals(bin.getOperation().getText())) {
+ // `List<Integer name` is parsed as the comparison `List < Integer` plus a
+ // command argument. javac: `'>' expected`.
+ if ("<".equals(bin.getOperation().getText())
+ && looksLikeTypeName(bin.getLeftExpression())
+ && looksLikeTypeName(bin.getRightExpression())) {
+ throw createParsingFailedException("Missing '>'", bin);
+ }
throw createParsingFailedException("Unexpected input: '" + getOriginalText(ctx.expression()) + "'", ctx.expression());
}
@@ -3120,9 +3185,12 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
throw createParsingFailedException("Expression expected", ctx.COMMA());
}
- if (!asBoolean(ctx) || !asBoolean(ctx.enhancedArgumentListInPar())) {
+ if (!asBoolean(ctx)) {
return new ArgumentListExpression();
}
+ if (!asBoolean(ctx.enhancedArgumentListInPar())) {
+ return configureAST(new ArgumentListExpression(), ctx); // authored `()`
+ }
return configureAST(this.visitEnhancedArgumentListInPar(ctx.enhancedArgumentListInPar()), ctx);
}
@@ -3259,7 +3327,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
ListExpression listExpression = new ListExpression(expressionList);
listExpression.setWrapped(false);
- indexExpr = listExpression;
+ indexExpr = configureAST(listExpression, ctx);
} else { // e.g. a[1]
indexExpr = expr;
}
@@ -3832,7 +3900,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
) {
- throw createParsingFailedException("The LHS of an assignment should be a variable or a field accessing expression", ctx);
+ throw createParsingFailedException("The left-hand side of an assignment must be a variable or a field", ctx);
}
return configureAST(
@@ -4211,7 +4279,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
// statements like `foo(String a)` is invalid
String methodName = methodCallExpression.getMethodAsString();
if (methodCallExpression.isImplicitThis() && Character.isUpperCase(methodName.codePointAt(0)) || isPrimitiveType(methodName)) {
- throw createParsingFailedException("Invalid method declaration", ctx);
+ throw createParsingFailedException("Invalid method declaration; a return type or 'def' is required", ctx);
}
}
}
@@ -4634,7 +4702,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
if (asBoolean(ctx.VOID())) {
- throw this.createParsingFailedException("void is not allowed here", ctx);
+ throw this.createParsingFailedException("'void' type is not allowed here", ctx);
}
ClassNode classNode;
@@ -5316,6 +5384,21 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
return (expression instanceof VariableExpression && isTrue(expression, IS_BUILT_IN_TYPE));
}
+ /**
+ * Capitalized name or class literal — the left-hand side of {@code T < U}
+ * when {@code T<U name} was meant as a type argument list.
+ */
+ private static boolean looksLikeTypeName(final Expression expression) {
+ if (expression instanceof ClassExpression) {
+ return true;
+ }
+ if (expression instanceof VariableExpression ve) {
+ String name = ve.getName();
+ return name != null && !name.isEmpty() && Character.isUpperCase(name.codePointAt(0));
+ }
+ return false;
+ }
+
private org.codehaus.groovy.syntax.Token createGroovyTokenByType(final Token token, final int type) {
if (token == null) {
throw new IllegalArgumentException("token should not be null");
@@ -5585,6 +5668,7 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
private static final String IS_INSIDE_INSTANCEOF_EXPR = "_IS_INSIDE_INSTANCEOF_EXPR";
private static final String NON_REIFIABLE_INSTANCEOF = "_NON_REIFIABLE_INSTANCEOF";
private static final String IS_SWITCH_DEFAULT = "_IS_SWITCH_DEFAULT";
+ private static final String SWITCH_DEFAULT_KEYWORD = "_SWITCH_DEFAULT_KEYWORD";
private static final String IS_NUMERIC = "_IS_NUMERIC";
private static final String IS_STRING = "_IS_STRING";
private static final String IS_INTERFACE_WITH_DEFAULT_METHODS = "_IS_INTERFACE_WITH_DEFAULT_METHODS";
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java b/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
index 4d86449b8d..4c9dc91cc3 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/ModifierManager.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -72,13 +73,13 @@ class ModifierManager {
if (count == null) {
modifierNodeCounter.put(modifierNode, 1);
} else if (count == 1 && !modifierNode.isRepeatable()) {
- throw astBuilder.createParsingFailedException("Cannot repeat modifier[" + modifierNode.getText() + "]", modifierNode);
+ throw astBuilder.createParsingFailedException("Cannot repeat modifier '" + modifierNode.getText() + "'", modifierNode);
}
if (modifierNode.isVisibilityModifier()) {
visibilityModifierCount += 1;
if (visibilityModifierCount > 1) {
- throw astBuilder.createParsingFailedException("Cannot specify modifier[" + modifierNode.getText() + "] when access scope has already been defined", modifierNode);
+ throw astBuilder.createParsingFailedException("Cannot specify modifier '" + modifierNode.getText() + "' when the access scope has already been defined", modifierNode);
}
}
}
@@ -95,7 +96,7 @@ class ModifierManager {
private void validate(List<Integer> invalidModifierList, MethodNode methodNode) {
modifierNodeList.forEach(e -> {
if (invalidModifierList.contains(e.getType())) {
- throw astBuilder.createParsingFailedException(methodNode.getClass().getSimpleName().replace("Node", "") + " has an incorrect modifier '" + e + "'.", methodNode);
+ throw astBuilder.createParsingFailedException("Modifier '" + e + "' is not allowed on a " + methodNode.getClass().getSimpleName().replace("Node", "").toLowerCase(Locale.ROOT), methodNode);
}
});
}
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/internal/AbstractFriendlyErrorStrategy.java b/src/main/java/org/apache/groovy/parser/antlr4/internal/AbstractFriendlyErrorStrategy.java
index 66ccbae8a1..9b0bf127c6 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/internal/AbstractFriendlyErrorStrategy.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/internal/AbstractFriendlyErrorStrategy.java
@@ -32,32 +32,48 @@ import org.antlr.v4.runtime.misc.IntervalSet;
import java.util.Objects;
+import static org.apache.groovy.parser.antlr4.GroovyParser.ABSTRACT;
import static org.apache.groovy.parser.antlr4.GroovyParser.ARROW;
+import static org.apache.groovy.parser.antlr4.GroovyParser.ASSIGN;
import static org.apache.groovy.parser.antlr4.GroovyParser.AT;
import static org.apache.groovy.parser.antlr4.GroovyParser.BooleanLiteral;
import static org.apache.groovy.parser.antlr4.GroovyParser.BuiltInPrimitiveType;
import static org.apache.groovy.parser.antlr4.GroovyParser.CASE;
import static org.apache.groovy.parser.antlr4.GroovyParser.CATCH;
import static org.apache.groovy.parser.antlr4.GroovyParser.COLON;
+import static org.apache.groovy.parser.antlr4.GroovyParser.COMMA;
import static org.apache.groovy.parser.antlr4.GroovyParser.CONST;
import static org.apache.groovy.parser.antlr4.GroovyParser.CapitalizedIdentifier;
import static org.apache.groovy.parser.antlr4.GroovyParser.DEFAULT;
+import static org.apache.groovy.parser.antlr4.GroovyParser.DEF;
import static org.apache.groovy.parser.antlr4.GroovyParser.DOT;
+import static org.apache.groovy.parser.antlr4.GroovyParser.DO;
import static org.apache.groovy.parser.antlr4.GroovyParser.ELSE;
+import static org.apache.groovy.parser.antlr4.GroovyParser.ENUM;
+import static org.apache.groovy.parser.antlr4.GroovyParser.EXTENDS;
+import static org.apache.groovy.parser.antlr4.GroovyParser.FINAL;
import static org.apache.groovy.parser.antlr4.GroovyParser.FINALLY;
import static org.apache.groovy.parser.antlr4.GroovyParser.FloatingPointLiteral;
import static org.apache.groovy.parser.antlr4.GroovyParser.GOTO;
import static org.apache.groovy.parser.antlr4.GroovyParser.GStringEnd;
import static org.apache.groovy.parser.antlr4.GroovyParser.GT;
+import static org.apache.groovy.parser.antlr4.GroovyParser.IMPORT;
+import static org.apache.groovy.parser.antlr4.GroovyParser.INTERFACE;
import static org.apache.groovy.parser.antlr4.GroovyParser.Identifier;
import static org.apache.groovy.parser.antlr4.GroovyParser.IntegerLiteral;
import static org.apache.groovy.parser.antlr4.GroovyParser.LBRACE;
import static org.apache.groovy.parser.antlr4.GroovyParser.LBRACK;
import static org.apache.groovy.parser.antlr4.GroovyParser.LPAREN;
+import static org.apache.groovy.parser.antlr4.GroovyParser.LT;
import static org.apache.groovy.parser.antlr4.GroovyParser.METHOD_POINTER;
import static org.apache.groovy.parser.antlr4.GroovyParser.METHOD_REFERENCE;
+import static org.apache.groovy.parser.antlr4.GroovyParser.NEW;
import static org.apache.groovy.parser.antlr4.GroovyParser.NL;
import static org.apache.groovy.parser.antlr4.GroovyParser.NullLiteral;
+import static org.apache.groovy.parser.antlr4.GroovyParser.PRIVATE;
+import static org.apache.groovy.parser.antlr4.GroovyParser.PROTECTED;
+import static org.apache.groovy.parser.antlr4.GroovyParser.PUBLIC;
+import static org.apache.groovy.parser.antlr4.GroovyParser.QUESTION;
import static org.apache.groovy.parser.antlr4.GroovyParser.RBRACE;
import static org.apache.groovy.parser.antlr4.GroovyParser.RBRACK;
import static org.apache.groovy.parser.antlr4.GroovyParser.RPAREN;
@@ -66,6 +82,7 @@ import static org.apache.groovy.parser.antlr4.GroovyParser.SAFE_DOT;
import static org.apache.groovy.parser.antlr4.GroovyParser.SAFE_INDEX;
import static org.apache.groovy.parser.antlr4.GroovyParser.SEMI;
import static org.apache.groovy.parser.antlr4.GroovyParser.SPREAD_DOT;
+import static org.apache.groovy.parser.antlr4.GroovyParser.STATIC;
import static org.apache.groovy.parser.antlr4.GroovyParser.StringLiteral;
import static org.apache.groovy.parser.antlr4.GroovyParser.SUPER;
import static org.apache.groovy.parser.antlr4.GroovyParser.THIS;
@@ -84,10 +101,11 @@ import static org.apache.groovy.parser.antlr4.GroovyParser.WHILE;
* <p>
* Two layers, on purpose: {@link MissingDelimiterDiagnostic} may <em>relocate</em>
* the caret (insertion point after an unclosed {@code ) } / {@code ] } / {@code } }).
- * Keyword / missing-receiver {@code ?[} / sole-expected-punctuation /
- * unexpected-EOF wording only changes the sentence and keeps ANTLR's
- * offending token, so it is a fallback-string refine rather than a second
- * locate pass.
+ * Keyword / missing-receiver {@code ?[} / array-creation / unclosed type
+ * argument / method-in-the-wrong-place / unmatched {@code do} / enum-constant
+ * separator / sole-expected-punctuation / unexpected-EOF wording only changes
+ * the sentence and keeps ANTLR's offending token, so it is a fallback-string
+ * refine rather than a second locate pass.
* </p>
*/
abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
@@ -103,7 +121,8 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
/**
* Prefer a relocated "Missing …" closer when the token stream supports it;
* otherwise refine the generic {@code Unexpected input: ...} fallback
- * (reserved keyword, sole expected punctuation, unexpected EOF).
+ * (reserved keyword, array creation, unclosed type argument, and the
+ * other sentence-only cases in {@link #refineFallbackMessage}).
* Locate/refine run in a defensive try; a single listener dispatch is
* outside so a listener {@link IllegalArgumentException} /
* {@link IndexOutOfBoundsException} is not mistaken for a lookup failure
@@ -131,8 +150,11 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
/**
* Improve a generic mismatch/NVAE sentence without moving the caret.
* Precedence: reserved/misplaced keyword, then a leading {@code ?[}
- * without a path to attach to, then a singleton expected punctuation
- * token, then unexpected EOF, then {@code generic}.
+ * without a path to attach to, then array-creation / unclosed type
+ * argument / method definition in a bad position / unmatched {@code do}
+ * / enum constants needing {@code ;}, then a singleton expected
+ * punctuation token, then unexpected EOF, then a named unexpected
+ * closer or semicolon, then {@code generic}.
*/
static String refineFallbackMessage(final RecognitionException e, final String generic) {
if (e == null) {
@@ -152,6 +174,30 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
if (safeIndex != null) {
return safeIndex;
}
+ String array = arrayCreationMessage(e, offending);
+ if (array != null) {
+ return array;
+ }
+ String typeArg = unmatchedTypeArgument(e, offending);
+ if (typeArg != null) {
+ return typeArg;
+ }
+ String method = methodDefinitionNotExpected(e, offending);
+ if (method != null) {
+ return method;
+ }
+ String doWhile = unmatchedDoWhile(e, offending);
+ if (doWhile != null) {
+ return doWhile;
+ }
+ String enumComma = enumMemberAfterComma(e, offending);
+ if (enumComma != null) {
+ return enumComma;
+ }
+ String defaultAfterHeader = interfaceDefaultAfterHeader(e, offending);
+ if (defaultAfterHeader != null) {
+ return defaultAfterHeader;
+ }
}
String sole = soleExpectedMessage(e);
if (sole != null) {
@@ -160,6 +206,10 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
if (offending != null && offending.getType() == Token.EOF) {
return "Unexpected end of input";
}
+ String punct = unexpectedPunctuation(offending);
+ if (punct != null) {
+ return punct;
+ }
return generic;
}
@@ -176,7 +226,9 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
* annotation-element keyword, so an offending {@code default} (for example
* {@code def m() default {1}}) is not "outside of switch".
* {@code default:} / {@code default ->} outside a switch is recognised
- * via {@link #misplacedDefaultClause}.
+ * via {@link #misplacedDefaultClause}. {@code import} is only legal as a
+ * compilation-unit member; a misplaced {@code import} (inside a method or
+ * closure) is named here rather than dumped as {@code Unexpected input}.
*/
static String keywordMessage(final int tokenType) {
return switch (tokenType) {
@@ -187,6 +239,7 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
case CATCH -> "'catch' without 'try'";
case FINALLY -> "'finally' without 'try'";
case CASE -> "'case' outside of switch";
+ case IMPORT -> "'import' is only allowed at the beginning of a compilation unit";
default -> null;
};
}
@@ -387,6 +440,437 @@ abstract class AbstractFriendlyErrorStrategy extends DefaultErrorStrategy {
};
}
+ /**
+ * javac: {@code array dimension missing}. Groovy's grammar commits to
+ * {@code dim0+ arrayInitializer} after {@code new T[]}, so the sole
+ * expected token at EOF is {@code \{} — {@code Missing '\{'} is the
+ * wrong advice. A sized dim after an empty dim ({@code new T[][n]}) and
+ * combining a size with an initializer ({@code new T[n] \{...\}}) are
+ * the same family.
+ */
+ static String arrayCreationMessage(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ Token[] prefix = defaultChannelPrefix(tokens, offending);
+ int newAt = lastIndexOfType(prefix, NEW);
+ if (newAt < 0) {
+ return null;
+ }
+ int i = newAt + 1;
+ while (i < prefix.length && isCreatedNameToken(prefix[i].getType())) {
+ i++;
+ }
+ if (i >= prefix.length || prefix[i].getType() != LBRACK) {
+ return null;
+ }
+ boolean sawEmpty = false;
+ boolean sawSized = false;
+ while (i < prefix.length && prefix[i].getType() == LBRACK) {
+ i++;
+ if (i < prefix.length && prefix[i].getType() == RBRACK) {
+ sawEmpty = true;
+ i++;
+ continue;
+ }
+ if (sawEmpty) {
+ return "Cannot specify an array size after an empty dimension";
+ }
+ while (i < prefix.length) {
+ int t = prefix[i].getType();
+ if (t == RBRACK) {
+ sawSized = true;
+ i++;
+ break;
+ }
+ if (t == LBRACK || t == LBRACE || t == Token.EOF) {
+ return null;
+ }
+ i++;
+ }
+ if (!sawSized) {
+ return null;
+ }
+ }
+ int leftover = i < prefix.length ? prefix[i].getType() : Token.EOF;
+ if (leftover == Token.EOF && sawEmpty && !sawSized) {
+ return "Array dimension missing; specify a size or add an initializer '{}'";
+ }
+ if (leftover == LBRACE && sawSized) {
+ return "Cannot combine an array size with an array initializer";
+ }
+ return null;
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * {@code List<Integer name} / {@code new ArrayList<Integer(} — an
+ * unmatched {@code <} after a capitalized type name is a missing
+ * {@code >}, not a comparison. {@code x < y z} (lowercase left
+ * operand) is left to the generic sentence.
+ * <p>
+ * ANTLR's offending token for {@code List<Integer name} is often
+ * {@code List} (the NVAE start), so a prefix-up-to-offender scan
+ * never sees the {@code <}. Look ahead from the error start until a
+ * statement boundary — not the rest of the file, or a later unclosed
+ * generic would steal an earlier unrelated diagnostic.
+ * </p>
+ */
+ static String unmatchedTypeArgument(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null || offending.getType() == GT) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ int lo = offending.getTokenIndex();
+ if (e instanceof NoViableAltException nvae && nvae.getStartToken() != null) {
+ int start = nvae.getStartToken().getTokenIndex();
+ if (start >= 0 && (lo < 0 || start < lo)) {
+ lo = start;
+ }
+ }
+ // Include the capitalized type name before '<'; ANTLR's offender is
+ // often the type, the '<', or the following identifier.
+ if (lo > 0) {
+ lo = Math.max(0, lo - 4);
+ } else if (lo < 0) {
+ lo = 0;
+ }
+ int depth = 0;
+ boolean typeOpener = false;
+ Token prev = null;
+ int n = tokens.size();
+ int seen = 0;
+ for (int i = lo; i < n && seen < 24; i++) {
+ Token t = tokens.get(i);
+ if (t.getChannel() != Token.DEFAULT_CHANNEL) {
+ continue;
+ }
+ int type = t.getType();
+ if (type == Token.EOF || type == SEMI || type == ASSIGN
+ || (type == NL && depth == 0 && i > lo)) {
+ if (i > lo) {
+ break;
+ }
+ continue;
+ }
+ seen++;
+ if (type == LT) {
+ // `<<` is two LT tokens (shift), not nested type arguments.
+ if (prev != null && prev.getType() == LT) {
+ prev = t;
+ continue;
+ }
+ if (prev != null && prev.getType() == CapitalizedIdentifier) {
+ depth++;
+ typeOpener = true;
+ } else if (depth > 0) {
+ depth++;
+ }
+ } else if (type == GT && depth > 0) {
+ depth--;
+ }
+ prev = t;
+ }
+ return depth > 0 && typeOpener ? "Missing '>'" : null;
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * {@code \{ -> def say(String msg) \{ } }()} — the unexpected {@code (}
+ * after {@code def ident} is a method header in a position that only
+ * allows statements. Successful parses never enter this method, so
+ * script- and class-level {@code def m()} is unaffected.
+ */
+ static String methodDefinitionNotExpected(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null || offending.getType() != LPAREN) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ Token prev = previousDefaultChannel(tokens, offending.getTokenIndex(), true);
+ if (prev == null || (prev.getType() != Identifier && prev.getType() != CapitalizedIdentifier)) {
+ return null;
+ }
+ Token prev2 = previousDefaultChannel(tokens, prev.getTokenIndex(), true);
+ if (prev2 == null || !isMethodHeaderPrefix(prev2.getType())) {
+ return null;
+ }
+ return "Method definition not expected here";
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * {@code do stmt; stmt; while (...)} — after the {@code do} body the
+ * parser wants {@code while}. The expected set is rarely a singleton
+ * (command expressions continue), so {@link #soleExpectedMessage} stays
+ * silent. javac reports {@code while expected} at the end of the first
+ * statement; that is misleading when {@code while} is already on the next
+ * line (the body was two statements without {@code \{ \}}). If a later
+ * {@code while} is present, name the multi-statement body; otherwise
+ * {@code Missing 'while'} (true omission, javac's wording family).
+ */
+ static String unmatchedDoWhile(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ IntervalSet expected;
+ try {
+ expected = e.getExpectedTokens();
+ } catch (IllegalArgumentException | IndexOutOfBoundsException ignored) {
+ return null;
+ }
+ if (expected == null || !expected.contains(WHILE)) {
+ return null;
+ }
+ Token[] prefix = defaultChannelPrefix(tokens, offending);
+ int lastDo = -1;
+ int lastWhile = -1;
+ int limit = prefix.length;
+ if (limit > 0 && prefix[limit - 1] == offending) {
+ limit--;
+ }
+ for (int i = 0; i < limit; i++) {
+ int type = prefix[i].getType();
+ if (type == DO && !isNamePart(prefix, i)) {
+ lastDo = i;
+ } else if (type == WHILE && !isNamePart(prefix, i)) {
+ lastWhile = i;
+ }
+ }
+ if (lastDo <= lastWhile) {
+ return null;
+ }
+ return whileAppearsAfter(tokens, offending)
+ ? "do-while body must be a single statement; wrap multiple statements in '{ }'"
+ : "Missing 'while'";
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * A {@code while} keyword after the offender — not {@code foo.while}.
+ * Distinguishes a missing closer from a multi-statement {@code do} body
+ * that already has its {@code while} on a later line.
+ */
+ private static boolean whileAppearsAfter(final TokenStream tokens, final Token offending) {
+ int from = offending.getTokenIndex() + 1;
+ if (from < 1) {
+ return false;
+ }
+ Token prevDefault = null;
+ int n = tokens.size();
+ for (int i = from; i < n; i++) {
+ Token t = tokens.get(i);
+ if (t.getChannel() != Token.DEFAULT_CHANNEL) {
+ continue;
+ }
+ if (t.getType() == WHILE) {
+ boolean namePart = prevDefault != null && isMemberSelection(prevDefault.getType());
+ if (!namePart) {
+ return true;
+ }
+ }
+ if (t.getType() == Token.EOF) {
+ return false;
+ }
+ prevDefault = t;
+ }
+ return false;
+ }
+
+ /**
+ * javac: {@code ';' expected} between enum constants and members.
+ * {@code enum E \{ X, Y, def z() \{\} \}} — a comma then a method
+ * header, not another constant.
+ */
+ static String enumMemberAfterComma(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null || !isEnumMemberStart(offending.getType())) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ Token prev = previousDefaultChannel(tokens, offending.getTokenIndex(), true);
+ if (prev == null || prev.getType() != COMMA) {
+ return null;
+ }
+ Token[] prefix = defaultChannelPrefix(tokens, offending);
+ if (!insideEnumConstantList(prefix)) {
+ return null;
+ }
+ return "';' expected after the last enum constant";
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * {@code interface I \{ def m() default \{1\} \}} — annotation-element
+ * {@code default} after a method header. Interface default methods put
+ * {@code default} <em>before</em> the name. {@code @interface} element
+ * defaults parse successfully and never reach this method.
+ */
+ static String interfaceDefaultAfterHeader(final RecognitionException e, final Token offending) {
+ if (e == null || offending == null || offending.getType() != DEFAULT) {
+ return null;
+ }
+ if (!(e.getInputStream() instanceof TokenStream tokens)) {
+ return null;
+ }
+ try {
+ Token prev = previousDefaultChannel(tokens, offending.getTokenIndex(), true);
+ if (prev == null || prev.getType() != RPAREN) {
+ return null;
+ }
+ Token[] prefix = defaultChannelPrefix(tokens, offending);
+ int iface = lastIndexOfType(prefix, INTERFACE);
+ if (iface < 0) {
+ return null;
+ }
+ if (iface > 0 && prefix[iface - 1].getType() == AT) {
+ return null;
+ }
+ return "'default' cannot follow a method header; put 'default' before the method name";
+ } catch (IndexOutOfBoundsException | IllegalArgumentException ignored) {
+ return null;
+ }
+ }
+
+ /**
+ * Name an extra closer or semicolon rather than {@code Unexpected input: ')'}.
+ */
+ static String unexpectedPunctuation(final Token offending) {
+ if (offending == null) {
+ return null;
+ }
+ return switch (offending.getType()) {
+ case RPAREN -> "Unexpected ')'";
+ case RBRACK -> "Unexpected ']'";
+ case RBRACE -> "Unexpected '}'";
+ case SEMI -> "Unexpected ';'";
+ case COMMA -> "Unexpected ','";
+ default -> null;
+ };
+ }
+
+ private static boolean isCreatedNameToken(final int type) {
+ return switch (type) {
+ case AT, Identifier, CapitalizedIdentifier, BuiltInPrimitiveType,
+ DOT, LT, GT, COMMA, QUESTION, EXTENDS, SUPER -> true;
+ default -> false;
+ };
+ }
+
+ private static boolean isMethodHeaderPrefix(final int type) {
+ return switch (type) {
+ case DEF, VOID, BuiltInPrimitiveType,
+ PUBLIC, PRIVATE, PROTECTED, STATIC, FINAL, ABSTRACT -> true;
+ default -> false;
+ };
+ }
+
+ private static boolean isNamePart(final Token[] prefix, final int index) {
+ if (index < 1) {
+ return false;
+ }
+ return isMemberSelection(prefix[index - 1].getType());
+ }
+
+ /**
+ * {@code enum E { X, Y, def z() }} — still in the constant list of an
+ * open enum body (no {@code ;} yet). A closed {@code enum} earlier in
+ * the file must not rewrite {@code [1, def]}.
+ */
+ private static boolean insideEnumConstantList(final Token[] prefix) {
+ int brace = 0;
+ boolean inEnum = false;
+ boolean seenSemi = false;
+ for (Token t : prefix) {
+ int type = t.getType();
+ if (type == ENUM && !inEnum) {
+ inEnum = true;
+ brace = 0;
+ seenSemi = false;
+ } else if (inEnum && type == LBRACE) {
+ brace++;
+ } else if (inEnum && type == RBRACE) {
+ brace--;
+ if (brace <= 0) {
+ inEnum = false;
+ }
+ } else if (inEnum && brace == 1 && type == SEMI) {
+ seenSemi = true;
+ }
+ }
+ return inEnum && brace > 0 && !seenSemi;
+ }
+
+ private static boolean isEnumMemberStart(final int type) {
+ return switch (type) {
+ case DEF, VOID, BuiltInPrimitiveType,
+ PUBLIC, PRIVATE, PROTECTED, STATIC, FINAL, ABSTRACT, DEFAULT -> true;
+ default -> false;
+ };
+ }
+
+ private static int lastIndexOfType(final Token[] prefix, final int type) {
+ for (int i = prefix.length - 1; i >= 0; i--) {
+ if (prefix[i].getType() == type) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Default-channel tokens up to and including {@code offending}, skipping
+ * newlines. Error-path only.
+ */
+ private static Token[] defaultChannelPrefix(final TokenStream tokens, final Token offending) {
+ int end = offending.getTokenIndex();
+ if (end < 0) {
+ end = tokens.size() - 1;
+ }
+ if (end < 0) {
+ return new Token[0];
+ }
+ int n = 0;
+ Token[] buf = new Token[end + 1];
+ for (int i = 0; i <= end; i++) {
+ Token t = tokens.get(i);
+ if (t.getChannel() == Token.DEFAULT_CHANNEL && t.getType() != NL) {
+ buf[n++] = t;
+ }
+ }
+ if (n == buf.length) {
+ return buf;
+ }
+ Token[] exact = new Token[n];
+ System.arraycopy(buf, 0, exact, 0, n);
+ return exact;
+ }
+
protected String createNoViableAlternativeErrorMessage(final Parser recognizer, final NoViableAltException e) {
TokenStream tokens = recognizer.getInputStream();
String input;
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/internal/package-info.java b/src/main/java/org/apache/groovy/parser/antlr4/internal/package-info.java
index eefadf3498..585a42046c 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/internal/package-info.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/internal/package-info.java
@@ -24,9 +24,12 @@
* diagnostics ({@link MissingDelimiterDiagnostic} for relocated missing-closer
* carets; fallback wording lives on {@link AbstractFriendlyErrorStrategy},
* including reserved keywords, a leading {@code ?[} without a path to
- * attach to, and a singleton expected-punctuation token after optional
- * newlines are ignored). Reporting is one listener dispatch
- * after locate/refine. Diagnostic helpers run only after recognition has
- * already failed so they do not affect steady-state parse performance.
+ * attach to, array-creation mistakes, an unclosed type argument, a method
+ * header in a statement position, an unmatched {@code do}, enum constants
+ * that need {@code ;} before members, and a singleton expected-punctuation
+ * token after optional newlines are ignored). Reporting is one listener
+ * dispatch after locate/refine. Diagnostic helpers run only after
+ * recognition has already failed so they do not affect steady-state parse
+ * performance.
*/
package org.apache.groovy.parser.antlr4.internal;
diff --git a/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java b/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
index 9b86150f6a..84c959173f 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/util/PositionConfigureUtils.java
@@ -25,10 +25,14 @@ import org.apache.groovy.parser.antlr4.GroovyParser;
import org.codehaus.groovy.ast.ASTNode;
import static groovy.lang.Tuple.tuple;
-import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
/**
- * Utilities for configuring node positions
+ * Utilities for configuring AST source positions.
+ * <p>
+ * Line and column numbers are 1-based; the end column is exclusive.
+ * {@code -1} means the node is synthetic or generated and has no span in
+ * the source. Authored nodes should be stamped through these helpers so
+ * tooling can tell them apart ({@code lineNumber > 0}).
*/
public class PositionConfigureUtils {
/**
@@ -97,12 +101,28 @@ public class PositionConfigureUtils {
return astNode;
}
+ /**
+ * Sets the start from {@code ctx} and the end from {@code initialStop}
+ * when that node has an authored end position. Otherwise the end comes
+ * from {@code ctx}'s stop token.
+ * <p>
+ * Groovy truth is non-null, so a synthetic {@code ConstantExpression}
+ * (default {@code -1} coordinates) must not be treated as a stop: it
+ * would wipe the parent's end. The same applies to
+ * {@code EmptyExpression.INSTANCE}.
+ *
+ * @param astNode node to modify
+ * @param ctx parse context supplying the start (and fallback end)
+ * @param initialStop authored initializer whose end should be used, or
+ * {@code null}/unpositioned to use {@code ctx}'s stop
+ * @return {@code astNode}
+ */
public static <T extends ASTNode> T configureAST(T astNode, GroovyParser.GroovyParserRuleContext ctx, ASTNode initialStop) {
Token start = ctx.getStart();
astNode.setLineNumber(start.getLine());
astNode.setColumnNumber(start.getCharPositionInLine() + 1);
- if (asBoolean(initialStop)) {
+ if (hasEndPosition(initialStop)) {
astNode.setLastLineNumber(initialStop.getLastLineNumber());
astNode.setLastColumnNumber(initialStop.getLastColumnNumber());
} else {
@@ -119,11 +139,22 @@ public class PositionConfigureUtils {
astNode.setLastColumnNumber(endPosition.getV2());
}
+ /**
+ * Sets the start from {@code start} and the end from {@code stop} when
+ * that node has an authored end position. Otherwise the end is copied
+ * from {@code start}. See {@link #configureAST(ASTNode, GroovyParser.GroovyParserRuleContext, ASTNode)}.
+ *
+ * @param astNode node to modify
+ * @param start node supplying the start (and fallback end)
+ * @param stop authored node whose end should be used, or
+ * {@code null}/unpositioned to use {@code start}'s end
+ * @return {@code astNode}
+ */
public static <T extends ASTNode> T configureAST(T astNode, ASTNode start, ASTNode stop) {
astNode.setLineNumber(start.getLineNumber());
astNode.setColumnNumber(start.getColumnNumber());
- if (asBoolean(stop)) {
+ if (hasEndPosition(stop)) {
astNode.setLastLineNumber(stop.getLastLineNumber());
astNode.setLastColumnNumber(stop.getLastColumnNumber());
} else {
@@ -133,4 +164,12 @@ public class PositionConfigureUtils {
return astNode;
}
+
+ /**
+ * {@link ASTNode} defaults to {@code -1}; line numbers are 1-based, so a
+ * last line of {@code 0} is also treated as missing.
+ */
+ private static boolean hasEndPosition(final ASTNode node) {
+ return node != null && node.getLastLineNumber() > 0;
+ }
}
diff --git a/src/main/java/org/codehaus/groovy/syntax/Numbers.java b/src/main/java/org/codehaus/groovy/syntax/Numbers.java
index 3ef70ade18..05311dec4e 100644
--- a/src/main/java/org/codehaus/groovy/syntax/Numbers.java
+++ b/src/main/java/org/codehaus/groovy/syntax/Numbers.java
@@ -186,13 +186,13 @@ public class Numbers {
switch (type) {
case 'i':
if (radix == 10 && (value.compareTo(MAX_INTEGER) > 0 || value.compareTo(MIN_INTEGER) < 0)) {
- throw new NumberFormatException("Number of value " + value + " does not fit in the range of int, but int was enforced.");
+ throw new NumberFormatException("Integer number too large: " + value);
} else {
return value.intValue();
}
case 'l':
if (radix == 10 && (value.compareTo(MAX_LONG) > 0 || value.compareTo(MIN_LONG) < 0)) {
- throw new NumberFormatException("Number of value " + value + " does not fit in the range of long, but long was enforced.");
+ throw new NumberFormatException("Long number too large: " + value);
} else {
return value.longValue();
}
diff --git a/src/test/groovy/bugs/Groovy4252Bug.groovy b/src/test/groovy/bugs/Groovy4252Bug.groovy
index e7f135b6fa..c07d09b754 100644
--- a/src/test/groovy/bugs/Groovy4252Bug.groovy
+++ b/src/test/groovy/bugs/Groovy4252Bug.groovy
@@ -31,7 +31,8 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Unexpected input: '('")
+ syntaxError.message.contains("Unexpected input: '('") ||
+ syntaxError.message.contains("Unexpected '('")
}
}
@@ -44,7 +45,8 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Unexpected input: ';'")
+ syntaxError.message.contains("Unexpected input: ';'") ||
+ syntaxError.message.contains("Unexpected ';'")
}
}
@@ -57,7 +59,8 @@ class Groovy4252Bug extends GroovyShellTestCase {
} catch (MultipleCompilationErrorsException e) {
def syntaxError = e.errorCollector.getSyntaxError(0)
assert syntaxError.message.contains("Expression list of the form (a; b; c) is not supported in this context") ||
- syntaxError.message.contains("Unexpected input: '('")
+ syntaxError.message.contains("Unexpected input: '('") ||
+ syntaxError.message.contains("Unexpected '('")
}
}
diff --git a/src/test/groovy/bugs/Groovy8046.groovy b/src/test/groovy/bugs/Groovy8046.groovy
index 6fedc00997..97621bcdd8 100644
--- a/src/test/groovy/bugs/Groovy8046.groovy
+++ b/src/test/groovy/bugs/Groovy8046.groovy
@@ -34,7 +34,7 @@ final class Groovy8046 {
}
'''
- assert err.message =~ /The field 'field' has invalid type void|void is not allowed here/
+ assert err.message =~ /The field 'field' has invalid type void|'void' type is not allowed here|void is not allowed here/
}
@Test
@@ -45,7 +45,7 @@ final class Groovy8046 {
}
'''
- assert err.message =~ /The parameter 'param' in method 'int foo\(void\)' has invalid type void|void is not allowed here/
+ assert err.message =~ /The parameter 'param' in method 'int foo\(void\)' has invalid type void|'void' type is not allowed here|void is not allowed here/
}
@Test
@@ -58,6 +58,6 @@ final class Groovy8046 {
}
'''
- assert err.message =~ /The variable 'bar' has invalid type void|void is not allowed here/
+ assert err.message =~ /The variable 'bar' has invalid type void|'void' type is not allowed here|void is not allowed here/
}
}
diff --git a/src/test/groovy/bugs/Groovy8446.groovy b/src/test/groovy/bugs/Groovy8446.groovy
index aad08947aa..885f2dd8d2 100644
--- a/src/test/groovy/bugs/Groovy8446.groovy
+++ b/src/test/groovy/bugs/Groovy8446.groovy
@@ -52,6 +52,6 @@ final class Groovy8446 {
def meth(void... args) {}
}
'''
- assert err.message =~ /void\[\] is an invalid type|void is not allowed here/
+ assert err.message =~ /void\[\] is an invalid type|'void' type is not allowed here|void is not allowed here/
}
}
diff --git a/src/test/groovy/bugs/Groovy9141.groovy b/src/test/groovy/bugs/Groovy9141.groovy
index 1e1a3594d0..072a364e73 100644
--- a/src/test/groovy/bugs/Groovy9141.groovy
+++ b/src/test/groovy/bugs/Groovy9141.groovy
@@ -34,7 +34,7 @@ final class Groovy9141 {
abstract void meth() {}
}
'''
- assert err.message =~ / You defined an abstract method\[meth\] with a body. Try removing the method body @ line /
+ assert err.message =~ / Abstract method 'meth' cannot have a body. Remove the method body @ line /
}
@Test // not a language requirement but script-level check takes precedence in current implementation
@@ -42,6 +42,6 @@ final class Groovy9141 {
def err = shouldFail CompilationFailedException, '''
abstract void meth() {}
'''
- assert err.message =~ / You cannot define an abstract method\[meth\] in the script. Try removing the 'abstract' /
+ assert err.message =~ / Scripts cannot declare abstract method 'meth'. Remove 'abstract' /
}
}
diff --git a/src/test/groovy/gls/generics/GenericsUsageTest.groovy b/src/test/groovy/gls/generics/GenericsUsageTest.groovy
index c7c5117ea7..c166ca2bc5 100644
--- a/src/test/groovy/gls/generics/GenericsUsageTest.groovy
+++ b/src/test/groovy/gls/generics/GenericsUsageTest.groovy
@@ -197,32 +197,32 @@ final class GenericsUsageTest {
shouldFailCompilationWithMessage '''
List<Integer list2 = new ArrayList<Integer>()
- ''', "Unexpected input: 'List<Integer'"
+ ''', "Missing '>'"
- shouldFailCompilationWithMessage '''
+ shouldFailCompilationWithAnyMessage '''
def c = []
for (Iterator<String i = c.iterator(); i.hasNext(); ) { }
- ''', "Unexpected input: 'Iterator<String i'"
+ ''', ["Missing '>'", "Unexpected input: 'Iterator<String i'"]
- shouldFailCompilationWithMessage '''
+ shouldFailCompilationWithAnyMessage '''
def m(Class<Integer someParam) {}
- ''', "Unexpected input: 'Class<Integer someParam'"
+ ''', ["Missing '>'", "Unexpected input: 'Class<Integer someParam'"]
shouldFailCompilationWithMessage '''
abstract class ArrayList1<E extends AbstractList<E> implements List<E> {}
''', "Missing '>'"
- shouldFailCompilationWithMessage '''
+ shouldFailCompilationWithAnyMessage '''
abstract class ArrayList2<E> extends AbstractList<E implements List<E> {}
- ''', "Unexpected input: '<'"
+ ''', ["Missing '>'", "Unexpected input: '<'"]
- shouldFailCompilationWithMessage '''
+ shouldFailCompilationWithAnyMessage '''
abstract class ArrayList3<E> extends AbstractList<E> implements List<E {}
- ''', "Unexpected input: '<'"
+ ''', ["Missing '>'", "Unexpected input: '<'"]
- shouldFailCompilationWithMessage '''
+ shouldFailCompilationWithAnyMessage '''
def List<List<Integer> history = new ArrayList<List<Integer>>()
- ''', "Unexpected input: 'def List<List<Integer> history'"
+ ''', ["Missing '>'", "Unexpected input: 'def List<List<Integer> history'"]
shouldFailCompilationWithMessage '''
def List<List<Integer>> history = new ArrayList<List<Integer>()
diff --git a/src/test/groovy/groovy/MethodInBadPositionTest.groovy b/src/test/groovy/groovy/MethodInBadPositionTest.groovy
index 17f799d375..9b11134297 100644
--- a/src/test/groovy/groovy/MethodInBadPositionTest.groovy
+++ b/src/test/groovy/groovy/MethodInBadPositionTest.groovy
@@ -33,7 +33,7 @@ final class MethodInBadPositionTest extends CompilableTestSupport {
}
}()
'''
- assert msg.contains('Method definition not expected here') || msg.contains("Unexpected input: '('")
+ assert msg.contains('Method definition not expected here')
}
// GROOVY-4215
@@ -44,6 +44,6 @@ final class MethodInBadPositionTest extends CompilableTestSupport {
case 1: def say(){}
}
'''
- assert msg.contains('Method definition not expected here') || msg.contains("Unexpected input: '('") || msg.contains("Unexpected input: 'switch(1)")
+ assert msg.contains('Method definition not expected here')
}
}
diff --git a/src/test/groovy/org/apache/groovy/parser/antlr4/ParserNegativeSyntaxTest.groovy b/src/test/groovy/org/apache/groovy/parser/antlr4/ParserNegativeSyntaxTest.groovy
index 527fb31846..2c147d4d31 100644
--- a/src/test/groovy/org/apache/groovy/parser/antlr4/ParserNegativeSyntaxTest.groovy
+++ b/src/test/groovy/org/apache/groovy/parser/antlr4/ParserNegativeSyntaxTest.groovy
@@ -43,7 +43,7 @@ final class ParserNegativeSyntaxTest {
| def x()
|}
|'''.stripMargin(), '''\
- |You defined a method[x] without a body. Try adding a method body, or declare it abstract @ line 2, column 5.
+ |Method 'x' is missing a body. Add a method body, or declare it abstract @ line 2, column 5.
| def x()
| ^
|
@@ -56,7 +56,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|def w()
|'''.stripMargin(), '''\
- |You cannot define a method[w] without method body in the script. Try adding a method body @ line 1, column 1.
+ |Scripts cannot declare method 'w' without a body. Add a method body @ line 1, column 1.
| def w()
| ^
|
@@ -69,7 +69,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|abstract u() {}
|'''.stripMargin(), '''\
- |You cannot define an abstract method[u] in the script. Try removing the 'abstract' @ line 1, column 1.
+ |Scripts cannot declare abstract method 'u'. Remove 'abstract' @ line 1, column 1.
| abstract u() {}
| ^
|
@@ -84,7 +84,7 @@ final class ParserNegativeSyntaxTest {
| void a()
|}
|'''.stripMargin(), '''\
- |annotation method cannot have void return type @ line 2, column 5.
+ |Annotation type elements cannot have a void return type @ line 2, column 5.
| void a()
| ^
|
@@ -139,7 +139,7 @@ final class ParserNegativeSyntaxTest {
| }
|}
|'''.stripMargin(), '''\
- |Annotation type element should not have body @ line 2, column 5.
+ |Annotation type elements cannot have a body @ line 2, column 5.
| String a() {
| ^
|
@@ -152,7 +152,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|def foo = new double[][5]
|'''.stripMargin(), '''\
- |Unexpected input: '5' @ line 1, column 24.
+ |Cannot specify an array size after an empty dimension @ line 1, column 24.
| def foo = new double[][5]
| ^
|
@@ -160,12 +160,25 @@ final class ParserNegativeSyntaxTest {
|'''.stripMargin()
}
+ @Test
+ void 'array size with initializer'() {
+ expectParseError '''\
+ |def foo = new double[2] { 1.0, 2.0 }
+ |'''.stripMargin(), '''\
+ |Cannot combine an array size with an array initializer @ line 1, column 25.
+ | def foo = new double[2] { 1.0, 2.0 }
+ | ^
+ |
+ |1 error
+ |'''.stripMargin()
+ }
+
@Test
void 'array no dimensions'() {
expectParseError '''\
|def foo = new double[]
|'''.stripMargin(), '''\
- |Missing '{' @ line 2, column 1.
+ |Array dimension missing; specify a size or add an initializer '{}' @ line 2, column 1.
|1 error
|'''.stripMargin()
}
@@ -192,7 +205,7 @@ final class ParserNegativeSyntaxTest {
| Foo() {}
|}
|'''.stripMargin(), '''\
- |Invalid method declaration: Foo @ line 3, column 5.
+ |Anonymous classes cannot declare constructors @ line 3, column 5.
| Foo() {}
| ^
|
@@ -209,7 +222,7 @@ final class ParserNegativeSyntaxTest {
| }
|}
|'''.stripMargin(), '''\
- |Only record can have compact constructor @ line 3, column 12.
+ |Compact constructors are only allowed in records @ line 3, column 12.
| public Person {
| ^
|
@@ -222,7 +235,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|def x = (1;2;3)
|'''.stripMargin(), '''\
- |Unexpected input: ';' @ line 1, column 11.
+ |Unexpected ';' @ line 1, column 11.
| def x = (1;2;3)
| ^
|
@@ -252,7 +265,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|List<Integer list2 = new ArrayList<Integer>()
|'''.stripMargin(), '''\
- |Unexpected input: 'List<Integer' @ line 1, column 1.
+ |Missing '>' @ line 1, column 1.
| List<Integer list2 = new ArrayList<Integer>()
| ^
|
@@ -265,7 +278,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|class Foo { static final Foo() {} }
|'''.stripMargin(), '''\
- |Constructor has an incorrect modifier 'static'. @ line 1, column 13.
+ |Modifier 'static' is not allowed on a constructor @ line 1, column 13.
| class Foo { static final Foo() {} }
| ^
|
@@ -281,7 +294,7 @@ final class ParserNegativeSyntaxTest {
|println 123
|while (false)
|'''.stripMargin(), '''\
- |Unexpected input: '123\\nprintln' @ line 3, column 1.
+ |do-while body must be a single statement; wrap multiple statements in '{ }' @ line 3, column 1.
| println 123
| ^
|
@@ -289,6 +302,17 @@ final class ParserNegativeSyntaxTest {
|'''.stripMargin()
}
+ @Test
+ void 'do without while'() {
+ expectParseError '''\
+ |do
+ |println 123
+ |'''.stripMargin(), '''\
+ |Missing 'while' @ line 3, column 1.
+ |1 error
+ |'''.stripMargin()
+ }
+
@Test
void 'duplicated named parameter'() {
expectParseError '''\
@@ -321,7 +345,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|1 = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| 1 = 2
| ^
|
@@ -349,7 +373,7 @@ final class ParserNegativeSyntaxTest {
| import java.util.*
|}
|'''.stripMargin(), '''\
- |Unexpected input: 'import' @ line 2, column 5.
+ |'import' is only allowed at the beginning of a compilation unit @ line 2, column 5.
| import java.util.*
| ^
|
@@ -381,7 +405,7 @@ final class ParserNegativeSyntaxTest {
| }
|}
|'''.stripMargin(), '''\
- |You defined an abstract method[foo] with a body. Try removing the method body, or declare it default or private @ line 2, column 5.
+ |Abstract method 'foo' cannot have a body. Remove the method body, or declare it default or private @ line 2, column 5.
| def foo(a, b) {
| ^
|
@@ -389,6 +413,21 @@ final class ParserNegativeSyntaxTest {
|'''.stripMargin()
}
+ @Test
+ void 'interface annotation-style default'() {
+ expectParseError '''\
+ |interface I {
+ | def m() default {1}
+ |}
+ |'''.stripMargin(), '''\
+ |'default' cannot follow a method header; put 'default' before the method name @ line 2, column 13.
+ | def m() default {1}
+ | ^
+ |
+ |1 error
+ |'''.stripMargin()
+ }
+
@Test
void 'interface implements'() {
expectParseError '''\
@@ -437,7 +476,7 @@ final class ParserNegativeSyntaxTest {
| }
|}()
|'''.stripMargin(), '''\
- |Unexpected input: '(' @ line 2, column 12.
+ |Method definition not expected here @ line 2, column 12.
| def say(String msg) {
| ^
|
@@ -476,7 +515,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|foo(String a)
|'''.stripMargin(), '''\
- |Invalid method declaration @ line 1, column 4.
+ |Invalid method declaration; a return type or 'def' is required @ line 1, column 4.
| foo(String a)
| ^
|
@@ -489,7 +528,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|def def m() {}
|'''.stripMargin(), '''\
- |Cannot repeat modifier[def] @ line 1, column 5.
+ |Cannot repeat modifier 'def' @ line 1, column 5.
| def def m() {}
| ^
|
@@ -504,7 +543,7 @@ final class ParserNegativeSyntaxTest {
| private public a
|}
|'''.stripMargin(), '''\
- |Cannot specify modifier[public] when access scope has already been defined @ line 2, column 13.
+ |Cannot specify modifier 'public' when the access scope has already been defined @ line 2, column 13.
| private public a
| ^
|
@@ -517,7 +556,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|volatile x() {}
|'''.stripMargin(), '''\
- |Method has an incorrect modifier 'volatile'. @ line 1, column 1.
+ |Modifier 'volatile' is not allowed on a method @ line 1, column 1.
| volatile x() {}
| ^
|
@@ -551,7 +590,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|2147483648I
|'''.stripMargin(), '''\
- |Number of value 2147483648 does not fit in the range of int, but int was enforced. @ line 1, column 1.
+ |Integer number too large: 2147483648 @ line 1, column 1.
| 2147483648I
| ^
|
@@ -590,7 +629,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|(1 + 2))
|'''.stripMargin(), '''\
- |Unexpected input: ')' @ line 1, column 8.
+ |Unexpected ')' @ line 1, column 8.
| (1 + 2))
| ^
|
@@ -656,7 +695,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|class Fruit(String name, double price) {}
|'''.stripMargin(), '''\
- |header declaration is only allowed for record declaration @ line 1, column 12.
+ |Only records can have a compact header, for example: record Fruit(...) @ line 1, column 12.
| class Fruit(String name, double price) {}
| ^
|
@@ -669,7 +708,7 @@ final class ParserNegativeSyntaxTest {
expectParseError '''\
|record Fruit {}
|'''.stripMargin(), '''\
- |header declaration of record is expected @ line 1, column 8.
+ |Record 'Fruit' is missing a header, for example: record Fruit(...) @ line 1, column 8.
| record Fruit {}
| ^
|
@@ -949,7 +988,7 @@ final class ParserNegativeSyntaxTest {
| default -> throw new RuntimeException('z')
|}
|'''.stripMargin(), '''\
- |Expect only 1 statement, but 2 statements found @ line 3, column 15.
+ |Arrow switch cases must contain a single statement, but 2 were found @ line 3, column 15.
| case 6 -> def x = 'a'; yield x
| ^
|
@@ -970,6 +1009,24 @@ final class ParserNegativeSyntaxTest {
|'''.stripMargin()
}
+ @Test
+ void 'default not last in switch'() {
+ expectParseError '''\
+ |switch (a) {
+ | default:
+ | break
+ | case 1:
+ | break
+ |}
+ |'''.stripMargin(), '''\
+ |A default branch must appear as the last branch of a switch @ line 2, column 5.
+ | default:
+ | ^
+ |
+ |1 error
+ |'''.stripMargin()
+ }
+
@Test
void 'duplicate default in switch'() {
expectParseError '''\
@@ -982,9 +1039,9 @@ final class ParserNegativeSyntaxTest {
| break
|}
|'''.stripMargin(), '''\
- |a switch must only have one default branch @ line 5, column 9.
- | break
- | ^
+ |A switch can have only one default branch @ line 6, column 5.
+ | default:
+ | ^
|
|1 error
|'''.stripMargin()
@@ -1010,7 +1067,7 @@ final class ParserNegativeSyntaxTest {
| abstract m() {}
|}
|'''.stripMargin(), '''\
- |Abstract method should not have method body @ line 2, column 5.
+ |Abstract method cannot have a body @ line 2, column 5.
| abstract m() {}
| ^
|
@@ -1064,7 +1121,7 @@ final class ParserNegativeSyntaxTest {
| void field
|}
|'''.stripMargin(), '''\
- |void is not allowed here @ line 2, column 5.
+ |'void' type is not allowed here @ line 2, column 5.
| void field
| ^
|
@@ -1098,6 +1155,22 @@ final class ParserNegativeSyntaxTest {
|'''.stripMargin()
}
+ @Test
+ void 'enum comma before members'() {
+ expectParseError '''\
+ |enum E {
+ | X, Y,
+ | def z() { }
+ |}
+ |'''.stripMargin(), '''\
+ |';' expected after the last enum constant @ line 3, column 3.
+ | def z() { }
+ | ^
+ |
+ |1 error
+ |'''.stripMargin()
+ }
+
@Test
void 'enum extends'() {
expectParseError '''\
@@ -1208,7 +1281,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|1 = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| 1 = 2
| ^
|
@@ -1216,7 +1289,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|m() = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| m() = 2
| ^
|
@@ -1224,7 +1297,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|[1, 2] = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| [1, 2] = 2
| ^
|
@@ -1232,7 +1305,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|[a: 1, b: 2] = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| [a: 1, b: 2] = 2
| ^
|
@@ -1240,7 +1313,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|"$x" = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| "$x" = 2
| ^
|
@@ -1248,7 +1321,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|'x' = 2
|'''.stripMargin(), '''\
- |The LHS of an assignment should be a variable or a field accessing expression @ line 1, column 1.
+ |The left-hand side of an assignment must be a variable or a field @ line 1, column 1.
| 'x' = 2
| ^
|
@@ -1286,9 +1359,9 @@ final class ParserNegativeSyntaxTest {
|
|
|'''.stripMargin(), '''\
- |a switch must only have one default branch @ line 5, column 9.
- | break;
- | ^
+ |A switch can have only one default branch @ line 6, column 5.
+ | default:
+ | ^
|
|1 error'''.stripMargin())
}
@@ -1432,7 +1505,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|(1 + 2))
|'''.stripMargin(), '''\
- |Unexpected input: ')' @ line 1, column 8.
+ |Unexpected ')' @ line 1, column 8.
| (1 + 2))
| ^
|
@@ -1536,7 +1609,7 @@ final class ParserNegativeSyntaxTest {
| def x()
|}
|'''.stripMargin(), '''\
- |You defined a method[x] without a body. Try adding a method body, or declare it abstract @ line 2, column 5.
+ |Method 'x' is missing a body. Add a method body, or declare it abstract @ line 2, column 5.
| def x()
| ^
|
@@ -1547,7 +1620,7 @@ final class ParserNegativeSyntaxTest {
| def y()
|}
|'''.stripMargin(), '''\
- |You defined a method[y] without a body. Try adding a method body, or declare it abstract @ line 3, column 5.
+ |Method 'y' is missing a body. Add a method body, or declare it abstract @ line 3, column 5.
| def y()
| ^
|
@@ -1557,7 +1630,7 @@ final class ParserNegativeSyntaxTest {
| def z()
|}
|'''.stripMargin(), '''\
- |You defined a method[z] without a body. Try adding a method body, or declare it abstract @ line 2, column 5.
+ |Method 'z' is missing a body. Add a method body, or declare it abstract @ line 2, column 5.
| def z()
| ^
|
@@ -1565,7 +1638,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|def w()
|'''.stripMargin(), '''\
- |You cannot define a method[w] without method body in the script. Try adding a method body @ line 1, column 1.
+ |Scripts cannot declare method 'w' without a body. Add a method body @ line 1, column 1.
| def w()
| ^
|
@@ -1573,7 +1646,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|abstract v()
|'''.stripMargin(), '''\
- |You cannot define an abstract method[v] without method body in the script. Try removing the 'abstract' and adding a method body @ line 1, column 1.
+ |Scripts cannot declare abstract method 'v'. Remove 'abstract' and add a method body @ line 1, column 1.
| abstract v()
| ^
|
@@ -1581,7 +1654,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|abstract u() {}
|'''.stripMargin(), '''\
- |You cannot define an abstract method[u] in the script. Try removing the 'abstract' @ line 1, column 1.
+ |Scripts cannot declare abstract method 'u'. Remove 'abstract' @ line 1, column 1.
| abstract u() {}
| ^
|
@@ -1619,7 +1692,7 @@ final class ParserNegativeSyntaxTest {
|println 123
|while(false)
|'''.stripMargin(), [
- 'Unexpected input: \'123\\nprintln\' @ line 3, column 1.',
+ 'do-while body must be a single statement; wrap multiple statements in \'{ }\' @ line 3, column 1.',
' println 123',
' ^',
'',
@@ -1652,7 +1725,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|def def m() {}
|'''.stripMargin(), '''\
- |Cannot repeat modifier[def] @ line 1, column 5.
+ |Cannot repeat modifier 'def' @ line 1, column 5.
| def def m() {}
| ^
|
@@ -1660,7 +1733,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|public public class A {}
|'''.stripMargin(), '''\
- |Cannot repeat modifier[public] @ line 1, column 8.
+ |Cannot repeat modifier 'public' @ line 1, column 8.
| public public class A {}
| ^
|
@@ -1668,7 +1741,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|final final int a = 1;
|'''.stripMargin(), '''\
- |Cannot repeat modifier[final] @ line 1, column 7.
+ |Cannot repeat modifier 'final' @ line 1, column 7.
| final final int a = 1;
| ^
|
@@ -1678,7 +1751,7 @@ final class ParserNegativeSyntaxTest {
| private public a
|}
|'''.stripMargin(), '''\
- |Cannot specify modifier[public] when access scope has already been defined @ line 2, column 13.
+ |Cannot specify modifier 'public' when the access scope has already been defined @ line 2, column 13.
| private public a
| ^
|
@@ -1688,7 +1761,7 @@ final class ParserNegativeSyntaxTest {
| protected public a
|}
|'''.stripMargin(), '''\
- |Cannot specify modifier[public] when access scope has already been defined @ line 2, column 15.
+ |Cannot specify modifier 'public' when the access scope has already been defined @ line 2, column 15.
| protected public a
| ^
|
@@ -1696,7 +1769,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|volatile x() {}
|'''.stripMargin(), '''\
- |Method has an incorrect modifier 'volatile'. @ line 1, column 1.
+ |Modifier 'volatile' is not allowed on a method @ line 1, column 1.
| volatile x() {}
| ^
|
@@ -1712,7 +1785,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |Invalid method declaration: Foo @ line 3, column 5.
+ |Anonymous classes cannot declare constructors @ line 3, column 5.
| Foo() {}
| ^
|
@@ -1735,7 +1808,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |Only record can have compact constructor @ line 7, column 12.
+ |Compact constructors are only allowed in records @ line 7, column 12.
| public Person {
| ^
|
@@ -1762,12 +1835,12 @@ final class ParserNegativeSyntaxTest {
|
|class Person {
| Person {
- | // Only record can have compact constructor
+ | // Compact constructors are only allowed in records
| }
|}
|
|'''.stripMargin(), '''\
- |Only record can have compact constructor @ line 4, column 5.
+ |Compact constructors are only allowed in records @ line 4, column 5.
| Person {
| ^
|
@@ -1809,7 +1882,7 @@ final class ParserNegativeSyntaxTest {
| def z() { }
|}
|'''.stripMargin(), '''\
- |Unexpected input: ',\\n def' @ line 3, column 3.
+ |';' expected after the last enum constant @ line 3, column 3.
| def z() { }
| ^
|
@@ -1824,7 +1897,7 @@ final class ParserNegativeSyntaxTest {
| void a()
|}
|'''.stripMargin(), '''\
- |annotation method cannot have void return type @ line 2, column 5.
+ |Annotation type elements cannot have a void return type @ line 2, column 5.
| void a()
| ^
|
@@ -1878,7 +1951,7 @@ final class ParserNegativeSyntaxTest {
| String a() {
| }
|}'''.stripMargin(), '''\
- |Annotation type element should not have body @ line 2, column 5.
+ |Annotation type elements cannot have a body @ line 2, column 5.
| String a() {
| ^
|
@@ -1979,7 +2052,7 @@ final class ParserNegativeSyntaxTest {
|}()
|
|'''.stripMargin(), '''\
- |Unexpected input: '(' @ line 2, column 12.
+ |Method definition not expected here @ line 2, column 12.
| def say(String msg) {
| ^
|
@@ -2008,7 +2081,7 @@ final class ParserNegativeSyntaxTest {
|foo(String a)
|
|'''.stripMargin(), '''\
- |Invalid method declaration @ line 1, column 4.
+ |Invalid method declaration; a return type or 'def' is required @ line 1, column 4.
| foo(String a)
| ^
|
@@ -2017,7 +2090,7 @@ final class ParserNegativeSyntaxTest {
|foo(int a)
|
|'''.stripMargin(), '''\
- |Invalid method declaration @ line 1, column 4.
+ |Invalid method declaration; a return type or 'def' is required @ line 1, column 4.
| foo(int a)
| ^
|
@@ -2029,7 +2102,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|class Foo { static final Foo() {}}
|'''.stripMargin(), '''\
- |Constructor has an incorrect modifier 'static'. @ line 1, column 13.
+ |Modifier 'static' is not allowed on a constructor @ line 1, column 13.
| class Foo { static final Foo() {}}
| ^
|
@@ -2049,7 +2122,7 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|def x = (1;2;3)
|'''.stripMargin(), '''\
- |Unexpected input: ';' @ line 1, column 11.
+ |Unexpected ';' @ line 1, column 11.
| def x = (1;2;3)
| ^
|
@@ -2117,7 +2190,7 @@ final class ParserNegativeSyntaxTest {
| def m() default {1}
|}
|'''.stripMargin(), '''\
- |Unexpected input: 'default' @ line 2, column 13.
+ |'default' cannot follow a method header; put 'default' before the method name @ line 2, column 13.
| def m() default {1}
| ^
|
@@ -2133,7 +2206,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |void is not allowed here @ line 2, column 5.
+ |'void' type is not allowed here @ line 2, column 5.
| void field
| ^
|
@@ -2146,7 +2219,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |void is not allowed here @ line 3, column 9.
+ |'void' type is not allowed here @ line 3, column 9.
| void bar = null
| ^
|
@@ -2225,7 +2298,7 @@ final class ParserNegativeSyntaxTest {
|2147483648I
|
|'''.stripMargin(), '''\
- |Number of value 2147483648 does not fit in the range of int, but int was enforced. @ line 1, column 1.
+ |Integer number too large: 2147483648 @ line 1, column 1.
| 2147483648I
| ^
|
@@ -2234,7 +2307,7 @@ final class ParserNegativeSyntaxTest {
|9223372036854775808L
|
|'''.stripMargin(), '''\
- |Number of value 9223372036854775808 does not fit in the range of long, but long was enforced. @ line 1, column 1.
+ |Long number too large: 9223372036854775808 @ line 1, column 1.
| 9223372036854775808L
| ^
|
@@ -2397,7 +2470,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), [
- 'Unexpected input: \'{\\n import\' @ line 2, column 5.',
+ '\'import\' is only allowed at the beginning of a compilation unit @ line 2, column 5.',
' import java.util.*',
' ^',
'',
@@ -2409,7 +2482,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |Unexpected input: 'import' @ line 2, column 5.
+ |'import' is only allowed at the beginning of a compilation unit @ line 2, column 5.
| import java.util.*
| ^
|
@@ -2426,7 +2499,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |Abstract method should not have method body @ line 4, column 5.
+ |Abstract method cannot have a body @ line 4, column 5.
| abstract m() {}
| ^
|
@@ -2453,7 +2526,7 @@ final class ParserNegativeSyntaxTest {
|class Fruit(String name, double price) {}
|
|'''.stripMargin(), '''\
- |header declaration is only allowed for record declaration @ line 3, column 12.
+ |Only records can have a compact header, for example: record Fruit(...) @ line 3, column 12.
| class Fruit(String name, double price) {}
| ^
|
@@ -2464,7 +2537,7 @@ final class ParserNegativeSyntaxTest {
|record Fruit {}
|
|'''.stripMargin(), '''\
- |header declaration of record is expected @ line 3, column 8.
+ |Record 'Fruit' is missing a header, for example: record Fruit(...) @ line 3, column 8.
| record Fruit {}
| ^
|
@@ -2555,7 +2628,7 @@ final class ParserNegativeSyntaxTest {
|record R1(int x[]) { }
|
|'''.stripMargin(), '''\
- |Invalid method declaration @ line 4, column 10.
+ |Invalid method declaration; a return type or 'def' is required @ line 4, column 10.
| record R1(int x[]) { }
| ^
|
@@ -2633,7 +2706,7 @@ final class ParserNegativeSyntaxTest {
|def foo = new double[][5]
|
|'''.stripMargin(), '''\
- |Unexpected input: '5' @ line 1, column 24.
+ |Cannot specify an array size after an empty dimension @ line 1, column 24.
| def foo = new double[][5]
| ^
|
@@ -2641,13 +2714,13 @@ final class ParserNegativeSyntaxTest {
expectParseError('''\
|def foo = new double[]
|'''.stripMargin(), '''\
- |Missing '{' @ line 2, column 1.
+ |Array dimension missing; specify a size or add an initializer '{}' @ line 2, column 1.
|1 error'''.stripMargin())
expectParseError('''\
|def foo = new double[2] { 1.0, 2.0 }
|
|'''.stripMargin(), '''\
- |Unexpected input: '{' @ line 1, column 25.
+ |Cannot combine an array size with an array initializer @ line 1, column 25.
| def foo = new double[2] { 1.0, 2.0 }
| ^
|
@@ -2783,7 +2856,7 @@ final class ParserNegativeSyntaxTest {
|}
|
|'''.stripMargin(), '''\
- |Expect only 1 statement, but 2 statements found @ line 4, column 15.
+ |Arrow switch cases must contain a single statement, but 2 were found @ line 4, column 15.
| case 6 -> def x = 'a'; yield x
| ^
|
diff --git a/src/test/groovy/org/apache/groovy/parser/antlr4/ParserPositiveSyntaxTest.groovy b/src/test/groovy/org/apache/groovy/parser/antlr4/ParserPositiveSyntaxTest.groovy
index f7f4dc5f03..2f124ff643 100644
--- a/src/test/groovy/org/apache/groovy/parser/antlr4/ParserPositiveSyntaxTest.groovy
+++ b/src/test/groovy/org/apache/groovy/parser/antlr4/ParserPositiveSyntaxTest.groovy
@@ -36,7 +36,8 @@ import static org.apache.groovy.parser.antlr4.TestUtils.parseModule
* <p>
* Each snippet is compiled through {@code CONVERSION} and asserted against
* a pretty-printed XML AST dump ({@link AstXmlDumper})
- * that includes source positions on every node.
+ * that includes source positions. Authored nodes carry line/column
+ * information; synthetic or generated nodes remain at {@code -1}.
*/
@AutoFinal
final class ParserPositiveSyntaxTest {
@@ -460,7 +461,10 @@ final class ParserPositiveSyntaxTest {
|'''.stripMargin(), '''\
|<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
- | <ClassNode line="1" column="1" lastLine="1" lastColumn="43" kind="record" name="Fruit"/>
+ | <ClassNode line="1" column="1" lastLine="1" lastColumn="43" kind="record" name="Fruit">
+ | <PropertyNode line="1" column="14" lastLine="1" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="1" column="27" lastLine="1" lastColumn="39" name="price" type="double" modifiers="public final"/>
+ | </ClassNode>
|</Module>
|'''.stripMargin()
expectAst '''\
@@ -477,6 +481,9 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.TupleConstructor" members="pre"/>
| <ClassNode line="1" column="1" lastLine="8" lastColumn="2" kind="record" name="Point">
+ | <PropertyNode line="1" column="14" lastLine="1" lastColumn="19" name="x" type="int" modifiers="public final"/>
+ | <PropertyNode line="1" column="21" lastLine="1" lastColumn="26" name="y" type="int" modifiers="public final"/>
+ | <PropertyNode line="1" column="28" lastLine="1" lastColumn="40" name="color" type="String" modifiers="public final"/>
| <ConstructorNode line="5" column="5" lastLine="7" lastColumn="6" name="<init>">
| <Parameter line="5" column="18" lastLine="5" lastColumn="23" name="x" type="int"/>
| <Parameter line="5" column="25" lastLine="5" lastColumn="30" name="y" type="int"/>
@@ -550,7 +557,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="1" column="1" lastLine="3" lastColumn="2" token="=">
| <VariableExpression line="1" column="5" lastLine="1" lastColumn="6" name="r"/>
| <ConstructorCallExpression line="1" column="9" lastLine="3" lastColumn="2" type="test$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="1" column="21" lastLine="1" lastColumn="23"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -623,6 +630,83 @@ final class ParserPositiveSyntaxTest {
| </FieldNode>
| <FieldNode line="4" column="5" lastLine="4" lastColumn="20" name="age" type="int" modifiers="private"/>
| <FieldNode line="7" column="5" lastLine="7" lastColumn="31" name="extra" type="java.lang.Object" modifiers="protected static"/>
+ | <PropertyNode line="5" column="5" lastLine="5" lastColumn="29" name="country" type="String" modifiers="public">
+ | <ConstantExpression line="5" column="22" lastLine="5" lastColumn="29" value="China"/>
+ | </PropertyNode>
+ | <PropertyNode line="5" column="31" lastLine="5" lastColumn="52" name="location" type="String" modifiers="public">
+ | <ConstantExpression line="5" column="42" lastLine="5" lastColumn="52" value="Shanghai"/>
+ | </PropertyNode>
+ | <PropertyNode line="6" column="5" lastLine="6" lastColumn="31" name="title" type="String" modifiers="public final">
+ | <ConstantExpression line="6" column="26" lastLine="6" lastColumn="31" value="dev"/>
+ | </PropertyNode>
+ | </ClassNode>
+ |</Module>
+ |'''.stripMargin()
+ }
+
+ @Test
+ void 'source positions not covered elsewhere'() {
+ // Interface primitive with an authored initializer (AA1 only has synthetic 0 / String NAME).
+ expectAst '''\
+ |interface I1 { int a = 1 }
+ |'''.stripMargin(), '''\
+ |<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClassNode line="1" column="1" lastLine="1" lastColumn="27" kind="interface" name="I1">
+ | <FieldNode line="1" column="16" lastLine="1" lastColumn="25" name="a" type="int" modifiers="public static final">
+ | <ConstantExpression line="1" column="24" lastLine="1" lastColumn="25" value="1"/>
+ | </FieldNode>
+ | </ClassNode>
+ |</Module>
+ |'''.stripMargin()
+ // Multi-declarator: second field must not keep lastLine -1 from the synthetic default.
+ expectAst '''\
+ |interface I2 { int a, b }
+ |'''.stripMargin(), '''\
+ |<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClassNode line="1" column="1" lastLine="1" lastColumn="26" kind="interface" name="I2">
+ | <FieldNode line="1" column="16" lastLine="1" lastColumn="24" name="a" type="int" modifiers="public static final">
+ | <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
+ | </FieldNode>
+ | <FieldNode line="1" column="23" lastLine="1" lastColumn="24" name="b" type="int" modifiers="public static final">
+ | <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
+ | </FieldNode>
+ | </ClassNode>
+ |</Module>
+ |'''.stripMargin()
+ // Property without a visibility modifier (synthetic field is omitted from the dump).
+ expectAst '''\
+ |class C { int a }
+ |'''.stripMargin(), '''\
+ |<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClassNode line="1" column="1" lastLine="1" lastColumn="18" kind="class" name="C">
+ | <PropertyNode line="1" column="11" lastLine="1" lastColumn="16" name="a" type="int" modifiers="public"/>
+ | </ClassNode>
+ |</Module>
+ |'''.stripMargin()
+ // Enum constant with empty parens: FieldNode span includes `()`.
+ expectAst '''\
+ |enum E { A() }
+ |'''.stripMargin(), '''\
+ |<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClassNode line="1" column="1" lastLine="1" lastColumn="15" kind="enum" name="E" extends="java.lang.Enum<E>">
+ | <FieldNode line="1" column="10" lastLine="1" lastColumn="13" name="A" type="E" modifiers="public static final" enumConstant="true"/>
+ | </ClassNode>
+ |</Module>
+ |'''.stripMargin()
+ // GROOVY-11492 multi-line `{ }` (the existing @interface D case is one line).
+ expectAst '''\
+ |@interface D {
+ | String[] zero() default {
+ | }
+ |}
+ |'''.stripMargin(), '''\
+ |<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClassNode line="1" column="1" lastLine="4" lastColumn="2" kind="annotation" name="D" implements="java.lang.annotation.Annotation">
+ | <MethodNode line="2" column="5" lastLine="3" lastColumn="6" name="zero" modifiers="abstract" returnType="String[]">
+ | <ExpressionStatement line="2" column="29" lastLine="3" lastColumn="6">
+ | <ListExpression line="2" column="29" lastLine="3" lastColumn="6"/>
+ | </ExpressionStatement>
+ | </MethodNode>
| </ClassNode>
|</Module>
|'''.stripMargin()
@@ -939,7 +1023,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="4" column="1" lastLine="4" lastColumn="44">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="4" column="6" lastLine="4" lastColumn="40">
| <ClosureListExpression line="4" column="6" lastLine="4" lastColumn="23">
| <DeclarationExpression line="4" column="6" lastLine="4" lastColumn="15" token="=">
| <VariableExpression line="4" column="10" lastLine="4" lastColumn="11" name="i" type="java.lang.Integer"/>
@@ -966,7 +1050,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="4" column="42" lastLine="4" lastColumn="44"/>
| </ForStatement>
| <ForStatement line="5" column="1" lastLine="5" lastColumn="12">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="5" column="6" lastLine="5" lastColumn="8">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -3671,12 +3755,12 @@ final class ParserPositiveSyntaxTest {
| <ClassNode line="45" column="1" lastLine="49" lastColumn="2" kind="annotation" name="D" implements="java.lang.annotation.Annotation">
| <MethodNode line="46" column="5" lastLine="46" lastColumn="32" name="zero" modifiers="abstract" returnType="String[]">
| <ExpressionStatement line="46" column="29" lastLine="46" lastColumn="32">
- | <ListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ListExpression line="46" column="29" lastLine="46" lastColumn="32"/>
| </ExpressionStatement>
| </MethodNode>
| <MethodNode line="47" column="5" lastLine="47" lastColumn="38" name="one" modifiers="abstract" returnType="String[]">
| <ExpressionStatement line="47" column="29" lastLine="47" lastColumn="38">
- | <ListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ListExpression line="47" column="29" lastLine="47" lastColumn="38">
| <ConstantExpression line="47" column="31" lastLine="47" lastColumn="36" value="foo"/>
| </ListExpression>
| </ExpressionStatement>
@@ -6384,7 +6468,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="14" column="1" lastLine="14" lastColumn="24" token="=">
| <VariableExpression line="14" column="5" lastLine="14" lastColumn="10" name="robot"/>
| <ConstructorCallExpression line="14" column="13" lastLine="14" lastColumn="24" type="Robot">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="14" column="22" lastLine="14" lastColumn="24"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -6746,7 +6830,7 @@ final class ParserPositiveSyntaxTest {
| <BooleanExpression line="71" column="8" lastLine="71" lastColumn="73">
| <BinaryExpression line="71" column="8" lastLine="71" lastColumn="73" token="==">
| <ConstructorCallExpression line="71" column="8" lastLine="71" lastColumn="38" type="HashMap<String, Integer>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="71" column="36" lastLine="71" lastColumn="38"/>
| </ConstructorCallExpression>
| <MethodCallExpression line="71" column="42" lastLine="71" lastColumn="73">
| <MethodReferenceExpression line="71" column="66" lastLine="71" lastColumn="71">
@@ -6763,7 +6847,7 @@ final class ParserPositiveSyntaxTest {
| <BooleanExpression line="72" column="8" lastLine="72" lastColumn="57">
| <BinaryExpression line="72" column="8" lastLine="72" lastColumn="57" token="==">
| <ConstructorCallExpression line="72" column="8" lastLine="72" lastColumn="30" type="HashSet<Integer>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="72" column="28" lastLine="72" lastColumn="30"/>
| </ConstructorCallExpression>
| <MethodCallExpression line="72" column="34" lastLine="72" lastColumn="57">
| <MethodReferenceExpression line="72" column="50" lastLine="72" lastColumn="55">
@@ -6780,7 +6864,7 @@ final class ParserPositiveSyntaxTest {
| <BooleanExpression line="74" column="8" lastLine="74" lastColumn="39">
| <BinaryExpression line="74" column="8" lastLine="74" lastColumn="39" token="==">
| <ConstructorCallExpression line="74" column="8" lastLine="74" lastColumn="21" type="HashSet">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="74" column="19" lastLine="74" lastColumn="21"/>
| </ConstructorCallExpression>
| <MethodCallExpression line="74" column="25" lastLine="74" lastColumn="39">
| <MethodReferenceExpression line="74" column="32" lastLine="74" lastColumn="37">
@@ -6797,7 +6881,7 @@ final class ParserPositiveSyntaxTest {
| <BooleanExpression line="75" column="8" lastLine="75" lastColumn="37">
| <BinaryExpression line="75" column="8" lastLine="75" lastColumn="37" token="==">
| <ConstructorCallExpression line="75" column="8" lastLine="75" lastColumn="20" type="String">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="75" column="18" lastLine="75" lastColumn="20"/>
| </ConstructorCallExpression>
| <MethodCallExpression line="75" column="24" lastLine="75" lastColumn="37">
| <MethodReferenceExpression line="75" column="30" lastLine="75" lastColumn="35">
@@ -7315,7 +7399,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="1" column="1" lastLine="1" lastColumn="30" token="=">
| <VariableExpression line="1" column="5" lastLine="1" lastColumn="10" name="shell"/>
| <ConstructorCallExpression line="1" column="13" lastLine="1" lastColumn="30" type="GroovyShell">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="1" column="28" lastLine="1" lastColumn="30"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -11632,7 +11716,7 @@ final class ParserPositiveSyntaxTest {
| <PropertyExpression line="41" column="1" lastLine="41" lastColumn="14" safe="true" spreadSafe="true">
| <BinaryExpression line="41" column="2" lastLine="41" lastColumn="11" token="[">
| <VariableExpression line="41" column="1" lastLine="41" lastColumn="2" name="a"/>
- | <ListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ListExpression line="41" column="2" lastLine="41" lastColumn="11">
| <SpreadExpression line="41" column="3" lastLine="41" lastColumn="10">
| <ListExpression line="41" column="4" lastLine="41" lastColumn="10">
| <ConstantExpression line="41" column="5" lastLine="41" lastColumn="6" value="2"/>
@@ -12073,7 +12157,7 @@ final class ParserPositiveSyntaxTest {
| <MethodCallExpression line="120" column="29" lastLine="120" lastColumn="36">
| <MethodCallExpression line="119" column="22" lastLine="119" lastColumn="47">
| <ConstructorCallExpression line="118" column="33" lastLine="118" lastColumn="53" type="ResolveOptions">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="118" column="51" lastLine="118" lastColumn="53"/>
| </ConstructorCallExpression>
| <ConstantExpression line="119" column="14" lastLine="119" lastColumn="22" value="setConfs"/>
| <CastExpression line="119" column="23" lastLine="119" lastColumn="46" kind="as" type="String[]">
@@ -13591,7 +13675,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="1" column="1" lastLine="1" lastColumn="28" token="=">
| <VariableExpression line="1" column="6" lastLine="1" lastColumn="10" name="list" type="List"/>
| <ConstructorCallExpression line="1" column="13" lastLine="1" lastColumn="28" type="ArrayList">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="1" column="26" lastLine="1" lastColumn="28"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13599,7 +13683,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="2" column="1" lastLine="2" lastColumn="39" token="=">
| <VariableExpression line="2" column="6" lastLine="2" lastColumn="11" name="list2" type="List"/>
| <ConstructorCallExpression line="2" column="14" lastLine="2" lastColumn="39" type="java.util.ArrayList">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="2" column="37" lastLine="2" lastColumn="39"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13607,7 +13691,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="3" column="1" lastLine="3" lastColumn="45" token="=">
| <VariableExpression line="3" column="14" lastLine="3" lastColumn="19" name="list3" type="List<String>"/>
| <ConstructorCallExpression line="3" column="22" lastLine="3" lastColumn="45" type="ArrayList<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="3" column="43" lastLine="3" lastColumn="45"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13615,7 +13699,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="4" column="1" lastLine="4" lastColumn="55" token="=">
| <VariableExpression line="4" column="14" lastLine="4" lastColumn="19" name="list4" type="List<String>"/>
| <ConstructorCallExpression line="4" column="22" lastLine="4" lastColumn="55" type="java.util.ArrayList<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="4" column="53" lastLine="4" lastColumn="55"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13623,7 +13707,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="5" column="1" lastLine="5" lastColumn="39" token="=">
| <VariableExpression line="5" column="14" lastLine="5" lastColumn="19" name="list5" type="List<String>"/>
| <ConstructorCallExpression line="5" column="22" lastLine="5" lastColumn="39" type="ArrayList">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="5" column="37" lastLine="5" lastColumn="39"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13631,7 +13715,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="7" column="1" lastLine="7" lastColumn="24" token="=">
| <VariableExpression line="7" column="5" lastLine="7" lastColumn="6" name="x"/>
| <ConstructorCallExpression line="7" column="9" lastLine="7" lastColumn="24" type="A<EE, TT>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="7" column="22" lastLine="7" lastColumn="24"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13754,7 +13838,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="22" column="1" lastLine="22" lastColumn="19" token="=">
| <VariableExpression line="22" column="5" lastLine="22" lastColumn="7" name="bb"/>
| <ConstructorCallExpression line="22" column="10" lastLine="22" lastColumn="19" type="A.B">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="22" column="17" lastLine="22" lastColumn="19"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -13776,17 +13860,17 @@ final class ParserPositiveSyntaxTest {
| </ExpressionStatement>
| <ExpressionStatement line="30" column="1" lastLine="30" lastColumn="8">
| <ConstructorCallExpression line="30" column="1" lastLine="30" lastColumn="8" type="a">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="30" column="6" lastLine="30" lastColumn="8"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="31" column="1" lastLine="31" lastColumn="9">
| <ConstructorCallExpression line="31" column="1" lastLine="31" lastColumn="9" type="$a">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="31" column="7" lastLine="31" lastColumn="9"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="32" column="1" lastLine="32" lastColumn="24">
| <ConstructorCallExpression line="32" column="1" lastLine="32" lastColumn="24" type="as.def.in.trait.a">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="32" column="22" lastLine="32" lastColumn="24"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -15986,7 +16070,7 @@ final class ParserPositiveSyntaxTest {
|<Module line="-1" column="-1" lastLine="-1" lastColumn="-1">
| <BlockStatement line="-1" column="-1" lastLine="-1" lastColumn="-1">
| <ForStatement line="1" column="1" lastLine="1" lastColumn="32">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="1" column="6" lastLine="1" lastColumn="28">
| <DeclarationExpression line="1" column="6" lastLine="1" lastColumn="15" token="=">
| <VariableExpression line="1" column="10" lastLine="1" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="1" column="14" lastLine="1" lastColumn="15" value="0"/>
@@ -15997,7 +16081,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="1" column="30" lastLine="1" lastColumn="32"/>
| </ForStatement>
| <ForStatement line="2" column="1" lastLine="4" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="2" column="6" lastLine="2" lastColumn="28">
| <DeclarationExpression line="2" column="6" lastLine="2" lastColumn="15" token="=">
| <VariableExpression line="2" column="10" lastLine="2" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="2" column="14" lastLine="2" lastColumn="15" value="0"/>
@@ -16008,7 +16092,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="2" column="30" lastLine="4" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="5" column="1" lastLine="7" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="5" column="6" lastLine="5" lastColumn="28">
| <DeclarationExpression line="5" column="6" lastLine="5" lastColumn="15" token="=">
| <VariableExpression line="5" column="10" lastLine="5" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="5" column="14" lastLine="5" lastColumn="15" value="0"/>
@@ -16019,7 +16103,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="6" column="1" lastLine="7" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="8" column="1" lastLine="12" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="8" column="6" lastLine="10" lastColumn="11">
| <DeclarationExpression line="8" column="6" lastLine="8" lastColumn="15" token="=">
| <VariableExpression line="8" column="10" lastLine="8" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="8" column="14" lastLine="8" lastColumn="15" value="0"/>
@@ -16030,7 +16114,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="11" column="1" lastLine="12" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="13" column="1" lastLine="15" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="13" column="5" lastLine="13" lastColumn="7">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -16038,7 +16122,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="13" column="9" lastLine="15" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="16" column="1" lastLine="18" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="16" column="5" lastLine="16" lastColumn="16">
| <DeclarationExpression line="16" column="5" lastLine="16" lastColumn="14" token="=">
| <VariableExpression line="16" column="9" lastLine="16" lastColumn="10" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="16" column="13" lastLine="16" lastColumn="14" value="0"/>
@@ -16049,7 +16133,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="16" column="18" lastLine="18" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="19" column="1" lastLine="21" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="19" column="5" lastLine="19" lastColumn="11">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| <ConstantExpression line="19" column="6" lastLine="19" lastColumn="10" value="true"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -16057,7 +16141,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="19" column="13" lastLine="21" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="22" column="1" lastLine="24" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="22" column="5" lastLine="22" lastColumn="12">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| <ConstantExpression line="22" column="7" lastLine="22" lastColumn="12" value="false"/>
@@ -16065,7 +16149,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="22" column="14" lastLine="24" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="26" column="1" lastLine="28" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="26" column="6" lastLine="26" lastColumn="28">
| <DeclarationExpression line="26" column="6" lastLine="26" lastColumn="15" token="=">
| <VariableExpression line="26" column="10" lastLine="26" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="26" column="14" lastLine="26" lastColumn="15" value="0"/>
@@ -16081,7 +16165,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="26" column="30" lastLine="28" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="30" column="1" lastLine="32" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="30" column="6" lastLine="30" lastColumn="24">
| <BinaryExpression line="30" column="6" lastLine="30" lastColumn="11" token="=">
| <VariableExpression line="30" column="6" lastLine="30" lastColumn="7" name="i"/>
| <ConstantExpression line="30" column="10" lastLine="30" lastColumn="11" value="0"/>
@@ -16097,7 +16181,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="30" column="26" lastLine="32" lastColumn="2"/>
| </ForStatement>
| <ForStatement line="34" column="1" lastLine="36" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="34" column="5" lastLine="34" lastColumn="7">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -16227,7 +16311,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="21" column="1" lastLine="22" lastColumn="19">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="21" column="6" lastLine="21" lastColumn="8">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -16246,7 +16330,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="26" column="1" lastLine="26" lastColumn="25">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="26" column="6" lastLine="26" lastColumn="23">
| <BinaryExpression line="26" column="6" lastLine="26" lastColumn="11" token="=">
| <VariableExpression line="26" column="6" lastLine="26" lastColumn="7" name="i"/>
| <ConstantExpression line="26" column="10" lastLine="26" lastColumn="11" value="0"/>
@@ -16353,7 +16437,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="6" column="5" lastLine="9" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="6" column="10" lastLine="6" lastColumn="69">
| <DeclarationExpression line="6" column="10" lastLine="6" lastColumn="37" token="=">
| <TupleExpression line="6" column="14" lastLine="6" lastColumn="28">
| <VariableExpression line="6" column="15" lastLine="6" lastColumn="20" name="i" type="java.lang.Integer"/>
@@ -16417,7 +16501,7 @@ final class ParserPositiveSyntaxTest {
| </BinaryExpression>
| </ExpressionStatement>
| <ForStatement line="13" column="5" lastLine="16" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="13" column="10" lastLine="13" lastColumn="58">
| <ClosureListExpression line="13" column="10" lastLine="13" lastColumn="26">
| <DeclarationExpression line="13" column="10" lastLine="13" lastColumn="19" token="=">
| <VariableExpression line="13" column="14" lastLine="13" lastColumn="15" name="i" type="java.lang.Integer"/>
@@ -16485,7 +16569,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="23" column="5" lastLine="26" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="23" column="10" lastLine="23" lastColumn="57">
| <BinaryExpression line="23" column="10" lastLine="23" lastColumn="25" token="=">
| <TupleExpression line="23" column="10" lastLine="23" lastColumn="16">
| <VariableExpression line="23" column="11" lastLine="23" lastColumn="12" name="i"/>
@@ -16549,7 +16633,7 @@ final class ParserPositiveSyntaxTest {
| </BinaryExpression>
| </ExpressionStatement>
| <ForStatement line="30" column="5" lastLine="33" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="30" column="10" lastLine="30" lastColumn="58">
| <ClosureListExpression line="30" column="10" lastLine="30" lastColumn="26">
| <DeclarationExpression line="30" column="10" lastLine="30" lastColumn="19" token="=">
| <VariableExpression line="30" column="14" lastLine="30" lastColumn="15" name="i" type="java.lang.Integer"/>
@@ -16676,7 +16760,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="6" column="5" lastLine="8" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="6" column="10" lastLine="6" lastColumn="38">
| <ClosureListExpression line="6" column="10" lastLine="6" lastColumn="26">
| <DeclarationExpression line="6" column="10" lastLine="6" lastColumn="19" token="=">
| <VariableExpression line="6" column="14" lastLine="6" lastColumn="15" name="i" type="java.lang.Integer"/>
@@ -16731,7 +16815,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="14" column="5" lastLine="17" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="14" column="10" lastLine="14" lastColumn="39">
| <ClosureListExpression line="14" column="10" lastLine="14" lastColumn="22">
| <BinaryExpression line="14" column="10" lastLine="14" lastColumn="15" token="=">
| <VariableExpression line="14" column="10" lastLine="14" lastColumn="11" name="i"/>
@@ -16789,7 +16873,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="24" column="5" lastLine="26" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="24" column="10" lastLine="24" lastColumn="38">
| <ClosureListExpression line="24" column="10" lastLine="24" lastColumn="26">
| <DeclarationExpression line="24" column="10" lastLine="24" lastColumn="19" token="=">
| <VariableExpression line="24" column="14" lastLine="24" lastColumn="15" name="i" type="java.lang.Integer"/>
@@ -16844,7 +16928,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="32" column="5" lastLine="35" lastColumn="6">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="32" column="10" lastLine="32" lastColumn="39">
| <ClosureListExpression line="32" column="10" lastLine="32" lastColumn="22">
| <BinaryExpression line="32" column="10" lastLine="32" lastColumn="15" token="=">
| <VariableExpression line="32" column="10" lastLine="32" lastColumn="11" name="i"/>
@@ -17673,7 +17757,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="27" column="1" lastLine="29" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="27" column="13" lastLine="27" lastColumn="35">
| <DeclarationExpression line="27" column="13" lastLine="27" lastColumn="22" token="=">
| <VariableExpression line="27" column="17" lastLine="27" lastColumn="18" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="27" column="21" lastLine="27" lastColumn="22" value="0"/>
@@ -17691,7 +17775,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="31" column="1" lastLine="33" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="31" column="20" lastLine="31" lastColumn="42">
| <DeclarationExpression line="31" column="20" lastLine="31" lastColumn="29" token="=">
| <VariableExpression line="31" column="24" lastLine="31" lastColumn="25" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="31" column="28" lastLine="31" lastColumn="29" value="0"/>
@@ -17709,7 +17793,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="35" column="1" lastLine="39" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="37" column="6" lastLine="37" lastColumn="28">
| <DeclarationExpression line="37" column="6" lastLine="37" lastColumn="15" token="=">
| <VariableExpression line="37" column="10" lastLine="37" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="37" column="14" lastLine="37" lastColumn="15" value="0"/>
@@ -17982,7 +18066,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="21" column="1" lastLine="29" lastColumn="2">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="27" column="6" lastLine="27" lastColumn="27">
| <DeclarationExpression line="27" column="6" lastLine="27" lastColumn="15" token="=">
| <VariableExpression line="27" column="10" lastLine="27" lastColumn="11" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="27" column="14" lastLine="27" lastColumn="15" value="0"/>
@@ -22754,6 +22838,13 @@ final class ParserPositiveSyntaxTest {
| </AssertStatement>
| </BlockStatement>
| <ClassNode line="6" column="1" lastLine="20" lastColumn="2" kind="class" name="Resource" implements="Closeable">
+ | <PropertyNode line="7" column="5" lastLine="7" lastColumn="19" name="resourceId" type="int" modifiers="public"/>
+ | <PropertyNode line="8" column="5" lastLine="8" lastColumn="34" name="closedResourceIds" type="java.lang.Object" modifiers="public static">
+ | <ListExpression line="8" column="32" lastLine="8" lastColumn="34"/>
+ | </PropertyNode>
+ | <PropertyNode line="9" column="5" lastLine="9" lastColumn="37" name="exMsg" type="java.lang.Object" modifiers="public static">
+ | <ConstantExpression line="9" column="20" lastLine="9" lastColumn="37" value="failed to close"/>
+ | </PropertyNode>
| <ConstructorNode line="11" column="5" lastLine="13" lastColumn="6" name="<init>">
| <Parameter line="11" column="21" lastLine="11" lastColumn="35" name="resourceId" type="int"/>
| <BlockStatement line="11" column="37" lastLine="13" lastColumn="6">
@@ -27732,6 +27823,13 @@ final class ParserPositiveSyntaxTest {
| </AssertStatement>
| </BlockStatement>
| <ClassNode line="6" column="1" lastLine="20" lastColumn="2" kind="class" name="Resource" implements="Closeable">
+ | <PropertyNode line="7" column="5" lastLine="7" lastColumn="19" name="resourceId" type="int" modifiers="public"/>
+ | <PropertyNode line="8" column="5" lastLine="8" lastColumn="34" name="closedResourceIds" type="java.lang.Object" modifiers="public static">
+ | <ListExpression line="8" column="32" lastLine="8" lastColumn="34"/>
+ | </PropertyNode>
+ | <PropertyNode line="9" column="5" lastLine="9" lastColumn="37" name="exMsg" type="java.lang.Object" modifiers="public static">
+ | <ConstantExpression line="9" column="20" lastLine="9" lastColumn="37" value="failed to close"/>
+ | </PropertyNode>
| <ConstructorNode line="11" column="5" lastLine="13" lastColumn="6" name="<init>">
| <Parameter line="11" column="21" lastLine="11" lastColumn="35" name="resourceId" type="int"/>
| <BlockStatement line="11" column="37" lastLine="13" lastColumn="6">
@@ -30914,7 +31012,10 @@ final class ParserPositiveSyntaxTest {
| </MethodCallExpression>
| </ExpressionStatement>
| </BlockStatement>
- | <ClassNode line="3" column="1" lastLine="6" lastColumn="2" kind="class" name="SpecialSafeIndex"/>
+ | <ClassNode line="3" column="1" lastLine="6" lastColumn="2" kind="class" name="SpecialSafeIndex">
+ | <PropertyNode line="4" column="5" lastLine="4" lastColumn="16" name="name" type="String" modifiers="public"/>
+ | <PropertyNode line="5" column="5" lastLine="5" lastColumn="20" name="location" type="String" modifiers="public"/>
+ | </ClassNode>
| <AnnotationNode line="8" column="1" lastLine="8" lastColumn="15" class="CompileStatic"/>
| <MethodNode line="8" column="1" lastLine="13" lastColumn="2" name="csSpecialSafeIndex" returnType="java.lang.Object">
| <BlockStatement line="9" column="26" lastLine="13" lastColumn="2">
@@ -31392,7 +31493,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="18" column="1" lastLine="18" lastColumn="21" token="=">
| <VariableExpression line="18" column="5" lastLine="18" lastColumn="6" name="p"/>
| <ConstructorCallExpression line="18" column="9" lastLine="18" lastColumn="21" type="Person">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="18" column="19" lastLine="18" lastColumn="21"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -31514,7 +31615,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="35" column="1" lastLine="35" lastColumn="16" token="=">
| <VariableExpression line="35" column="5" lastLine="35" lastColumn="6" name="c"/>
| <ConstructorCallExpression line="35" column="9" lastLine="35" lastColumn="16" type="C">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="35" column="14" lastLine="35" lastColumn="16"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -32922,7 +33023,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </WhileStatement>
| <ForStatement line="98" column="1" lastLine="99" lastColumn="18">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="98" column="5" lastLine="98" lastColumn="7">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -32935,7 +33036,7 @@ final class ParserPositiveSyntaxTest {
| </ExpressionStatement>
| </ForStatement>
| <ForStatement line="101" column="1" lastLine="102" lastColumn="22">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="101" column="5" lastLine="101" lastColumn="7">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -32956,7 +33057,7 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| </ForStatement>
| <ForStatement line="104" column="1" lastLine="105" lastColumn="26">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="104" column="5" lastLine="104" lastColumn="7">
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
| < line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
@@ -33420,12 +33521,31 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="27" column="1" lastLine="27" lastColumn="17" class="Test5" members="a,b"/>
| <AnnotationNode line="28" column="1" lastLine="28" lastColumn="17" class="Test6" members="a,b"/>
| <ClassNode line="21" column="1" lastLine="45" lastColumn="2" kind="class" name="M" generics="<T extends A & B & C>" extends="A" implements="X,Y,Z"/>
- | <ClassNode line="49" column="1" lastLine="51" lastColumn="2" kind="class" name="OutputTransforms"/>
- | <ClassNode line="53" column="1" lastLine="55" lastColumn="2" kind="class" name="OutputTransforms2"/>
+ | <ClassNode line="49" column="1" lastLine="51" lastColumn="2" kind="class" name="OutputTransforms">
+ | <PropertyNode line="50" column="9" lastLine="50" lastColumn="63" name="localTransforms" type="java.lang.Object" modifiers="public static final">
+ | <MethodCallExpression line="50" column="41" lastLine="50" lastColumn="63" implicitThis="true">
+ | <ConstantExpression line="50" column="41" lastLine="50" lastColumn="61" value="loadOutputTransforms"/>
+ | <ArgumentListExpression line="50" column="61" lastLine="50" lastColumn="63"/>
+ | </MethodCallExpression>
+ | </PropertyNode>
+ | </ClassNode>
+ | <ClassNode line="53" column="1" lastLine="55" lastColumn="2" kind="class" name="OutputTransforms2">
+ | <AnnotationNode line="54" column="9" lastLine="54" lastColumn="14" class="Lazy"/>
+ | <PropertyNode line="54" column="9" lastLine="54" lastColumn="63" name="localTransforms" type="java.lang.Object" modifiers="public static">
+ | <MethodCallExpression line="54" column="41" lastLine="54" lastColumn="63" implicitThis="true">
+ | <ConstantExpression line="54" column="41" lastLine="54" lastColumn="61" value="loadOutputTransforms"/>
+ | <ArgumentListExpression line="54" column="61" lastLine="54" lastColumn="63"/>
+ | </MethodCallExpression>
+ | </PropertyNode>
+ | </ClassNode>
| <ClassNode line="57" column="1" lastLine="60" lastColumn="2" kind="class" name="XX">
| <FieldNode line="59" column="9" lastLine="59" lastColumn="22" name="x" type="java.lang.Object" modifiers="private">
| <ConstantExpression line="59" column="21" lastLine="59" lastColumn="22" value="1"/>
| </FieldNode>
+ | <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.CompileStatic"/>
+ | <PropertyNode line="58" column="9" lastLine="58" lastColumn="14" name="x" type="java.lang.Object" modifiers="public">
+ | <ConstantExpression line="59" column="21" lastLine="59" lastColumn="22" value="1"/>
+ | </PropertyNode>
| </ClassNode>
| <ClassNode line="47" column="1" lastLine="47" lastColumn="11" kind="class" name="a"/>
|</Module>'''.stripMargin())
@@ -33791,6 +33911,30 @@ final class ParserPositiveSyntaxTest {
| <ConstantExpression line="9" column="36" lastLine="9" lastColumn="44" value="field2"/>
| </FieldNode>
| <FieldNode line="21" column="5" lastLine="21" lastColumn="49" name="protectedStaticDefField" type="java.lang.Object" modifiers="protected static"/>
+ | <PropertyNode line="10" column="5" lastLine="10" lastColumn="24" name="someProperty" type="String" modifiers="public"/>
+ | <PropertyNode line="11" column="5" lastLine="11" lastColumn="43" name="someProperty2" type="String" modifiers="public">
+ | <ConstantExpression line="11" column="28" lastLine="11" lastColumn="43" value="someProperty2"/>
+ | </PropertyNode>
+ | <PropertyNode line="12" column="5" lastLine="12" lastColumn="43" name="someProperty3" type="String" modifiers="public">
+ | <ConstantExpression line="12" column="28" lastLine="12" lastColumn="43" value="someProperty3"/>
+ | </PropertyNode>
+ | <PropertyNode line="13" column="13" lastLine="13" lastColumn="44" name="someProperty4" type="String" modifiers="public">
+ | <ConstantExpression line="13" column="29" lastLine="13" lastColumn="44" value="someProperty4"/>
+ | </PropertyNode>
+ | <PropertyNode line="14" column="5" lastLine="14" lastColumn="58" name="someProperty5" type="String" modifiers="public"/>
+ | <PropertyNode line="14" column="27" lastLine="14" lastColumn="58" name="someProperty6" type="String" modifiers="public">
+ | <ConstantExpression line="14" column="43" lastLine="14" lastColumn="58" value="someProperty6"/>
+ | </PropertyNode>
+ | <PropertyNode line="15" column="5" lastLine="15" lastColumn="49" name="someProperty7" type="String" modifiers="public final">
+ | <ConstantExpression line="15" column="34" lastLine="15" lastColumn="49" value="someProperty7"/>
+ | </PropertyNode>
+ | <PropertyNode line="16" column="5" lastLine="16" lastColumn="56" name="someProperty8" type="String" modifiers="public static final">
+ | <ConstantExpression line="16" column="41" lastLine="16" lastColumn="56" value="someProperty8"/>
+ | </PropertyNode>
+ | <AnnotationNode line="18" column="5" lastLine="18" lastColumn="11" class="Test3"/>
+ | <PropertyNode line="18" column="5" lastLine="19" lastColumn="56" name="someProperty9" type="String" modifiers="public static final">
+ | <ConstantExpression line="19" column="41" lastLine="19" lastColumn="56" value="someProperty9"/>
+ | </PropertyNode>
| </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
@@ -33998,7 +34142,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="22" column="40" lastLine="28" lastColumn="10">
| <ExpressionStatement line="23" column="13" lastLine="27" lastColumn="14">
| <ConstructorCallExpression line="23" column="13" lastLine="27" lastColumn="14" type="AA$ProtectedFinalInner$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="23" column="18" lastLine="23" lastColumn="20"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34054,7 +34198,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="-1" column="-1" lastLine="-1" lastColumn="-1">
| <ExpressionStatement line="1" column="1" lastLine="1" lastColumn="11">
| <ConstructorCallExpression line="1" column="1" lastLine="1" lastColumn="11" type="test$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="1" column="6" lastLine="1" lastColumn="8"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="2" column="1" lastLine="16" lastColumn="2">
@@ -34071,17 +34215,17 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="19" column="26" lastLine="26" lastColumn="6">
| <ExpressionStatement line="20" column="9" lastLine="20" lastColumn="25">
| <ConstructorCallExpression line="20" column="9" lastLine="20" lastColumn="25" type="OuterAA$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="20" column="20" lastLine="20" lastColumn="22"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="21" column="9" lastLine="24" lastColumn="11">
| <ConstructorCallExpression line="21" column="9" lastLine="24" lastColumn="11" type="OuterAA$2" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="21" column="20" lastLine="21" lastColumn="22"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="25" column="9" lastLine="25" lastColumn="25">
| <ConstructorCallExpression line="25" column="9" lastLine="25" lastColumn="25" type="OuterAA$3" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="25" column="20" lastLine="25" lastColumn="22"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34094,12 +34238,12 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="21" column="24" lastLine="24" lastColumn="10">
| <ExpressionStatement line="22" column="13" lastLine="22" lastColumn="29">
| <ConstructorCallExpression line="22" column="13" lastLine="22" lastColumn="29" type="OuterAA$2$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="22" column="24" lastLine="22" lastColumn="26"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="23" column="13" lastLine="23" lastColumn="29">
| <ConstructorCallExpression line="23" column="13" lastLine="23" lastColumn="29" type="OuterAA$2$2" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="23" column="24" lastLine="23" lastColumn="26"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34115,12 +34259,12 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="3" column="23" lastLine="15" lastColumn="6">
| <ExpressionStatement line="4" column="9" lastLine="4" lastColumn="19">
| <ConstructorCallExpression line="4" column="9" lastLine="4" lastColumn="19" type="test$2$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="4" column="14" lastLine="4" lastColumn="16"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="5" column="9" lastLine="14" lastColumn="10">
| <ConstructorCallExpression line="5" column="9" lastLine="14" lastColumn="10" type="test$2$2" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="5" column="14" lastLine="5" lastColumn="16"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34133,7 +34277,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="6" column="13" lastLine="13" lastColumn="14">
| <ExpressionStatement line="7" column="17" lastLine="12" lastColumn="18">
| <ConstructorCallExpression line="7" column="17" lastLine="12" lastColumn="18" type="test$2$2$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="7" column="22" lastLine="7" lastColumn="24"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34146,12 +34290,12 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="8" column="21" lastLine="11" lastColumn="22">
| <ExpressionStatement line="9" column="25" lastLine="9" lastColumn="35">
| <ConstructorCallExpression line="9" column="25" lastLine="9" lastColumn="35" type="test$2$2$1$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="9" column="30" lastLine="9" lastColumn="32"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| <ExpressionStatement line="10" column="25" lastLine="10" lastColumn="35">
| <ConstructorCallExpression line="10" column="25" lastLine="10" lastColumn="35" type="test$2$2$1$2" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="10" column="30" lastLine="10" lastColumn="32"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -34175,6 +34319,7 @@ final class ParserPositiveSyntaxTest {
| <PackageNode line="1" column="1" lastLine="1" lastColumn="13" name="core"/>
| <ClassNode line="3" column="1" lastLine="7" lastColumn="2" kind="class" name="À">
| <FieldNode line="4" column="5" lastLine="4" lastColumn="15" name="f" type="À" modifiers="public"/>
+ | <PropertyNode line="5" column="12" lastLine="5" lastColumn="15" name="p" type="À" modifiers="public"/>
| <MethodNode line="6" column="5" lastLine="6" lastColumn="20" name="m" modifiers="static" returnType="À">
| <BlockStatement line="6" column="18" lastLine="6" lastColumn="20"/>
| </MethodNode>
@@ -34294,28 +34439,28 @@ final class ParserPositiveSyntaxTest {
| <PackageNode line="1" column="1" lastLine="1" lastColumn="13" name="core"/>
| <ImportNode line="3" column="1" lastLine="3" lastColumn="29" type="java.sql.SQLException"/>
| <ClassNode line="5" column="1" lastLine="42" lastColumn="2" kind="interface" name="AA1">
- | <FieldNode line="6" column="9" lastLine="-1" lastColumn="-1" name="a" type="int" modifiers="public static final">
+ | <FieldNode line="6" column="9" lastLine="6" lastColumn="14" name="a" type="int" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
| </FieldNode>
- | <FieldNode line="7" column="9" lastLine="-1" lastColumn="-1" name="b" type="long" modifiers="public static final">
+ | <FieldNode line="7" column="9" lastLine="7" lastColumn="15" name="b" type="long" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
| </FieldNode>
- | <FieldNode line="8" column="9" lastLine="-1" lastColumn="-1" name="c" type="double" modifiers="public static final">
+ | <FieldNode line="8" column="9" lastLine="8" lastColumn="17" name="c" type="double" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0.0"/>
| </FieldNode>
- | <FieldNode line="9" column="9" lastLine="-1" lastColumn="-1" name="d" type="char" modifiers="public static final">
+ | <FieldNode line="9" column="9" lastLine="9" lastColumn="15" name="d" type="char" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="\u0000"/>
| </FieldNode>
- | <FieldNode line="10" column="9" lastLine="-1" lastColumn="-1" name="e" type="short" modifiers="public static final">
+ | <FieldNode line="10" column="9" lastLine="10" lastColumn="16" name="e" type="short" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
| </FieldNode>
- | <FieldNode line="11" column="9" lastLine="-1" lastColumn="-1" name="f" type="byte" modifiers="public static final">
+ | <FieldNode line="11" column="9" lastLine="11" lastColumn="15" name="f" type="byte" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0"/>
| </FieldNode>
- | <FieldNode line="12" column="9" lastLine="-1" lastColumn="-1" name="g" type="float" modifiers="public static final">
+ | <FieldNode line="12" column="9" lastLine="12" lastColumn="16" name="g" type="float" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="0.0"/>
| </FieldNode>
- | <FieldNode line="13" column="9" lastLine="-1" lastColumn="-1" name="h" type="boolean" modifiers="public static final">
+ | <FieldNode line="13" column="9" lastLine="13" lastColumn="18" name="h" type="boolean" modifiers="public static final">
| <ConstantExpression line="-1" column="-1" lastLine="-1" lastColumn="-1" value="false"/>
| </FieldNode>
| <FieldNode line="14" column="9" lastLine="14" lastColumn="17" name="i" type="String" modifiers="public static final"/>
@@ -34365,7 +34510,7 @@ final class ParserPositiveSyntaxTest {
| <ClassNode line="5" column="1" lastLine="7" lastColumn="2" kind="interface" name="Koo2">
| <FieldNode line="6" column="5" lastLine="6" lastColumn="53" name="INNER" type="Inner" modifiers="public static final">
| <ConstructorCallExpression line="6" column="39" lastLine="6" lastColumn="53" type="Koo2$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="6" column="48" lastLine="6" lastColumn="50"/>
| </ConstructorCallExpression>
| </FieldNode>
| </ClassNode>
@@ -34722,6 +34867,7 @@ final class ParserPositiveSyntaxTest {
| <FieldNode line="4" column="5" lastLine="4" lastColumn="6" name="B" type="E1" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="4" column="7" lastLine="4" lastColumn="8" name="C" type="E1" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="5" column="5" lastLine="5" lastColumn="6" name="D" type="E1" modifiers="public static final" enumConstant="true"/>
+ | <PropertyNode line="7" column="5" lastLine="7" lastColumn="13" name="prop" type="java.lang.Object" modifiers="public"/>
| <MethodNode line="6" column="5" lastLine="6" lastColumn="27" name="proc" modifiers="private" returnType="void">
| <BlockStatement line="6" column="25" lastLine="6" lastColumn="27"/>
| </MethodNode>
@@ -34729,6 +34875,7 @@ final class ParserPositiveSyntaxTest {
| <ClassNode line="59" column="1" lastLine="66" lastColumn="2" kind="enum" name="E10" extends="java.lang.Enum<E10>">
| <FieldNode line="60" column="5" lastLine="60" lastColumn="9" name="X" type="E10" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="60" column="11" lastLine="60" lastColumn="15" name="Y" type="E10" modifiers="public static final" enumConstant="true"/>
+ | <PropertyNode line="62" column="5" lastLine="62" lastColumn="17" name="value" type="Object" modifiers="public"/>
| <ConstructorNode line="63" column="5" lastLine="65" lastColumn="6" name="<init>">
| <Parameter line="63" column="9" lastLine="63" lastColumn="14" name="value"/>
| <BlockStatement line="63" column="16" lastLine="65" lastColumn="6">
@@ -34858,6 +35005,9 @@ final class ParserPositiveSyntaxTest {
| <FieldNode line="15" column="5" lastLine="15" lastColumn="30" name="age" type="int" modifiers="private final">
| <ConstantExpression line="15" column="29" lastLine="15" lastColumn="30" value="2"/>
| </FieldNode>
+ | <PropertyNode line="16" column="5" lastLine="16" lastColumn="31" name="title" type="String" modifiers="public final">
+ | <ConstantExpression line="16" column="24" lastLine="16" lastColumn="31" value="title"/>
+ | </PropertyNode>
| <ConstructorNode line="17" column="5" lastLine="17" lastColumn="24" name="<init>">
| <Parameter line="17" column="15" lastLine="17" lastColumn="20" name="x" type="int"/>
| <BlockStatement line="17" column="22" lastLine="17" lastColumn="24"/>
@@ -34951,6 +35101,7 @@ final class ParserPositiveSyntaxTest {
| <ClassNode line="50" column="1" lastLine="56" lastColumn="2" kind="enum" name="E9" extends="java.lang.Enum<E9>">
| <FieldNode line="51" column="5" lastLine="51" lastColumn="9" name="A" type="E9" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="51" column="11" lastLine="51" lastColumn="15" name="B" type="E9" modifiers="public static final" enumConstant="true"/>
+ | <PropertyNode line="52" column="5" lastLine="52" lastColumn="17" name="value" type="Object" modifiers="public"/>
| <ConstructorNode line="53" column="5" lastLine="55" lastColumn="6" name="<init>">
| <Parameter line="53" column="8" lastLine="53" lastColumn="13" name="value"/>
| <BlockStatement line="53" column="15" lastLine="55" lastColumn="6">
@@ -35025,6 +35176,7 @@ final class ParserPositiveSyntaxTest {
| <FieldNode line="159" column="5" lastLine="159" lastColumn="24" name="DIAMONDS" type="Suit" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="160" column="5" lastLine="160" lastColumn="22" name="HEARTS" type="Suit" modifiers="public static final" enumConstant="true"/>
| <FieldNode line="161" column="5" lastLine="161" lastColumn="24" name="SPADES" type="Suit" modifiers="public static final" enumConstant="true"/>
+ | <PropertyNode line="163" column="5" lastLine="163" lastColumn="22" name="color" type="Color" modifiers="public final"/>
| <ConstructorNode line="164" column="5" lastLine="166" lastColumn="6" name="<init>">
| <Parameter line="164" column="10" lastLine="164" lastColumn="21" name="color" type="Color"/>
| <BlockStatement line="164" column="23" lastLine="166" lastColumn="6">
@@ -35742,6 +35894,30 @@ final class ParserPositiveSyntaxTest {
| <ConstantExpression line="9" column="36" lastLine="9" lastColumn="44" value="field2"/>
| </FieldNode>
| <FieldNode line="21" column="5" lastLine="21" lastColumn="49" name="protectedStaticDefField" type="java.lang.Object" modifiers="protected static"/>
+ | <PropertyNode line="10" column="5" lastLine="10" lastColumn="24" name="someProperty" type="String" modifiers="public"/>
+ | <PropertyNode line="11" column="5" lastLine="11" lastColumn="43" name="someProperty2" type="String" modifiers="public">
+ | <ConstantExpression line="11" column="28" lastLine="11" lastColumn="43" value="someProperty2"/>
+ | </PropertyNode>
+ | <PropertyNode line="12" column="5" lastLine="12" lastColumn="43" name="someProperty3" type="String" modifiers="public">
+ | <ConstantExpression line="12" column="28" lastLine="12" lastColumn="43" value="someProperty3"/>
+ | </PropertyNode>
+ | <PropertyNode line="13" column="13" lastLine="13" lastColumn="44" name="someProperty4" type="String" modifiers="public">
+ | <ConstantExpression line="13" column="29" lastLine="13" lastColumn="44" value="someProperty4"/>
+ | </PropertyNode>
+ | <PropertyNode line="14" column="5" lastLine="14" lastColumn="58" name="someProperty5" type="String" modifiers="public"/>
+ | <PropertyNode line="14" column="27" lastLine="14" lastColumn="58" name="someProperty6" type="String" modifiers="public">
+ | <ConstantExpression line="14" column="43" lastLine="14" lastColumn="58" value="someProperty6"/>
+ | </PropertyNode>
+ | <PropertyNode line="15" column="5" lastLine="15" lastColumn="49" name="someProperty7" type="String" modifiers="public final">
+ | <ConstantExpression line="15" column="34" lastLine="15" lastColumn="49" value="someProperty7"/>
+ | </PropertyNode>
+ | <PropertyNode line="16" column="5" lastLine="16" lastColumn="56" name="someProperty8" type="String" modifiers="public static final">
+ | <ConstantExpression line="16" column="41" lastLine="16" lastColumn="56" value="someProperty8"/>
+ | </PropertyNode>
+ | <AnnotationNode line="18" column="5" lastLine="18" lastColumn="11" class="Test3"/>
+ | <PropertyNode line="18" column="5" lastLine="19" lastColumn="56" name="someProperty9" type="String" modifiers="public static final">
+ | <ConstantExpression line="19" column="41" lastLine="19" lastColumn="56" value="someProperty9"/>
+ | </PropertyNode>
| </ClassNode>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.Trait"/>
| <ClassNode line="24" column="1" lastLine="28" lastColumn="2" kind="trait" name="xx"/>
@@ -35780,7 +35956,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="21" column="1" lastLine="21" lastColumn="22" token="=">
| <VariableExpression line="21" column="5" lastLine="21" lastColumn="9" name="duck"/>
| <ConstructorCallExpression line="21" column="12" lastLine="21" lastColumn="22" type="Duck">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="21" column="20" lastLine="21" lastColumn="22"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -35899,7 +36075,10 @@ final class ParserPositiveSyntaxTest {
| </AssertStatement>
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
- | <ClassNode line="3" column="1" lastLine="3" lastColumn="43" kind="record" name="Fruit"/>
+ | <ClassNode line="3" column="1" lastLine="3" lastColumn="43" kind="record" name="Fruit">
+ | <PropertyNode line="3" column="14" lastLine="3" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="27" lastLine="3" lastColumn="39" name="price" type="double" modifiers="public final"/>
+ | </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
|package core
@@ -35951,6 +36130,8 @@ final class ParserPositiveSyntaxTest {
| </ClassNode>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="7" column="1" lastLine="12" lastColumn="2" kind="record" name="Fruit" implements="Eatable">
+ | <PropertyNode line="7" column="14" lastLine="7" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="7" column="27" lastLine="7" lastColumn="39" name="price" type="double" modifiers="public final"/>
| <AnnotationNode line="8" column="5" lastLine="8" lastColumn="14" class="Override"/>
| <MethodNode line="8" column="5" lastLine="11" lastColumn="6" name="eat" returnType="String">
| <BlockStatement line="9" column="18" lastLine="11" lastColumn="6">
@@ -35990,7 +36171,10 @@ final class ParserPositiveSyntaxTest {
| </ExpressionStatement>
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
- | <ClassNode line="3" column="1" lastLine="3" lastColumn="43" kind="record" name="Fruit"/>
+ | <ClassNode line="3" column="1" lastLine="3" lastColumn="43" kind="record" name="Fruit">
+ | <PropertyNode line="3" column="14" lastLine="3" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="27" lastLine="3" lastColumn="39" name="price" type="double" modifiers="public final"/>
+ | </ClassNode>
| <AnnotationNode line="5" column="1" lastLine="5" lastColumn="32" class="groovy.transform.CompileStatic"/>
| <MethodNode line="5" column="1" lastLine="10" lastColumn="2" name="test" returnType="void">
| <BlockStatement line="6" column="13" lastLine="10" lastColumn="2">
@@ -36065,6 +36249,8 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="3" column="1" lastLine="3" lastColumn="32" class="groovy.transform.CompileStatic"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="9" lastColumn="2" kind="record" name="Fruit">
+ | <PropertyNode line="4" column="14" lastLine="4" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="4" column="27" lastLine="4" lastColumn="39" name="price" type="double" modifiers="public final"/>
| <MethodNode line="5" column="5" lastLine="8" lastColumn="6" name="record" returnType="String">
| <BlockStatement line="5" column="21" lastLine="8" lastColumn="6">
| <ExpressionStatement line="6" column="9" lastLine="6" lastColumn="37">
@@ -36169,6 +36355,8 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="10" lastColumn="2" kind="record" name="Fruit">
+ | <PropertyNode line="3" column="14" lastLine="3" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="27" lastLine="3" lastColumn="39" name="price" type="double" modifiers="public final"/>
| <MethodNode line="4" column="5" lastLine="6" lastColumn="6" name="name" returnType="String">
| <BlockStatement line="4" column="19" lastLine="6" lastColumn="6">
| <ReturnStatement line="5" column="9" lastLine="5" lastColumn="20">
@@ -36221,6 +36409,8 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="3" column="1" lastLine="3" lastColumn="32" class="groovy.transform.CompileStatic"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="11" lastColumn="2" kind="record" name="Fruit">
+ | <PropertyNode line="4" column="14" lastLine="4" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="4" column="27" lastLine="4" lastColumn="39" name="price" type="double" modifiers="public final"/>
| <MethodNode line="5" column="5" lastLine="7" lastColumn="6" name="name" returnType="String">
| <BlockStatement line="5" column="19" lastLine="7" lastColumn="6">
| <ReturnStatement line="6" column="9" lastLine="6" lastColumn="20">
@@ -36329,6 +36519,8 @@ final class ParserPositiveSyntaxTest {
| <FieldNode line="4" column="5" lastLine="4" lastColumn="46" name="CONST_1" type="String" modifiers="public static final">
| <ConstantExpression line="4" column="42" lastLine="4" lastColumn="46" value="C1"/>
| </FieldNode>
+ | <PropertyNode line="3" column="14" lastLine="3" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="27" lastLine="3" lastColumn="39" name="price" type="double" modifiers="public final"/>
| <MethodNode line="6" column="5" lastLine="8" lastColumn="6" name="eat" returnType="String">
| <BlockStatement line="6" column="18" lastLine="8" lastColumn="6">
| <ReturnStatement line="7" column="9" lastLine="7" lastColumn="41">
@@ -36565,7 +36757,10 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.TupleConstructor" members="pre"/>
- | <ClassNode line="3" column="1" lastLine="8" lastColumn="2" kind="record" name="Person"/>
+ | <ClassNode line="3" column="1" lastLine="8" lastColumn="2" kind="record" name="Person">
+ | <PropertyNode line="3" column="15" lastLine="3" lastColumn="26" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="28" lastLine="3" lastColumn="35" name="age" type="int" modifiers="public final"/>
+ | </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
|package core
@@ -36792,7 +36987,10 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="3" column="1" lastLine="3" lastColumn="32" class="groovy.transform.CompileStatic"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.TupleConstructor" members="pre"/>
- | <ClassNode line="3" column="1" lastLine="9" lastColumn="2" kind="record" name="Person"/>
+ | <ClassNode line="3" column="1" lastLine="9" lastColumn="2" kind="record" name="Person">
+ | <PropertyNode line="4" column="15" lastLine="4" lastColumn="26" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="4" column="28" lastLine="4" lastColumn="35" name="age" type="int" modifiers="public final"/>
+ | </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
|package core
@@ -36988,6 +37186,9 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="3" column="1" lastLine="3" lastColumn="51" class="groovy.transform.TupleConstructor" members="defaults,pre"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="14" lastColumn="2" kind="record" name="Point">
+ | <PropertyNode line="4" column="14" lastLine="4" lastColumn="19" name="x" type="int" modifiers="public final"/>
+ | <PropertyNode line="4" column="21" lastLine="4" lastColumn="26" name="y" type="int" modifiers="public final"/>
+ | <PropertyNode line="4" column="28" lastLine="4" lastColumn="40" name="color" type="String" modifiers="public final"/>
| <ConstructorNode line="11" column="5" lastLine="13" lastColumn="6" name="<init>">
| <Parameter line="11" column="18" lastLine="11" lastColumn="23" name="x" type="int"/>
| <Parameter line="11" column="25" lastLine="11" lastColumn="30" name="y" type="int"/>
@@ -37134,6 +37335,9 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="3" column="1" lastLine="3" lastColumn="71" class="groovy.transform.TupleConstructor" members="defaults,namedVariant,pre"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="14" lastColumn="2" kind="record" name="Point">
+ | <PropertyNode line="4" column="14" lastLine="4" lastColumn="19" name="x" type="int" modifiers="public final"/>
+ | <PropertyNode line="4" column="21" lastLine="4" lastColumn="26" name="y" type="int" modifiers="public final"/>
+ | <PropertyNode line="4" column="28" lastLine="4" lastColumn="40" name="color" type="String" modifiers="public final"/>
| <ConstructorNode line="11" column="5" lastLine="13" lastColumn="6" name="<init>">
| <Parameter line="11" column="18" lastLine="11" lastColumn="23" name="x" type="int"/>
| <Parameter line="11" column="25" lastLine="11" lastColumn="30" name="y" type="int"/>
@@ -37284,6 +37488,9 @@ final class ParserPositiveSyntaxTest {
| <AnnotationNode line="4" column="1" lastLine="4" lastColumn="51" class="groovy.transform.TupleConstructor" members="defaults,pre"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <ClassNode line="3" column="1" lastLine="17" lastColumn="2" kind="record" name="Point">
+ | <PropertyNode line="5" column="14" lastLine="5" lastColumn="19" name="x" type="int" modifiers="public final"/>
+ | <PropertyNode line="5" column="21" lastLine="5" lastColumn="26" name="y" type="int" modifiers="public final"/>
+ | <PropertyNode line="5" column="28" lastLine="5" lastColumn="40" name="color" type="String" modifiers="public final"/>
| <ConstructorNode line="14" column="5" lastLine="16" lastColumn="6" name="<init>">
| <Parameter line="14" column="18" lastLine="14" lastColumn="23" name="x" type="int"/>
| <Parameter line="14" column="25" lastLine="14" lastColumn="30" name="y" type="int"/>
@@ -37357,7 +37564,10 @@ final class ParserPositiveSyntaxTest {
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.TupleConstructor" members="pre"/>
- | <ClassNode line="3" column="1" lastLine="8" lastColumn="2" kind="record" name="Fruit"/>
+ | <ClassNode line="3" column="1" lastLine="8" lastColumn="2" kind="record" name="Fruit">
+ | <PropertyNode line="3" column="14" lastLine="3" lastColumn="25" name="name" type="String" modifiers="public final"/>
+ | <PropertyNode line="3" column="27" lastLine="3" lastColumn="39" name="price" type="double" modifiers="public final"/>
+ | </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
|package core
@@ -37397,7 +37607,9 @@ final class ParserPositiveSyntaxTest {
| </AssertStatement>
| </BlockStatement>
| <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.RecordType"/>
- | <ClassNode line="3" column="1" lastLine="3" lastColumn="23" kind="record" name="R2"/>
+ | <ClassNode line="3" column="1" lastLine="3" lastColumn="23" kind="record" name="R2">
+ | <PropertyNode line="3" column="11" lastLine="3" lastColumn="18" name="x" type="int[]" modifiers="public final"/>
+ | </ClassNode>
|</Module>'''.stripMargin())
}
@@ -37448,7 +37660,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="27" column="1" lastLine="27" lastColumn="21" token="=">
| <VariableExpression line="27" column="5" lastLine="27" lastColumn="6" name="c"/>
| <ConstructorCallExpression line="27" column="9" lastLine="27" lastColumn="21" type="Circle">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="27" column="19" lastLine="27" lastColumn="21"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -37456,7 +37668,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="28" column="1" lastLine="28" lastColumn="24" token="=">
| <VariableExpression line="28" column="5" lastLine="28" lastColumn="6" name="r"/>
| <ConstructorCallExpression line="28" column="9" lastLine="28" lastColumn="24" type="Rectangle">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="28" column="22" lastLine="28" lastColumn="24"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -37464,7 +37676,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="29" column="1" lastLine="29" lastColumn="21" token="=">
| <VariableExpression line="29" column="5" lastLine="29" lastColumn="6" name="s"/>
| <ConstructorCallExpression line="29" column="9" lastLine="29" lastColumn="21" type="Square">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="29" column="19" lastLine="29" lastColumn="21"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -40096,7 +40308,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="7" column="1" lastLine="7" lastColumn="14" token="=">
| <VariableExpression line="7" column="3" lastLine="7" lastColumn="4" name="b" type="a"/>
| <ConstructorCallExpression line="7" column="7" lastLine="7" lastColumn="14" type="a">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="7" column="12" lastLine="7" lastColumn="14"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -40115,7 +40327,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="10" column="1" lastLine="10" lastColumn="31" token="=">
| <VariableExpression line="10" column="11" lastLine="10" lastColumn="13" name="b2" type="a<String>"/>
| <ConstructorCallExpression line="10" column="16" lastLine="10" lastColumn="31" type="a<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="10" column="29" lastLine="10" lastColumn="31"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -40153,7 +40365,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="16" column="1" lastLine="16" lastColumn="20" token="=">
| <VariableExpression line="16" column="8" lastLine="16" lastColumn="10" name="b4" type="core.a"/>
| <ConstructorCallExpression line="16" column="13" lastLine="16" lastColumn="20" type="a">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="16" column="18" lastLine="16" lastColumn="20"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -40172,7 +40384,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="19" column="1" lastLine="19" lastColumn="36" token="=">
| <VariableExpression line="19" column="16" lastLine="19" lastColumn="18" name="b5" type="core.a<String>"/>
| <ConstructorCallExpression line="19" column="21" lastLine="19" lastColumn="36" type="a<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="19" column="34" lastLine="19" lastColumn="36"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -40207,7 +40419,11 @@ final class ParserPositiveSyntaxTest {
| </BooleanExpression>
| </AssertStatement>
| </BlockStatement>
- | <ClassNode line="3" column="1" lastLine="5" lastColumn="2" kind="class" name="a" generics="<T>"/>
+ | <ClassNode line="3" column="1" lastLine="5" lastColumn="2" kind="class" name="a" generics="<T>">
+ | <PropertyNode line="4" column="5" lastLine="4" lastColumn="14" name="x" type="int" modifiers="public">
+ | <ConstantExpression line="4" column="13" lastLine="4" lastColumn="14" value="1"/>
+ | </PropertyNode>
+ | </ClassNode>
|</Module>'''.stripMargin())
expectAst('''\
|package core
@@ -40418,7 +40634,7 @@ final class ParserPositiveSyntaxTest {
| <BinaryExpression line="5" column="1" lastLine="5" lastColumn="12" token="=">
| <VariableExpression line="5" column="1" lastLine="5" lastColumn="2" name="b"/>
| <ConstructorCallExpression line="5" column="5" lastLine="5" lastColumn="12" type="B">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="5" column="10" lastLine="5" lastColumn="12"/>
| </ConstructorCallExpression>
| </BinaryExpression>
| </ExpressionStatement>
@@ -40440,7 +40656,7 @@ final class ParserPositiveSyntaxTest {
| <BinaryExpression line="9" column="1" lastLine="9" lastColumn="21" token="=">
| <VariableExpression line="9" column="1" lastLine="9" lastColumn="3" name="b2"/>
| <ConstructorCallExpression line="9" column="6" lastLine="9" lastColumn="21" type="B<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="9" column="19" lastLine="9" lastColumn="21"/>
| </ConstructorCallExpression>
| </BinaryExpression>
| </ExpressionStatement>
@@ -40484,7 +40700,7 @@ final class ParserPositiveSyntaxTest {
| <BinaryExpression line="17" column="1" lastLine="17" lastColumn="13" token="=">
| <VariableExpression line="17" column="1" lastLine="17" lastColumn="3" name="b4"/>
| <ConstructorCallExpression line="17" column="6" lastLine="17" lastColumn="13" type="B">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="17" column="11" lastLine="17" lastColumn="13"/>
| </ConstructorCallExpression>
| </BinaryExpression>
| </ExpressionStatement>
@@ -40506,7 +40722,7 @@ final class ParserPositiveSyntaxTest {
| <BinaryExpression line="21" column="1" lastLine="21" lastColumn="21" token="=">
| <VariableExpression line="21" column="1" lastLine="21" lastColumn="3" name="b5"/>
| <ConstructorCallExpression line="21" column="6" lastLine="21" lastColumn="21" type="B<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="21" column="19" lastLine="21" lastColumn="21"/>
| </ConstructorCallExpression>
| </BinaryExpression>
| </ExpressionStatement>
@@ -41525,7 +41741,7 @@ final class ParserPositiveSyntaxTest {
| <ConstantExpression line="15" column="8" lastLine="15" lastColumn="9" value="1"/>
| <PropertyExpression line="15" column="13" lastLine="15" lastColumn="34">
| <ConstructorCallExpression line="15" column="13" lastLine="15" lastColumn="30" type="FieldHolder">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="15" column="28" lastLine="15" lastColumn="30"/>
| </ConstructorCallExpression>
| <ConstantExpression line="15" column="31" lastLine="15" lastColumn="34" value="num"/>
| </PropertyExpression>
@@ -41538,7 +41754,7 @@ final class ParserPositiveSyntaxTest {
| <ConstantExpression line="16" column="8" lastLine="16" lastColumn="9" value="2"/>
| <PropertyExpression line="16" column="13" lastLine="16" lastColumn="35">
| <ConstructorCallExpression line="16" column="13" lastLine="16" lastColumn="31" type="FieldHolder2">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="16" column="29" lastLine="16" lastColumn="31"/>
| </ConstructorCallExpression>
| <ConstantExpression line="16" column="32" lastLine="16" lastColumn="35" value="num"/>
| </PropertyExpression>
@@ -41546,16 +41762,28 @@ final class ParserPositiveSyntaxTest {
| </BooleanExpression>
| </AssertStatement>
| </BlockStatement>
- | <ClassNode line="1" column="1" lastLine="3" lastColumn="2" kind="class" name="Base"/>
+ | <ClassNode line="1" column="1" lastLine="3" lastColumn="2" kind="class" name="Base">
+ | <PropertyNode line="2" column="5" lastLine="2" lastColumn="16" name="num" type="java.lang.Object" modifiers="public">
+ | <ConstantExpression line="2" column="15" lastLine="2" lastColumn="16" value="0"/>
+ | </PropertyNode>
+ | </ClassNode>
| <ClassNode line="5" column="1" lastLine="8" lastColumn="2" kind="class" name="FieldHolder" extends="Base">
| <FieldNode line="7" column="5" lastLine="7" lastColumn="20" name="num" type="java.lang.Object" modifiers="private">
| <ConstantExpression line="7" column="19" lastLine="7" lastColumn="20" value="1"/>
| </FieldNode>
+ | <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.CompileStatic"/>
+ | <PropertyNode line="6" column="5" lastLine="6" lastColumn="12" name="num" type="java.lang.Object" modifiers="public">
+ | <ConstantExpression line="7" column="19" lastLine="7" lastColumn="20" value="1"/>
+ | </PropertyNode>
| </ClassNode>
| <ClassNode line="10" column="1" lastLine="13" lastColumn="2" kind="class" name="FieldHolder2" extends="Base">
| <FieldNode line="11" column="5" lastLine="11" lastColumn="20" name="num" type="java.lang.Object" modifiers="private">
| <ConstantExpression line="11" column="19" lastLine="11" lastColumn="20" value="2"/>
| </FieldNode>
+ | <AnnotationNode line="-1" column="-1" lastLine="-1" lastColumn="-1" class="groovy.transform.CompileStatic"/>
+ | <PropertyNode line="12" column="5" lastLine="12" lastColumn="12" name="num" type="java.lang.Object" modifiers="public">
+ | <ConstantExpression line="11" column="19" lastLine="11" lastColumn="20" value="2"/>
+ | </PropertyNode>
| </ClassNode>
|</Module>'''.stripMargin())
}
@@ -42677,7 +42905,7 @@ final class ParserPositiveSyntaxTest {
| <VariableExpression line="44" column="20" lastLine="44" lastColumn="21" name="Y"/>
| <ConstantExpression line="44" column="22" lastLine="44" lastColumn="29" value="createX"/>
| <ConstructorCallExpression line="44" column="30" lastLine="44" lastColumn="37" type="Y">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="44" column="35" lastLine="44" lastColumn="37"/>
| </ConstructorCallExpression>
| </MethodCallExpression>
| <ConstantExpression line="44" column="39" lastLine="44" lastColumn="43" value="name"/>
@@ -42754,7 +42982,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="10" column="31" lastLine="12" lastColumn="6">
| <ReturnStatement line="11" column="9" lastLine="11" lastColumn="23">
| <ConstructorCallExpression line="11" column="16" lastLine="11" lastColumn="23" type="Y">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="11" column="21" lastLine="11" lastColumn="23"/>
| </ConstructorCallExpression>
| </ReturnStatement>
| </BlockStatement>
@@ -42863,6 +43091,7 @@ final class ParserPositiveSyntaxTest {
| </MethodNode>
| </ClassNode>
| <ClassNode line="2" column="5" lastLine="8" lastColumn="6" kind="class" name="Y$X">
+ | <PropertyNode line="3" column="9" lastLine="3" lastColumn="17" name="name" type="java.lang.Object" modifiers="public"/>
| <ConstructorNode line="5" column="9" lastLine="7" lastColumn="10" name="<init>">
| <Parameter line="5" column="18" lastLine="5" lastColumn="29" name="name" type="String"/>
| <BlockStatement line="5" column="31" lastLine="7" lastColumn="10">
@@ -46313,7 +46542,7 @@ final class ParserPositiveSyntaxTest {
| </DeclarationExpression>
| </ExpressionStatement>
| <ForStatement line="6" column="9" lastLine="11" lastColumn="10">
- | <ClosureListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1">
+ | <ClosureListExpression line="6" column="14" lastLine="6" lastColumn="39">
| <DeclarationExpression line="6" column="14" lastLine="6" lastColumn="25" token="=">
| <VariableExpression line="6" column="18" lastLine="6" lastColumn="19" name="i" type="java.lang.Integer"/>
| <ConstantExpression line="6" column="22" lastLine="6" lastColumn="25" value="100"/>
@@ -46411,7 +46640,7 @@ final class ParserPositiveSyntaxTest {
| <ConstantExpression line="9" column="8" lastLine="9" lastColumn="13" value="abc"/>
| <MethodCallExpression line="9" column="17" lastLine="9" lastColumn="37">
| <ConstructorCallExpression line="9" column="17" lastLine="9" lastColumn="26" type="Foo">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="9" column="24" lastLine="9" lastColumn="26"/>
| </ConstructorCallExpression>
| <ConstantExpression line="9" column="27" lastLine="9" lastColumn="30" value="foo"/>
| <ConstantExpression line="9" column="31" lastLine="9" lastColumn="36" value="abc"/>
@@ -46733,7 +46962,7 @@ final class ParserPositiveSyntaxTest {
| <BinaryExpression line="4" column="1" lastLine="4" lastColumn="16" token="=">
| <VariableExpression line="4" column="1" lastLine="4" lastColumn="4" name="bar"/>
| <ConstructorCallExpression line="4" column="7" lastLine="4" lastColumn="16" type="Foo">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="4" column="14" lastLine="4" lastColumn="16"/>
| </ConstructorCallExpression>
| </BinaryExpression>
| </ExpressionStatement>
@@ -46860,7 +47089,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="52" column="1" lastLine="52" lastColumn="31" token="=">
| <VariableExpression line="52" column="5" lastLine="52" lastColumn="11" name="jsr308"/>
| <ConstructorCallExpression line="52" column="14" lastLine="52" lastColumn="31" type="JSR308Class">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="52" column="29" lastLine="52" lastColumn="31"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -47150,7 +47379,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="26" column="9" lastLine="26" lastColumn="88" token="=">
| <VariableExpression line="26" column="38" lastLine="26" lastColumn="46" name="localVar" type="List<String>"/>
| <ConstructorCallExpression line="26" column="49" lastLine="26" lastColumn="88" type="ArrayList<String>">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="26" column="86" lastLine="26" lastColumn="88"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -47546,7 +47775,7 @@ final class ParserPositiveSyntaxTest {
| <DeclarationExpression line="1" column="1" lastLine="6" lastColumn="2" token="=">
| <VariableExpression line="1" column="5" lastLine="1" lastColumn="13" name="delegate"/>
| <ConstructorCallExpression line="1" column="16" lastLine="6" lastColumn="2" type="test$1" anonymous="true">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="1" column="26" lastLine="1" lastColumn="28"/>
| </ConstructorCallExpression>
| </DeclarationExpression>
| </ExpressionStatement>
@@ -47731,7 +47960,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="18" column="19" lastLine="20" lastColumn="10">
| <ExpressionStatement line="19" column="13" lastLine="19" lastColumn="28">
| <ConstructorCallExpression line="19" column="13" lastLine="19" lastColumn="28" type="BarHolder">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="19" column="26" lastLine="19" lastColumn="28"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -47766,7 +47995,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="27" column="19" lastLine="29" lastColumn="10">
| <ExpressionStatement line="28" column="13" lastLine="28" lastColumn="28">
| <ConstructorCallExpression line="28" column="13" lastLine="28" lastColumn="28" type="BarHolder">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="28" column="26" lastLine="28" lastColumn="28"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -47805,7 +48034,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="36" column="19" lastLine="38" lastColumn="10">
| <ExpressionStatement line="37" column="13" lastLine="37" lastColumn="28">
| <ConstructorCallExpression line="37" column="13" lastLine="37" lastColumn="28" type="BarHolder">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="37" column="26" lastLine="37" lastColumn="28"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -47816,7 +48045,7 @@ final class ParserPositiveSyntaxTest {
| <BlockStatement line="39" column="21" lastLine="41" lastColumn="10">
| <ExpressionStatement line="40" column="13" lastLine="40" lastColumn="28">
| <ConstructorCallExpression line="40" column="13" lastLine="40" lastColumn="28" type="BarHolder">
- | <ArgumentListExpression line="-1" column="-1" lastLine="-1" lastColumn="-1"/>
+ | <ArgumentListExpression line="40" column="26" lastLine="40" lastColumn="28"/>
| </ConstructorCallExpression>
| </ExpressionStatement>
| </BlockStatement>
@@ -48107,7 +48336,16 @@ final class ParserPositiveSyntaxTest {
| <MethodNode line="3" column="5" lastLine="3" lastColumn="18" name="table" modifiers="abstract" returnType="Table"/>
| <MethodNode line="4" column="5" lastLine="4" lastColumn="31" name="joinColumns" modifiers="abstract" returnType="JoinColumn[]"/>
| </ClassNode>
- | <ClassNode line="13" column="1" lastLine="23" lastColumn="2" kind="class" name="OtherSection"/>
+ | <ClassNode line="13" column="1" lastLine="23" lastColumn="2" kind="class" name="OtherSection">
+ | <AnnotationNode line="14" column="5" lastLine="14" lastColumn="26" class="CollectionOfElements"/>
+ | <AnnotationNode line="15" column="5" lastLine="19" lastColumn="14" class="JoinTable" members="joinColumns,table"/>
+ | <AnnotationNode line="20" column="5" lastLine="21" lastColumn="28" class="Column" members="name,nullable"/>
+ | <PropertyNode line="14" column="5" lastLine="22" lastColumn="51" name="questions" type="Set<String>" modifiers="public">
+ | <ConstructorCallExpression line="22" column="29" lastLine="22" lastColumn="51" type="HashSet<String>">
+ | <ArgumentListExpression line="22" column="49" lastLine="22" lastColumn="51"/>
+ | </ConstructorCallExpression>
+ | </PropertyNode>
+ | </ClassNode>
| <ClassNode line="6" column="1" lastLine="6" lastColumn="34" kind="annotation" name="Table" implements="java.lang.annotation.Annotation">
| <MethodNode line="6" column="19" lastLine="6" lastColumn="32" name="name" modifiers="abstract" returnType="String"/>
| </ClassNode>
diff --git a/src/test/groovy/org/apache/groovy/parser/antlr4/PositionConfigureUtilsTest.groovy b/src/test/groovy/org/apache/groovy/parser/antlr4/PositionConfigureUtilsTest.groovy
index 4dd567ff89..598b6d7920 100644
--- a/src/test/groovy/org/apache/groovy/parser/antlr4/PositionConfigureUtilsTest.groovy
+++ b/src/test/groovy/org/apache/groovy/parser/antlr4/PositionConfigureUtilsTest.groovy
@@ -20,13 +20,18 @@ package org.apache.groovy.parser.antlr4
import org.antlr.v4.runtime.CommonToken
import org.antlr.v4.runtime.Token
+import org.antlr.v4.runtime.tree.TerminalNodeImpl
import org.apache.groovy.parser.antlr4.util.PositionConfigureUtils
import org.codehaus.groovy.ast.ASTNode
+import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.codehaus.groovy.ast.expr.EmptyExpression
import org.junit.jupiter.api.Test
/**
* Position calculations for tokens whose {@link Token#getText()} is null
- * (typical of an unset EOF / imaginary token).
+ * (typical of an unset EOF / imaginary token), and the
+ * {@code initialStop} / {@code start,stop} overloads that must ignore
+ * synthetic nodes whose end is unset.
*/
final class PositionConfigureUtilsTest {
@@ -43,6 +48,31 @@ final class PositionConfigureUtilsTest {
assert lastColumn == 8
}
+ @Test
+ void endPositionWithEmptyTextUsesStartColumn() {
+ CommonToken token = token('', 4, 2)
+ def (lastLine, lastColumn) = PositionConfigureUtils.endPosition(token)
+ assert lastLine == 4
+ assert lastColumn == 3
+ }
+
+ @Test
+ void endPositionWithoutNewlineUsesCodePointLength() {
+ CommonToken token = token('int', 1, 8)
+ def (lastLine, lastColumn) = PositionConfigureUtils.endPosition(token)
+ assert lastLine == 1
+ assert lastColumn == 12
+ }
+
+ @Test
+ void endPositionWithNewlineUsesTrailingLine() {
+ CommonToken token = token('a\nb', 5, 2)
+ def (lastLine, lastColumn) = PositionConfigureUtils.endPosition(token)
+ assert lastLine == 6
+ // trailing "\nb" measured in code points from the last newline
+ assert lastColumn == 2
+ }
+
@Test
void configureASTWithNullTokenTextUsesStartColumn() {
CommonToken token = new CommonToken(Token.EOF)
@@ -51,9 +81,151 @@ final class PositionConfigureUtilsTest {
assert token.text == null
def node = PositionConfigureUtils.configureAST(new ASTNode(), token)
- assert node.lineNumber == 3
- assert node.columnNumber == 5
- assert node.lastLineNumber == 3
- assert node.lastColumnNumber == 5
+ assertPos node, 3, 5, 3, 5
+ }
+
+ @Test
+ void configureASTWithTokenTextUsesCodePointLength() {
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), token('foo', 2, 0))
+ assertPos node, 2, 1, 2, 4
+ }
+
+ @Test
+ void configureASTWithTerminalNodeMatchesToken() {
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), new TerminalNodeImpl(token('x', 9, 3)))
+ assertPos node, 9, 4, 9, 5
+ }
+
+ @Test
+ void configureASTFromSourceCopiesAllFour() {
+ def source = positioned(4, 2, 5, 8)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), source)
+ assertPos node, 4, 2, 5, 8
+ }
+
+ @Test
+ void configureASTFromContextUsesStartAndStopTokens() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx)
+ assertPos node, 2, 5, 2, 22
+ }
+
+ @Test
+ void configureEndPositionUsesStopToken() {
+ def node = new ASTNode()
+ PositionConfigureUtils.configureEndPosition(node, token(';', 7, 10))
+ assert node.lastLineNumber == 7
+ assert node.lastColumnNumber == 12
+ }
+
+ @Test
+ void configureASTContextInitialStopUsesAuthoredEnd() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def initial = positioned(2, 18, 2, 19)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx, initial)
+ assertPos node, 2, 5, 2, 19
+ }
+
+ @Test
+ void configureASTContextInitialStopIgnoresSyntheticConstant() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def synthetic = new ConstantExpression(0, true)
+ assert synthetic.lastLineNumber == -1
+
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx, synthetic)
+ assertPos node, 2, 5, 2, 22
+ }
+
+ @Test
+ void configureASTContextInitialStopIgnoresEmptyExpressionSingleton() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx, EmptyExpression.INSTANCE)
+ assertPos node, 2, 5, 2, 22
+ }
+
+ @Test
+ void configureASTContextInitialStopNullFallsBackToContext() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx, null)
+ assertPos node, 2, 5, 2, 22
+ }
+
+ @Test
+ void configureASTContextInitialStopZeroLastLineFallsBackToContext() {
+ def ctx = ctx(token('int', 2, 4), token(';', 2, 20))
+ def zero = positioned(1, 1, 0, 1)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), ctx, zero)
+ assertPos node, 2, 5, 2, 22
+ }
+
+ @Test
+ void configureASTStartStopUsesAuthoredEnd() {
+ def start = positioned(3, 2, 3, 5)
+ def stop = positioned(3, 8, 3, 12)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, stop)
+ assertPos node, 3, 2, 3, 12
+ }
+
+ @Test
+ void configureASTStartStopIgnoresUnpositionedStop() {
+ def start = positioned(3, 2, 3, 5)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, new ASTNode())
+ assertPos node, 3, 2, 3, 5
+ }
+
+ @Test
+ void configureASTStartStopNullStopUsesStartEnd() {
+ def start = positioned(3, 2, 3, 5)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, null)
+ assertPos node, 3, 2, 3, 5
+ }
+
+ @Test
+ void configureASTStartStopIgnoresEmptyExpressionSingleton() {
+ def start = positioned(3, 2, 3, 5)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, EmptyExpression.INSTANCE)
+ assertPos node, 3, 2, 3, 5
+ }
+
+ @Test
+ void configureASTStartStopIgnoresSyntheticConstant() {
+ def start = positioned(3, 2, 3, 5)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, new ConstantExpression(0, true))
+ assertPos node, 3, 2, 3, 5
+ }
+
+ @Test
+ void configureASTStartStopZeroLastLineUsesStartEnd() {
+ def start = positioned(3, 2, 3, 5)
+ def zero = positioned(3, 8, 0, 9)
+ def node = PositionConfigureUtils.configureAST(new ASTNode(), start, zero)
+ assertPos node, 3, 2, 3, 5
+ }
+
+ private static CommonToken token(String text, int line, int charPos) {
+ CommonToken token = new CommonToken(0, text)
+ token.setLine(line)
+ token.setCharPositionInLine(charPos)
+ return token
+ }
+
+ private static GroovyParser.GroovyParserRuleContext ctx(Token start, Token stop) {
+ def ctx = new GroovyParser.GroovyParserRuleContext()
+ ctx.start = start
+ ctx.stop = stop
+ return ctx
+ }
+
+ private static ASTNode positioned(int line, int column, int lastLine, int lastColumn) {
+ def node = new ASTNode()
+ node.lineNumber = line
+ node.columnNumber = column
+ node.lastLineNumber = lastLine
+ node.lastColumnNumber = lastColumn
+ return node
+ }
+
+ private static void assertPos(ASTNode node, int line, int column, int lastLine, int lastColumn) {
+ assert [node.lineNumber, node.columnNumber, node.lastLineNumber, node.lastColumnNumber] == [line, column, lastLine, lastColumn]
}
}
diff --git a/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy b/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
index 8a12e87d10..78121c72d8 100644
--- a/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
+++ b/src/test/groovy/org/apache/groovy/parser/antlr4/TestUtils.groovy
@@ -157,7 +157,7 @@ final class TestUtils {
/**
* Pretty-printed XML dump of the AST of {@code source}, including
- * source positions on every node.
+ * source positions on authored nodes. Synthetic nodes remain at {@code -1}.
*/
static String dumpAst(String source, CompilerConfiguration compilerConfiguration = CompilerConfiguration.DEFAULT) {
return AstXmlDumper.dump(parseModule(source, compilerConfiguration))
diff --git a/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstXmlDumper.groovy b/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstXmlDumper.groovy
index 4bf5ed21a9..8204a62fe9 100644
--- a/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstXmlDumper.groovy
+++ b/src/test/groovy/org/apache/groovy/parser/antlr4/util/AstXmlDumper.groovy
@@ -29,6 +29,7 @@ import org.codehaus.groovy.ast.ImportNode
import org.codehaus.groovy.ast.MethodNode
import org.codehaus.groovy.ast.ModuleNode
import org.codehaus.groovy.ast.Parameter
+import org.codehaus.groovy.ast.PropertyNode
import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.stmt.Statement
@@ -116,6 +117,7 @@ final class AstXmlDumper {
}
}
n.fields.findAll { !it.synthetic }.each { dumpField(it) }
+ n.properties.each { dumpProperty(it) }
n.declaredConstructors.each { dumpMethod(it, true) }
n.objectInitializerStatements.each { stmt ->
elem('ObjectInitializer', [:]) {
@@ -159,6 +161,22 @@ final class AstXmlDumper {
}
}
+ // No-visibility members are properties; the synthetic backing field is omitted above.
+ private void dumpProperty(PropertyNode n) {
+ dumpAnnotations(n)
+ Map attrs = pos(n) + [name: n.name, type: typeName(n.type)]
+ String mods = fieldMods(n.modifiers)
+ if (mods) attrs.modifiers = mods
+ Expression init = n.field?.initialValueExpression
+ if (init) {
+ elem('PropertyNode', attrs) {
+ dumpExpression(init)
+ }
+ } else {
+ elem('PropertyNode', attrs)
+ }
+ }
+
private void dumpMethod(MethodNode n, boolean ctor) {
dumpAnnotations(n)
Map attrs = pos(n) + [name: n.name]
diff --git a/src/test/groovy/org/codehaus/groovy/classgen/Jep361SwitchExpressionTest.groovy b/src/test/groovy/org/codehaus/groovy/classgen/Jep361SwitchExpressionTest.groovy
index 289b7aaedc..0fcb51fd58 100644
--- a/src/test/groovy/org/codehaus/groovy/classgen/Jep361SwitchExpressionTest.groovy
+++ b/src/test/groovy/org/codehaus/groovy/classgen/Jep361SwitchExpressionTest.groovy
@@ -188,7 +188,7 @@ final class Jep361SwitchExpressionTest {
case 6 -> def x = 'a'; yield x
default -> 'z'
}
- ''', 'Expect only 1 statement'
+ ''', 'Arrow switch cases must contain a single statement'
}
//--------------------------------------------------------------------------
diff --git a/src/test/java/org/apache/groovy/parser/antlr4/internal/ErrorStrategyTest.java b/src/test/java/org/apache/groovy/parser/antlr4/internal/ErrorStrategyTest.java
index c607a2b53e..a75088c4c6 100644
--- a/src/test/java/org/apache/groovy/parser/antlr4/internal/ErrorStrategyTest.java
+++ b/src/test/java/org/apache/groovy/parser/antlr4/internal/ErrorStrategyTest.java
@@ -497,6 +497,8 @@ final class ErrorStrategyTest {
AbstractFriendlyErrorStrategy.keywordMessage(GroovyParser.FINALLY));
assertEquals("'case' outside of switch",
AbstractFriendlyErrorStrategy.keywordMessage(GroovyParser.CASE));
+ assertEquals("'import' is only allowed at the beginning of a compilation unit",
+ AbstractFriendlyErrorStrategy.keywordMessage(GroovyParser.IMPORT));
assertNull(AbstractFriendlyErrorStrategy.keywordMessage(GroovyParser.DEFAULT),
"default as offender is a method/annotation keyword, not 'outside of switch'");
assertNull(AbstractFriendlyErrorStrategy.keywordMessage(GroovyParser.Identifier));
@@ -766,6 +768,377 @@ final class ErrorStrategyTest {
assertNull(AbstractFriendlyErrorStrategy.misplacedDefaultClause(e2, colon));
}
+ @Test
+ void arrayCreationMissingDimensionAtEofPrefersJavacWordingOverMissingBrace() {
+ var tokens = lex("new double[]");
+ Token eof = tokens.get(tokens.size() - 1);
+ RecognitionException e = stubException(setOf(GroovyParser.LBRACE), eof, tokens);
+ assertEquals("Array dimension missing; specify a size or add an initializer '{}'",
+ AbstractFriendlyErrorStrategy.arrayCreationMessage(e, eof));
+ assertEquals("Array dimension missing; specify a size or add an initializer '{}'",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Missing '{'"));
+ }
+
+ @Test
+ void arrayCreationSizedDimAfterEmptyDim() {
+ var tokens = lex("new double[][5]");
+ Token five = requireType(tokens, GroovyParser.IntegerLiteral);
+ RecognitionException e = stubException(new IntervalSet(), five, tokens);
+ assertEquals("Cannot specify an array size after an empty dimension",
+ AbstractFriendlyErrorStrategy.arrayCreationMessage(e, five));
+ assertEquals("Cannot specify an array size after an empty dimension",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: '5'"));
+ }
+
+ @Test
+ void arrayCreationSizeWithInitializer() {
+ var tokens = lex("new double[2] { 1.0, 2.0 }");
+ Token brace = requireType(tokens, GroovyParser.LBRACE);
+ RecognitionException e = stubException(new IntervalSet(), brace, tokens);
+ assertEquals("Cannot combine an array size with an array initializer",
+ AbstractFriendlyErrorStrategy.arrayCreationMessage(e, brace));
+ }
+
+ @Test
+ void arrayCreationIgnoresConstructorCall() {
+ var tokens = lex("new Foo()");
+ Token paren = requireType(tokens, GroovyParser.LPAREN);
+ RecognitionException e = stubException(new IntervalSet(), paren, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(e, paren));
+ }
+
+ @Test
+ void arrayCreationNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(null, token(Token.EOF, "<EOF>")));
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(stubException(new IntervalSet(), null), null));
+ CommonToken eof = token(Token.EOF, "<EOF>");
+ eof.setTokenIndex(0);
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(stubException(new IntervalSet(), eof), eof));
+ }
+
+ @Test
+ void unmatchedTypeArgumentWhenOffenderIsTheTypeName() {
+ var tokens = lex("List<Integer list2 = new ArrayList<Integer>()");
+ Token list = tokens.get(0);
+ RecognitionException e = stubException(new IntervalSet(), list, tokens);
+ assertEquals("Missing '>'", AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, list));
+ assertEquals("Missing '>'",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: 'List<Integer'"));
+ }
+
+ @Test
+ void unmatchedTypeArgumentAfterCapitalizedName() {
+ var tokens = lex("List<Integer x");
+ Token x = null;
+ for (int i = 0; i < tokens.size(); i++) {
+ if (tokens.get(i).getType() == GroovyParser.Identifier && "x".equals(tokens.get(i).getText())) {
+ x = tokens.get(i);
+ break;
+ }
+ }
+ assertNotNull(x);
+ RecognitionException e = stubException(new IntervalSet(), x, tokens);
+ assertEquals("Missing '>'", AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, x));
+ assertEquals("Missing '>'", AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: 'List<Integer'"));
+ }
+
+ @Test
+ void unmatchedTypeArgumentIgnoresLeftShift() {
+ var tokens = lex("Integer.SIZE << 1\n(1+2))");
+ Token extraClose = null;
+ int seen = 0;
+ for (int i = 0; i < tokens.size(); i++) {
+ if (tokens.get(i).getType() == GroovyParser.RPAREN) {
+ seen++;
+ if (seen == 2) {
+ extraClose = tokens.get(i);
+ break;
+ }
+ }
+ }
+ assertNotNull(extraClose);
+ RecognitionException e = stubException(new IntervalSet(), extraClose, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, extraClose));
+ assertEquals("Unexpected ')'",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: ')'"));
+ }
+
+ @Test
+ void unmatchedTypeArgumentDoesNotStealAnEarlierUnrelatedError() {
+ var tokens = lex("(1+2))\nList<Integer x");
+ // first RPAREN is the closer of (1+2); the extra one is later
+ Token extraClose = null;
+ int seen = 0;
+ for (int i = 0; i < tokens.size(); i++) {
+ if (tokens.get(i).getType() == GroovyParser.RPAREN) {
+ seen++;
+ if (seen == 2) {
+ extraClose = tokens.get(i);
+ break;
+ }
+ }
+ }
+ assertNotNull(extraClose);
+ RecognitionException e = stubException(new IntervalSet(), extraClose, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, extraClose),
+ "a later unclosed generic must not rewrite an earlier extra ')'");
+ assertEquals("Unexpected ')'",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: ')'"));
+ }
+
+ @Test
+ void unmatchedTypeArgumentIgnoresComparison() {
+ var tokens = lex("x < y z");
+ Token z = null;
+ for (int i = 0; i < tokens.size(); i++) {
+ if ("z".equals(tokens.get(i).getText())) {
+ z = tokens.get(i);
+ break;
+ }
+ }
+ assertNotNull(z);
+ RecognitionException e = stubException(new IntervalSet(), z, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, z));
+ }
+
+ @Test
+ void unmatchedTypeArgumentNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(null, token(GroovyParser.Identifier, "x")));
+ Token gt = token(GroovyParser.GT, ">");
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(stubException(new IntervalSet(), gt), gt));
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(stubException(new IntervalSet(), null), null));
+ }
+
+ @Test
+ void methodDefinitionNotExpectedAfterDefIdent() {
+ var tokens = lex("{ -> def say(");
+ Token lparen = requireType(tokens, GroovyParser.LPAREN);
+ RecognitionException e = stubException(new IntervalSet(), lparen, tokens);
+ assertEquals("Method definition not expected here",
+ AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(e, lparen));
+ assertEquals("Method definition not expected here",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: '('"));
+ }
+
+ @Test
+ void methodDefinitionNotExpectedIgnoresOrdinaryCall() {
+ var tokens = lex("foo(");
+ Token lparen = requireType(tokens, GroovyParser.LPAREN);
+ RecognitionException e = stubException(new IntervalSet(), lparen, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(e, lparen));
+ }
+
+ @Test
+ void methodDefinitionNotExpectedNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(null, token(GroovyParser.LPAREN, "(")));
+ Token ident = token(GroovyParser.Identifier, "x");
+ assertNull(AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(stubException(new IntervalSet(), ident), ident));
+ assertNull(AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(stubException(new IntervalSet(), null), null));
+ }
+
+ @Test
+ void unmatchedDoWhileNamesMissingWhile() {
+ var tokens = lex("do\nprintln 123\nprintln");
+ Token println = null;
+ int seen = 0;
+ for (int i = 0; i < tokens.size(); i++) {
+ if ("println".equals(tokens.get(i).getText())) {
+ seen++;
+ if (seen == 2) {
+ println = tokens.get(i);
+ break;
+ }
+ }
+ }
+ assertNotNull(println);
+ RecognitionException e = stubException(setOf(GroovyParser.WHILE, GroovyParser.Identifier), println, tokens);
+ assertEquals("Missing 'while'", AbstractFriendlyErrorStrategy.unmatchedDoWhile(e, println));
+ assertEquals("Missing 'while'", AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: '123\\nprintln'"));
+ }
+
+ @Test
+ void unmatchedDoWhileNamesMultiStatementBodyWhenWhileFollows() {
+ var tokens = lex("do\nprintln 123\nprintln 123\nwhile (false)");
+ Token println = null;
+ int seen = 0;
+ for (int i = 0; i < tokens.size(); i++) {
+ if ("println".equals(tokens.get(i).getText())) {
+ seen++;
+ if (seen == 2) {
+ println = tokens.get(i);
+ break;
+ }
+ }
+ }
+ assertNotNull(println);
+ RecognitionException e = stubException(setOf(GroovyParser.WHILE, GroovyParser.Identifier), println, tokens);
+ assertEquals("do-while body must be a single statement; wrap multiple statements in '{ }'",
+ AbstractFriendlyErrorStrategy.unmatchedDoWhile(e, println));
+ assertEquals("do-while body must be a single statement; wrap multiple statements in '{ }'",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: '123\\nprintln'"));
+ }
+
+ @Test
+ void unmatchedDoWhileIgnoresWhileLoop() {
+ var tokens = lex("while (true) x");
+ Token x = null;
+ for (int i = 0; i < tokens.size(); i++) {
+ if ("x".equals(tokens.get(i).getText())) {
+ x = tokens.get(i);
+ break;
+ }
+ }
+ assertNotNull(x);
+ RecognitionException e = stubException(new IntervalSet(), x, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedDoWhile(e, x));
+ }
+
+ @Test
+ void unmatchedDoWhileNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedDoWhile(null, token(GroovyParser.Identifier, "x")));
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedDoWhile(stubException(new IntervalSet(), null), null));
+ }
+
+ @Test
+ void enumMemberAfterCommaNamesSemicolon() {
+ var tokens = lex("enum E { X, Y,\ndef");
+ Token defTok = requireType(tokens, GroovyParser.DEF);
+ RecognitionException e = stubException(new IntervalSet(), defTok, tokens);
+ assertEquals("';' expected after the last enum constant",
+ AbstractFriendlyErrorStrategy.enumMemberAfterComma(e, defTok));
+ assertEquals("';' expected after the last enum constant",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: ',\\n def'"));
+ }
+
+ @Test
+ void enumMemberAfterCommaIgnoresListLiteral() {
+ var tokens = lex("[a, def]");
+ Token defTok = requireType(tokens, GroovyParser.DEF);
+ RecognitionException e = stubException(new IntervalSet(), defTok, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(e, defTok));
+ }
+
+ @Test
+ void enumMemberAfterCommaIgnoresClosedEnumEarlierInFile() {
+ var tokens = lex("enum Color { R, G, B }\ndef x = [1, def]");
+ Token defTok = null;
+ for (int i = tokens.size() - 1; i >= 0; i--) {
+ if (tokens.get(i).getType() == GroovyParser.DEF) {
+ defTok = tokens.get(i);
+ break;
+ }
+ }
+ assertNotNull(defTok);
+ RecognitionException e = stubException(new IntervalSet(), defTok, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(e, defTok));
+ }
+
+ @Test
+ void enumMemberAfterCommaNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(null, token(GroovyParser.DEF, "def")));
+ Token ident = token(GroovyParser.Identifier, "x");
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(stubException(new IntervalSet(), ident), ident));
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(stubException(new IntervalSet(), null), null));
+ }
+
+ @Test
+ void interfaceDefaultAfterHeader() {
+ var tokens = lex("interface I { def m() default");
+ Token deflt = requireType(tokens, GroovyParser.DEFAULT);
+ RecognitionException e = stubException(new IntervalSet(), deflt, tokens);
+ assertEquals("'default' cannot follow a method header; put 'default' before the method name",
+ AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(e, deflt));
+ assertEquals("'default' cannot follow a method header; put 'default' before the method name",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: 'default'"));
+ }
+
+ @Test
+ void interfaceDefaultAfterHeaderIgnoresAnnotationType() {
+ var tokens = lex("@interface A { String a() default");
+ Token deflt = requireType(tokens, GroovyParser.DEFAULT);
+ RecognitionException e = stubException(new IntervalSet(), deflt, tokens);
+ assertNull(AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(e, deflt));
+ }
+
+ @Test
+ void interfaceDefaultAfterHeaderNulls() {
+ assertNull(AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(null, token(GroovyParser.DEFAULT, "default")));
+ Token ident = token(GroovyParser.Identifier, "x");
+ assertNull(AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(stubException(new IntervalSet(), ident), ident));
+ assertNull(AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(stubException(new IntervalSet(), null), null));
+ }
+
+ @Test
+ void unexpectedPunctuationNamesClosersAndSemicolon() {
+ assertEquals("Unexpected ')'", AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.RPAREN, ")")));
+ assertEquals("Unexpected ']'", AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.RBRACK, "]")));
+ assertEquals("Unexpected '}'", AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.RBRACE, "}")));
+ assertEquals("Unexpected ';'", AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.SEMI, ";")));
+ assertEquals("Unexpected ','", AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.COMMA, ",")));
+ assertNull(AbstractFriendlyErrorStrategy.unexpectedPunctuation(token(GroovyParser.Identifier, "x")));
+ assertNull(AbstractFriendlyErrorStrategy.unexpectedPunctuation(null));
+ Token semi = token(GroovyParser.SEMI, ";");
+ RecognitionException e = stubException(new IntervalSet(), semi);
+ assertEquals("Unexpected ';'", AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: ';'"));
+ }
+
+ @Test
+ void refineFallbackImportKeyword() {
+ Token imp = token(GroovyParser.IMPORT, "import");
+ RecognitionException e = stubException(new IntervalSet(), imp);
+ assertEquals("'import' is only allowed at the beginning of a compilation unit",
+ AbstractFriendlyErrorStrategy.refineFallbackMessage(e, "Unexpected input: 'import'"));
+ }
+
+ @Test
+ void arrayCreationSwallowsStreamFailure() {
+ CommonToken eof = token(Token.EOF, "<EOF>");
+ eof.setTokenIndex(1);
+ RecognitionException e = stubException(new IntervalSet(), eof, new ThrowingTokenStream());
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(e, eof));
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, eof));
+ assertNull(AbstractFriendlyErrorStrategy.unmatchedDoWhile(e, eof));
+ CommonToken lparen = token(GroovyParser.LPAREN, "(");
+ lparen.setTokenIndex(1);
+ assertNull(AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(
+ stubException(new IntervalSet(), lparen, new ThrowingTokenStream()), lparen));
+ CommonToken defTok = token(GroovyParser.DEF, "def");
+ defTok.setTokenIndex(1);
+ assertNull(AbstractFriendlyErrorStrategy.enumMemberAfterComma(
+ stubException(new IntervalSet(), defTok, new ThrowingTokenStream()), defTok));
+ CommonToken deflt = token(GroovyParser.DEFAULT, "default");
+ deflt.setTokenIndex(1);
+ assertNull(AbstractFriendlyErrorStrategy.interfaceDefaultAfterHeader(
+ stubException(new IntervalSet(), deflt, new ThrowingTokenStream()), deflt));
+ RecognitionException iae = stubException(new IntervalSet(), eof,
+ new ThrowingTokenStream(new IllegalArgumentException("test")));
+ assertNull(AbstractFriendlyErrorStrategy.arrayCreationMessage(iae, eof));
+ }
+
+ @Test
+ void methodDefinitionNotExpectedAfterVoidReturnType() {
+ var tokens = lex("{ void say(");
+ Token lparen = requireType(tokens, GroovyParser.LPAREN);
+ RecognitionException e = stubException(new IntervalSet(), lparen, tokens);
+ assertEquals("Method definition not expected here",
+ AbstractFriendlyErrorStrategy.methodDefinitionNotExpected(e, lparen));
+ }
+
+ @Test
+ void unmatchedTypeArgumentNestedGenerics() {
+ var tokens = lex("List<List<Integer x");
+ Token x = null;
+ for (int i = 0; i < tokens.size(); i++) {
+ if ("x".equals(tokens.get(i).getText())) {
+ x = tokens.get(i);
+ break;
+ }
+ }
+ assertNotNull(x);
+ RecognitionException e = stubException(new IntervalSet(), x, tokens);
+ assertEquals("Missing '>'", AbstractFriendlyErrorStrategy.unmatchedTypeArgument(e, x));
+ }
+
// --- helpers ----------------------------------------------------------------
private static void assertSafeIndexMessage(final String src) {
@@ -777,12 +1150,16 @@ final class ErrorStrategyTest {
}
private static Token requireSafeIndex(final CommonTokenStream tokens) {
+ return requireType(tokens, GroovyParser.SAFE_INDEX);
+ }
+
+ private static Token requireType(final CommonTokenStream tokens, final int type) {
for (int i = 0; i < tokens.size(); i++) {
- if (tokens.get(i).getType() == GroovyParser.SAFE_INDEX) {
+ if (tokens.get(i).getType() == type) {
return tokens.get(i);
}
}
- throw new AssertionError("no SAFE_INDEX in: " + tokens.getText());
+ throw new AssertionError("no token type " + type + " in: " + tokens.getText());
}
private static CommonTokenStream lex(final String src) {