You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/08/09 07:16:13 UTC
[groovy] branch master updated: GROOVY-10193: Support sealed type
grammar (minor tweaks)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new b69fafd GROOVY-10193: Support sealed type grammar (minor tweaks)
b69fafd is described below
commit b69fafd61693c0e9fe48a6cedff79cac2d5494c3
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Aug 9 17:16:07 2021 +1000
GROOVY-10193: Support sealed type grammar (minor tweaks)
---
.../apache/groovy/parser/antlr4/AstBuilder.java | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
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 ba8287b..6852904 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1462,15 +1462,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if ((isAnnotation || isEnum) && (isSealed || isNonSealed)) {
ModifierNode mn = isSealed ? sealedModifierNodeOptional.get() : nonSealedModifierNodeOptional.get();
- throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed here", mn);
+ throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed for " +
+ (isEnum ? "enum" : "annotation definition"), mn);
}
boolean hasPermits = asBoolean(ctx.PERMITS());
- if (isSealed && !hasPermits) {
- throw createParsingFailedException("sealed type declaration should have `permits` clause", ctx);
- }
- if (isNonSealed && hasPermits) {
- throw createParsingFailedException("non-sealed type declaration should not have `permits` clause", ctx);
+ if (!isSealed && hasPermits) {
+ throw createParsingFailedException("only sealed type declarations should have `permits` clause", ctx);
}
int modifiers = modifierManager.getClassModifiersOpValue();
@@ -1510,11 +1508,13 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
if (isSealed) {
AnnotationNode sealedAnnotationNode = new AnnotationNode(ClassHelper.makeCached(Sealed.class));
- ListExpression permittedSubclassesListExpression =
- listX(Arrays.stream(this.visitTypeList(ctx.ps))
- .map(ClassExpression::new)
- .collect(Collectors.toList()));
- sealedAnnotationNode.setMember("permittedSubclasses", permittedSubclassesListExpression);
+ if (asBoolean(ctx.ps)) {
+ ListExpression permittedSubclassesListExpression =
+ listX(Arrays.stream(this.visitTypeList(ctx.ps))
+ .map(ClassExpression::new)
+ .collect(Collectors.toList()));
+ sealedAnnotationNode.setMember("permittedSubclasses", permittedSubclassesListExpression);
+ }
classNode.addAnnotation(sealedAnnotationNode);
} else if (isNonSealed) {
classNode.addAnnotation(new AnnotationNode(ClassHelper.makeCached(NonSealed.class)));