groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: GROOVY-8730: trait helper contains unused abstract methods
Date Sat, 04 Aug 2018 03:44:26 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 2c96f9ec7 -> 4bddeb2dd


GROOVY-8730: trait helper contains unused abstract methods


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

Branch: refs/heads/master
Commit: 4bddeb2dd4a0759c0723caddc2b01e6ce101e276
Parents: 2c96f9e
Author: Paul King <paulk@asert.com.au>
Authored: Sat Aug 4 13:44:15 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Sat Aug 4 13:44:15 2018 +1000

----------------------------------------------------------------------
 .../transform/trait/TraitASTTransformation.java  |  5 ++++-
 .../traitx/TraitASTTransformationTest.groovy     | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4bddeb2d/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
b/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
index 55d894c..6757fc2 100644
--- a/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/trait/TraitASTTransformation.java
@@ -224,7 +224,10 @@ public class TraitASTTransformation extends AbstractASTTransformation
implements
                             methodNode.getLineNumber(), methodNode.getColumnNumber()));
                     return null;
                 }
-                helper.addMethod(processMethod(cNode, helper, methodNode, fieldHelper, fieldNames));
+                if (!methodNode.isAbstract()) {
+                    // add non-abstract methods; abstract methods covered from trait interface
+                    helper.addMethod(processMethod(cNode, helper, methodNode, fieldHelper,
fieldNames));
+                }
                 if (methodNode.isPrivate() || methodNode.isStatic()) {
                     nonPublicAPIMethods.add(methodNode);
                 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/4bddeb2d/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index 362c8ff..e449198 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -2492,4 +2492,23 @@ assert c.b() == 2
         '''
     }
 
+    //GROOVY-8730
+    void testAbstractMethodsNotNeededInHelperClass() {
+        assertScript '''
+            import static groovy.test.GroovyAssert.shouldFail
+
+            trait Foo { abstract bar() }
+
+            // appears in interface as expected
+            assert Foo.getMethod("bar", [] as Class[])
+
+            // shouldn't appear in trait helper
+            shouldFail(NoSuchMethodException) {
+                // first and only inner class is the trait helper
+                // fragile if current implementation changes drastically
+                Foo.classes[0].getMethod("bar", [Foo] as Class[])
+            }
+        '''
+    }
+
 }


Mime
View raw message