use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
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-core by groovy.
the class FlatNodeListTraversal method process.
public AST process(AST t) {
GroovySourceAST node = (GroovySourceAST) t;
// fetch all the nodes in this AST into a List
NodeCollector collector = new NodeCollector();
AntlrASTProcessor internalTraversal = new PreOrderTraversal(collector);
internalTraversal.process(t);
List listOfAllNodesInThisAST = collector.getNodes();
// process each node in turn
setUp(node);
Iterator itr = listOfAllNodesInThisAST.iterator();
while (itr.hasNext()) {
GroovySourceAST currentNode = (GroovySourceAST) itr.next();
accept(currentNode);
}
tearDown(node);
return null;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
the class SimpleGroovyClassDocAssembler method recurseDownImportBranch.
private String recurseDownImportBranch(GroovySourceAST t) {
if (t != null) {
if (t.getType() == DOT) {
GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild();
GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling();
return (recurseDownImportBranch(firstChild) + "/" + recurseDownImportBranch(secondChild));
}
if (t.getType() == IDENT) {
return t.getText();
}
if (t.getType() == STAR) {
return t.getText();
}
}
return "";
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
the class SimpleGroovyClassDocAssembler method getTypeNodeAsText.
private String getTypeNodeAsText(GroovySourceAST typeNode, String defaultText) {
// TODO refactor to retain richer type information rather than converting to String
if (typeNode == null) {
return defaultText;
}
if (typeNode.getType() == TYPE) {
return getAsText(typeNode, defaultText);
} else if (typeNode.getType() == TYPE_ARGUMENT) {
return getTypeNodeAsText((GroovySourceAST) typeNode.getFirstChild(), defaultText);
} else if (typeNode.getType() == WILDCARD_TYPE) {
AST next = typeNode.getNextSibling();
if (next == null && typeNode.getFirstChild() != null) {
// Java2Groovy produces a slightly different tree structure (TODO fix converter or java.g instead?)
next = typeNode.getFirstChild();
}
if (next == null)
return "?";
String boundType = getTypeNodeAsText((GroovySourceAST) next.getFirstChild(), defaultText);
if (next.getType() == TYPE_UPPER_BOUNDS)
return "? extends " + boundType;
if (next.getType() == TYPE_LOWER_BOUNDS)
return "? super " + boundType;
} else if (typeNode.getType() == IDENT) {
return getAsTextCurrent(typeNode, defaultText);
}
return defaultText;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
the class SimpleGroovyClassDocAssembler method getCurrentClassDoc.
private SimpleGroovyClassDoc getCurrentClassDoc() {
if (stack.isEmpty())
return null;
GroovySourceAST node = getParentNode();
if (isTopLevelConstruct(node))
return foundClasses.get(getIdentFor(node));
GroovySourceAST saved = stack.pop();
SimpleGroovyClassDoc result = getCurrentClassDoc();
stack.push(saved);
return result;
}
Aggregations