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 2020/02/01 20:29:56 UTC
[groovy] branch master updated: Remove the semantic predicate in
the `returnType` rule suggested by @sharwell
This is an automated email from the ASF dual-hosted git repository.
sunlan 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 5240910 Remove the semantic predicate in the `returnType` rule suggested by @sharwell
5240910 is described below
commit 52409103df8e8ccef3d093c71a726723f0e0adf8
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Feb 2 01:12:21 2020 +0800
Remove the semantic predicate in the `returnType` rule suggested by @sharwell
---
src/antlr/GroovyParser.g4 | 4 +---
.../apache/groovy/parser/antlr4/AstBuilder.java | 4 ++++
.../groovy/parser/antlr4/SyntaxErrorTest.groovy | 4 ++++
.../fail/AnnotationDeclaration_01x.groovy | 22 ++++++++++++++++++++++
4 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/antlr/GroovyParser.g4 b/src/antlr/GroovyParser.g4
index bb47db1..829fe02 100644
--- a/src/antlr/GroovyParser.g4
+++ b/src/antlr/GroovyParser.g4
@@ -307,9 +307,7 @@ methodName
returnType[int ct]
:
standardType
- |
- // annotation method can not have void return type
- { 3 != $ct }? VOID
+ | VOID
;
fieldDeclaration
diff --git a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index d1d5948..a4a4ec8 100644
--- a/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -1670,6 +1670,10 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
}
if (asBoolean(ctx.VOID())) {
+ if (3 == ctx.ct) { // annotation
+ throw createParsingFailedException("annotation method can not have void return type", ctx);
+ }
+
return ClassHelper.VOID_TYPE;
}
diff --git a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
index e686578..33503c6 100644
--- a/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
+++ b/subprojects/parser-antlr4/src/test/groovy/org/apache/groovy/parser/antlr4/SyntaxErrorTest.groovy
@@ -146,6 +146,10 @@ final class SyntaxErrorTest extends GroovyTestCase {
TestUtils.doRunAndShouldFail('fail/ClassDeclaration_02x.groovy')
}
+ void "test groovy core - AnnotationDeclaration"() {
+ TestUtils.doRunAndShouldFail('fail/AnnotationDeclaration_01x.groovy');
+ }
+
void "test groovy core - MethodDeclaration"() {
TestUtils.shouldFail('fail/MethodDeclaration_01.groovy')
TestUtils.doRunAndShouldFail('fail/MethodDeclaration_02x.groovy')
diff --git a/subprojects/parser-antlr4/src/test/resources/fail/AnnotationDeclaration_01x.groovy b/subprojects/parser-antlr4/src/test/resources/fail/AnnotationDeclaration_01x.groovy
new file mode 100644
index 0000000..c32699e
--- /dev/null
+++ b/subprojects/parser-antlr4/src/test/resources/fail/AnnotationDeclaration_01x.groovy
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+@interface A {
+ void a()
+}