groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/3] groovy git commit: AstBrowser fix for Trait object initializers
Date Sat, 21 Jan 2017 12:18:24 GMT
Repository: groovy
Updated Branches:
  refs/heads/parrot d3c68531e -> ad91e0e4a


AstBrowser fix for Trait object initializers

Fix to GROOVY-4636 that incorrectly handled adding statements to
the AST node tree.


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

Branch: refs/heads/parrot
Commit: 76f6e62c800ed9ce72a585aa83f95694011eebb3
Parents: 465b4c0
Author: John Wagenleitner <jwagenleitner@apache.org>
Authored: Sat Jan 14 13:51:06 2017 -0800
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Sat Jan 14 16:05:59 2017 -0800

----------------------------------------------------------------------
 .../swingui/ScriptToTreeNodeAdapter.groovy      |  7 ++---
 .../swingui/ScriptToTreeNodeAdapterTest.groovy  | 29 +++++++++++++++++++-
 2 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/76f6e62c/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
index be80a59..553fc1c 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapter.groovy
@@ -371,13 +371,10 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation
{
         def allInitializers = nodeMaker.makeNode(name)
         parent.add(allInitializers)
         for (Statement stmt : initStatements) {
-            Statement initBlock = ((BlockStatement)stmt).statements.first()
-            def ggrandchild = adapter.make(initBlock)
-            allInitializers.add(ggrandchild)
             TreeNodeBuildingVisitor visitor = new TreeNodeBuildingVisitor(adapter)
-            initBlock.visit(visitor)
+            stmt.visit(visitor)
             if (visitor.currentNode) {
-                ggrandchild.add(visitor.currentNode)
+                allInitializers.add(visitor.currentNode)
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/76f6e62c/subprojects/groovy-console/src/test/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapterTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/test/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapterTest.groovy
b/subprojects/groovy-console/src/test/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapterTest.groovy
index b3196cb..1a6d9c1 100644
--- a/subprojects/groovy-console/src/test/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapterTest.groovy
+++ b/subprojects/groovy-console/src/test/groovy/groovy/inspect/swingui/ScriptToTreeNodeAdapterTest.groovy
@@ -578,7 +578,34 @@ class ScriptToTreeNodeAdapterTest extends GroovyTestCase {
         assertTreeStructure(source, CompilePhase.CONVERSION,
                 [
                         startsWith('ClassNode - A'),
-                        eq('Object Initializers')
+                        eq('Object Initializers'),
+                        contains('BlockStatement'),
+                        contains('BlockStatement'),
+                        contains('ExpressionStatement')
+                ],
+                adapter)
+
+    }
+
+    void testTraitObjectInitializers() {
+        ScriptToTreeNodeAdapter adapter = createAdapter(false, true, true)
+
+        def source = '''
+            trait Interceptor {
+                final Collection<String> matchers = new ArrayList<String>()
+                void matchAll() {
+                    matchers << 'foo'
+                }
+            }
+
+            class TestInterceptor implements Interceptor { }
+            '''
+
+        assertTreeStructure(source, CompilePhase.CANONICALIZATION,
+                [
+                        startsWith('ClassNode - TestInterceptor'),
+                        eq('Object Initializers'),
+                        eq('ExpressionStatement - MethodCallExpression')
                 ],
                 adapter)
 


Mime
View raw message