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 2018/08/10 20:20:19 UTC

[2/2] groovy git commit: Refine "GROOVY-8743: Abstract method in trait should not have method body"

Refine "GROOVY-8743: Abstract method in trait should not have method body"

(cherry picked from commit 40a8a63bc6a3e3827e2d1ecd135006cc3a652c3a)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a7354c29
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a7354c29
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a7354c29

Branch: refs/heads/GROOVY_2_6_X
Commit: a7354c2983d64fa28bc2463dd15d6e4560bf04e1
Parents: c405e6a
Author: Daniel Sun <su...@apache.org>
Authored: Sat Aug 11 03:54:17 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sat Aug 11 04:19:50 2018 +0800

----------------------------------------------------------------------
 .../org/apache/groovy/parser/antlr4/AstBuilder.java     | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a7354c29/subprojects/parser-antlr4/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
----------------------------------------------------------------------
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 f708bd0..01e5825 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
@@ -1648,26 +1648,26 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> implements Groov
             }
         }
 
-        /*
         if (2 == ctx.t) {
             if (asBoolean(ctx.methodBody())) {
                 throw createParsingFailedException("Abstract method should not have method body", ctx);
             }
         }
-        */
 
         boolean isAbstractMethod = methodNode.isAbstract();
         boolean hasMethodBody = asBoolean(methodNode.getCode());
 
-        if (isAbstractMethod && hasMethodBody) {
-            throw createParsingFailedException("Abstract method should not have method body", ctx);
-        }
-
         if (9 == ctx.ct) { // script
             if (isAbstractMethod || !hasMethodBody) { // method should not be declared abstract in the script
                 throw createParsingFailedException("You can not define a " + (isAbstractMethod ? "abstract" : "") + " method[" + methodNode.getName() + "] " + (!hasMethodBody ? "without method body" : "") + " in the script. Try " + (isAbstractMethod ? "removing the 'abstract'" : "") + (isAbstractMethod && !hasMethodBody ? " and" : "") + (!hasMethodBody ? " adding a method body" : ""), methodNode);
             }
         } else {
+            if (4 == ctx.ct) { // trait
+                if (isAbstractMethod && hasMethodBody) {
+                    throw createParsingFailedException("Abstract method should not have method 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 body. Try adding a method body, or declare it abstract", methodNode);
             }