use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
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);
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class PreJava2GroovyConverter method visitJavaArrayInit.
/**
* Handle Arrays. Examples:
*
* <pre>
* String[] myArray = new String[] {"a","b","c"};
*
* becomes
*
* String[] myArray = ["a", "b", "c"]
*
* ---
*
* To convert node (t) and surrounding nodes into the right structure for List Constructor
*
* (a) java/EXPR
* |
* +- (b) java/new
* |
* + (t) java/ARRAY_INIT
*
* becomes
*
* (a) groovy/LIST_CONSTRUCTOR (via ARRAY_INIT as temporary marker type)
* |
* +- (t) groovy/ELIST
*
* * note: node (b) is thrown away...
* </pre>
*/
private void visitJavaArrayInit(GroovySourceAST t) {
// given that we might have a grandParent...
if (stack.size() > 2) {
GroovySourceAST grandParent = getGrandParentNode();
if (grandParent.getType() == JavaTokenTypes.EXPR) {
//set type as indicator for Java2GroovyConvertor to turn into LIST_CONSTRUCTOR
grandParent.setType(JavaTokenTypes.ARRAY_INIT);
grandParent.setFirstChild(t);
t.setType(JavaTokenTypes.ELIST);
}
}
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class CompositeVisitor method pop.
public GroovySourceAST pop() {
GroovySourceAST lastNodePopped = null;
Iterator itr = backToFrontVisitors.iterator();
while (itr.hasNext()) {
lastNodePopped = (GroovySourceAST) ((Visitor) itr.next()).pop();
}
return lastNodePopped;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
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();
}
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
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);
}
Aggregations