Search in sources :

Example 21 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.

the class TraversalHelper method acceptChildren.

protected void acceptChildren(GroovySourceAST t) {
    if (t != null) {
        GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
        if (child != null) {
            accept(child);
            acceptSiblings(child);
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 22 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.

the class TraversalHelper method accept_FirstSecondAndThirdChild_v_v_ForthChild.

protected void accept_FirstSecondAndThirdChild_v_v_ForthChild(GroovySourceAST t) {
    GroovySourceAST child1 = (GroovySourceAST) t.getFirstChild();
    if (child1 != null) {
        accept(child1);
        GroovySourceAST child2 = (GroovySourceAST) child1.getNextSibling();
        if (child2 != null) {
            accept(child2);
            GroovySourceAST child3 = (GroovySourceAST) child2.getNextSibling();
            if (child3 != null) {
                accept(child3);
                openingVisit(t);
                GroovySourceAST child4 = (GroovySourceAST) child3.getNextSibling();
                if (child4 != null) {
                    subsequentVisit(t);
                    accept(child4);
                }
            }
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 23 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.

the class TraversalHelper method accept_v_FirstChildsFirstChild_v_RestOfTheChildren.

protected void accept_v_FirstChildsFirstChild_v_RestOfTheChildren(GroovySourceAST t) {
    openingVisit(t);
    GroovySourceAST expr = t.childAt(0);
    skip(expr);
    accept(expr.childAt(0));
    closingVisit(t);
    acceptSiblings(expr);
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 24 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.

the class TraversalHelper method accept_v_FirstChildsFirstChild_v_Child2_Child3_v_Child4_v___v_LastChild.

protected void accept_v_FirstChildsFirstChild_v_Child2_Child3_v_Child4_v___v_LastChild(GroovySourceAST t) {
    openingVisit(t);
    GroovySourceAST expr2 = t.childAt(0);
    skip(expr2);
    accept(expr2.childAt(0));
    closingVisit(t);
    GroovySourceAST sibling = (GroovySourceAST) expr2.getNextSibling();
    boolean firstSList = true;
    while (sibling != null) {
        if (!firstSList) {
            subsequentVisit(t);
        }
        firstSList = false;
        accept(sibling);
        sibling = (GroovySourceAST) sibling.getNextSibling();
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 25 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.

the class PreJava2GroovyConverter method swapTwoChildren.

/**
 * To swap two children of node t...
 *
 *<pre>
 *   (t)
 *    |
 *    |
 *   (a) -- (b)
 *
 * t.down = firstNode
 * a.right = b
 * b.right = null
 *</pre>
 * becomes
 *<pre>
 *   (t)
 *    |
 *    |
 *   (b) -- (a)
 *
 * t.down = b
 * a.right = null
 * b.right = a
 *</pre>
 *
 * todo - build API of basic tree mutations like this method.
 */
public void swapTwoChildren(GroovySourceAST t) {
    // this swaps the two child nodes, see javadoc above for explanation of implementation
    GroovySourceAST a = (GroovySourceAST) t.getFirstChild();
    GroovySourceAST b = (GroovySourceAST) a.getNextSibling();
    t.setFirstChild(b);
    a.setNextSibling(null);
    b.setNextSibling(a);
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Aggregations

GroovySourceAST (org.codehaus.groovy.antlr.GroovySourceAST)77 AST (antlr.collections.AST)4 Iterator (java.util.Iterator)2 List (java.util.List)2 AntlrASTProcessor (org.codehaus.groovy.antlr.AntlrASTProcessor)2 LineColumn (org.codehaus.groovy.antlr.LineColumn)2