Skip to content

Commit

Permalink
Fix for #1328: propagate source position of record compact constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 30, 2021
1 parent 7e58b8c commit b346ade
Show file tree
Hide file tree
Showing 4 changed files with 423 additions and 8 deletions.
2 changes: 1 addition & 1 deletion base/org.codehaus.groovy40/.checkstyle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<file-match-pattern match-pattern="groovy/transform/ASTTestTransformation.groovy" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/ASTTransformationCollectorCodeVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/ASTTransformationVisitor.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/(Field|Log|NullCheck|RecordType|Sealed)ASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/(Field|Log|NullCheck|RecordType|Sealed|TupleConstructor)ASTTransformation.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/NotYetImplemented.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/sc/transformers/(Binary|MethodCall)ExpressionTransformer.java" include-pattern="false" />
<file-match-pattern match-pattern="groovy/transform/stc/StaticTypeCheckingSupport.java" include-pattern="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.codehaus.groovy.antlr.EnumHelper;
import org.codehaus.groovy.antlr.LocationSupport;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
Expand Down Expand Up @@ -583,7 +584,7 @@ public ImportNode visitImportDeclaration(final ImportDeclarationContext ctx) {
}

// GRECLIPSE add
ASTNode nameNode = configureAST(new ConstantExpression(null), ctx.qualifiedName());
ASTNode nameNode = configureAST(new AnnotatedNode(), ctx.qualifiedName());
importNode.setNameStart(nameNode.getStart());
importNode.setNameEnd(nameNode.getEnd() - 1);
// GRECLIPSE end
Expand Down Expand Up @@ -1997,14 +1998,19 @@ private void validateParametersOfMethodDeclaration(final Parameter[] parameters,
@Override
public MethodNode visitCompactConstructorDeclaration(final CompactConstructorDeclarationContext ctx) {
ClassNode classNode = ctx.getNodeMetaData(CLASS_DECLARATION_CLASS_NODE);
Objects.requireNonNull(classNode, "classNode should not be null");
// GRECLIPSE add
AnnotatedNode name = configureAST(new AnnotatedNode(),ctx.methodName());
AnnotatedNode node = configureAST(new AnnotatedNode(),ctx);
classNode.putNodeMetaData("compact.constructor",node);
node.setNameStart(name.getStart());
node.setNameEnd(name.getEnd() - 1);
// GRECLIPSE end

if (classNode.getAnnotations().stream().noneMatch(a -> a.getClassNode().getName().equals(RecordType.class.getName()))) {
if (classNode.getAnnotations().stream().noneMatch(a -> a.getClassNode().getName().equals("groovy.transform.RecordType"))) {
createParsingFailedException("Only record can have compact constructor", ctx);
}

List<ModifierNode> modifierNodeList = ctx.getNodeMetaData(COMPACT_CONSTRUCTOR_DECLARATION_MODIFIERS);
if (new ModifierManager(this, modifierNodeList).containsAny(VAR)) {
if (new ModifierManager(this, ctx.getNodeMetaData(COMPACT_CONSTRUCTOR_DECLARATION_MODIFIERS)).containsAny(VAR)) {
throw createParsingFailedException("var cannot be used for compact constructor declaration", ctx);
}

Expand Down
Loading

0 comments on commit b346ade

Please sign in to comment.