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-8224: Stubs for classes implementing traits with fields don't include getters/setters
Date Thu, 21 Jun 2018 06:27:42 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 3848a746f -> 2860fbd4c


GROOVY-8224: Stubs for classes implementing traits with fields don't include getters/setters


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 2860fbd4ca5b367ab99b3cdd9951a3f232764505
Parents: 3848a74
Author: Paul King <paulk@asert.com.au>
Authored: Tue Jun 19 21:15:24 2018 +1000
Committer: Paul King <paulk@asert.com.au>
Committed: Thu Jun 21 16:27:28 2018 +1000

----------------------------------------------------------------------
 .../groovy/tools/javac/JavaStubGenerator.java   |  9 +++
 .../TraitPropertiesStubTest.groovy              | 70 ++++++++++++++++++++
 2 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/2860fbd4/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 0add1d3..9814ee4 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -31,6 +31,7 @@ import org.codehaus.groovy.ast.InnerClassNode;
 import org.codehaus.groovy.ast.MethodNode;
 import org.codehaus.groovy.ast.ModuleNode;
 import org.codehaus.groovy.ast.Parameter;
+import org.codehaus.groovy.ast.PropertyNode;
 import org.codehaus.groovy.ast.expr.ArgumentListExpression;
 import org.codehaus.groovy.ast.expr.ClassExpression;
 import org.codehaus.groovy.ast.expr.ClosureExpression;
@@ -157,6 +158,14 @@ public class JavaStubGenerator {
                     List<Statement> savedStatements = new ArrayList<Statement>(node.getObjectInitializerStatements());
                     super.visitClass(node);
                     node.getObjectInitializerStatements().addAll(savedStatements);
+                    for (ClassNode inode : node.getAllInterfaces()) {
+                        if (Traits.isTrait(inode)) {
+                            List<PropertyNode> traitProps = inode.getProperties();
+                            for (PropertyNode pn : traitProps) {
+                                visitProperty(pn);
+                            }
+                        }
+                    }
                 }
 
                 @Override

http://git-wip-us.apache.org/repos/asf/groovy/blob/2860fbd4/src/test/org/codehaus/groovy/tools/stubgenerator/TraitPropertiesStubTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/TraitPropertiesStubTest.groovy
b/src/test/org/codehaus/groovy/tools/stubgenerator/TraitPropertiesStubTest.groovy
new file mode 100644
index 0000000..4c0e668
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/TraitPropertiesStubTest.groovy
@@ -0,0 +1,70 @@
+/*
+ *  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-8224: Checks that trait properties appear within stubs
+ */
+class TraitPropertiesStubTest extends StringSourcesStubTestCase {
+
+    @Override
+    Map<String, String> provideSources() {
+        [
+            'GroovyXTrait.groovy': '''
+                trait GroovyXTrait {
+                    int bar
+                    boolean foo
+                    String baz() { 'baz' }
+                }
+            ''',
+
+            'GroovyXImpl.groovy': '''
+                class GroovyXImpl implements GroovyXTrait { }
+            ''',
+
+            'Main.java': '''
+                public class Main {
+                    public static void main(String[] args) {
+                        new GroovyXImpl();
+                    }
+                }
+            ''',
+        ]
+    }
+
+//    protected void init() {
+//        debug = true
+//        delete = false
+//    }
+
+    @Override
+    void verifyStubs() {
+        verifyMethodAndPropsInStubs(stubJavaSourceFor('GroovyXTrait'))
+        verifyMethodAndPropsInStubs(stubJavaSourceFor('GroovyXImpl'))
+    }
+
+    private static void verifyMethodAndPropsInStubs(String stubSource) {
+        assert stubSource.contains('String baz()')
+        assert stubSource.contains('int getBar()')
+        assert stubSource.contains('void setBar(int value)')
+        assert stubSource.contains('boolean getFoo()')
+        assert stubSource.contains('boolean isFoo()')
+        assert stubSource.contains('void setFoo(boolean value)')
+    }
+}


Mime
View raw message