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-8895: Traits defining getter conflicts with generated getter
Date Tue, 20 Nov 2018 20:08:09 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 541b3df5e -> 0dc69445c


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/0dc69445
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/0dc69445
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/0dc69445

Branch: refs/heads/GROOVY_2_5_X
Commit: 0dc69445ca2b1f0ec2e7dd62d5172f54304ea692
Parents: 541b3df
Author: Paul King <paulk@asert.com.au>
Authored: Wed Nov 21 06:06:18 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Wed Nov 21 06:07:58 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/0dc69445/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/0dc69445/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()')
+    }
+
+}


Mime
View raw message