Repository: groovy
Updated Branches:
  refs/heads/master 1fc3b672d -> 650936ecd


GROOVY-8895: Traits defining getter conflicts with generated getter


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

Branch: refs/heads/master
Commit: 650936ecd10301f4b0cc37bbe4566a338ac29167
Parents: 1fc3b67
Author: Paul King <pa...@asert.com.au>
Authored: Wed Nov 21 06:06:18 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Wed Nov 21 06:06:33 2018 +1000

----------------------------------------------------------------------
 .../groovy/tools/javac/JavaStubGenerator.java   |  2 +-
 .../TraitAbstractGetterStubTest.groovy          | 68 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/650936ec/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java 
b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 0c1acbd..4b9efbb 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -337,7 +337,7 @@ public class JavaStubGenerator {
                                 }
                             }
                         }
-                        if (method==null) {
+                        if (method==null && !traitMethod.isAbstract()) {
                             printMethod(out, classNode, traitMethod);
                         }
                     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/650936ec/src/test/org/codehaus/groovy/tools/stubgenerator/TraitAbstractGetterStubTest.groovy
----------------------------------------------------------------------
diff --git 
a/src/test/org/codehaus/groovy/tools/stubgenerator/TraitAbstractGetterStubTest.groovy
 
b/src/test/org/codehaus/groovy/tools/stubgenerator/TraitAbstractGetterStubTest.groovy
new file mode 100644
index 0000000..d2df4c5
--- /dev/null
+++ 
b/src/test/org/codehaus/groovy/tools/stubgenerator/TraitAbstractGetterStubTest.groovy
@@ -0,0 +1,68 @@
+/*
+ *  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.
+ */
+package org.codehaus.groovy.tools.stubgenerator
+
+/**
+ * GROOVY-8895: Checks that a trait with an abstract getter isn't included in 
stub by mistake
+ */
+class TraitAbstractGetterStubTest extends StringSourcesStubTestCase {
+
+    @Override
+    Map<String, String> provideSources() {
+        [
+            'Foo8895.java': '''
+                public class Foo8895 { }
+            ''',
+
+            'GetFoo.groovy': '''
+                trait GetFoo {
+                    abstract Foo8895 getFoo()
+                }
+            ''',
+
+            'BaseFooSpec.groovy': '''
+                class BaseFooSpec {
+                    Foo8895 foo = new Foo8895()
+                }
+            ''',
+
+            'FooSpec.groovy': '''
+                class FooSpec extends BaseFooSpec implements GetFoo { }
+            ''',
+
+            'Control.groovy': '''
+                class Control implements GetFoo { }
+            ''',
+        ]
+    }
+
+//    protected void init() {
+//        debug = true
+//        delete = false
+//    }
+
+    @Override
+    void verifyStubs() {
+        String stubSource = stubJavaSourceFor('FooSpec')
+        assert !stubSource.contains('Foo8895 getFoo()')
+        stubSource = stubJavaSourceFor('Control')
+        assert !stubSource.contains('Foo8895 getFoo()')
+    }
+
+}

Reply via email to