You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2015/10/07 21:26:48 UTC

[28/37] incubator-groovy git commit: ASTMatcher: Fix matcher constraints ordering

ASTMatcher: Fix matcher constraints ordering


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

Branch: refs/heads/master
Commit: bea3042479e330ee4e72b5676390d89ff425274d
Parents: 3271e6d
Author: Cedric Champeau <ce...@gmail.com>
Authored: Wed Nov 12 10:58:06 2014 +0100
Committer: Sergei Egorov <bs...@gmail.com>
Committed: Mon Sep 28 14:33:12 2015 +0300

----------------------------------------------------------------------
 .../groovy/macro/matcher/ASTMatcher.groovy       |  4 ++--
 .../groovy/macro/matcher/ASTMatcherTest.groovy   | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/bea30424/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/matcher/ASTMatcher.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/matcher/ASTMatcher.groovy b/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/matcher/ASTMatcher.groovy
index ab8b459..e8d83f7 100644
--- a/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/matcher/ASTMatcher.groovy
+++ b/subprojects/groovy-macro/src/main/groovy/org/codehaus/groovy/macro/matcher/ASTMatcher.groovy
@@ -131,17 +131,17 @@ class ASTMatcher extends ContextualClassCodeVisitor {
 
         boolean doPush = treeContext.node!=foundNode && foundNode instanceof ASTNode
         if (doPush) {
+            pushContext((ASTNode)foundNode)
             if (patternNode instanceof ASTNode) {
                 storeContraints(patternNode)
             }
-            pushContext((ASTNode)foundNode)
         }
 
         if (!isWildcardExpression(patternNode)) {
             String placeholder = findPlaceholder(patternNode)
             if (placeholder) {
                 def alreadySeenAST = treeContext.getUserdata("placeholder_$placeholder", true)
-                if (!alreadySeenAST) {
+                if (alreadySeenAST==null) {
                     treeContext.parent.putUserdata("placeholder_$placeholder", foundNode)
                 } else {
                     // during the tree inspection, placeholder already found

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/bea30424/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/matcher/ASTMatcherTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/matcher/ASTMatcherTest.groovy b/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/matcher/ASTMatcherTest.groovy
index c8ff1fc..35301e4 100644
--- a/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/matcher/ASTMatcherTest.groovy
+++ b/subprojects/groovy-macro/src/test/groovy/org/codehaus/groovy/macro/matcher/ASTMatcherTest.groovy
@@ -708,4 +708,23 @@ class ASTMatcherTest extends GroovyTestCase {
         }
     }
 
+    void testInlineMacroCombinationWithConstraints() {
+        use(ASTMatcher) {
+            def ast1 = macro { a + b }
+            def ast2 = macro { b + b }
+            def ast3 = macro { b + c }
+            def ast4 = macro { b - b }
+            def pattern = macro {
+                $v { macro { a }.withConstraints { placeholder a } } + $v { macro { b } }
+            }.withConstraints {
+                anyToken()
+            }
+            assert pattern instanceof BinaryExpression
+            assert ast1.matches(pattern)
+            assert ast2.matches(pattern)
+            assert !ast3.matches(pattern)
+            assert ast4.matches(pattern)
+        }
+    }
+
 }