Search in sources :

Example 11 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.

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;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST) Iterator(java.util.Iterator) List(java.util.List) AntlrASTProcessor(org.codehaus.groovy.antlr.AntlrASTProcessor)

Example 12 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.

the class SimpleGroovyClassDocAssembler method getGrandParentNode.

private GroovySourceAST getGrandParentNode() {
    GroovySourceAST grandParentNode = null;
    GroovySourceAST parentNode;
    GroovySourceAST currentNode = stack.pop();
    if (!stack.empty()) {
        parentNode = stack.pop();
        if (!stack.empty()) {
            grandParentNode = stack.peek();
        }
        stack.push(parentNode);
    }
    stack.push(currentNode);
    return grandParentNode;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 13 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.

the class SimpleGroovyClassDocAssembler method getAnnotationNames.

private List<String> getAnnotationNames(GroovySourceAST modifiers) {
    List<String> annotationNames = new ArrayList<String>();
    List<GroovySourceAST> annotations = modifiers.childrenOfType(ANNOTATION);
    for (GroovySourceAST annotation : annotations) {
        annotationNames.add(buildName((GroovySourceAST) annotation.getFirstChild()));
    }
    return annotationNames;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 14 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.

the class SimpleGroovyClassDocAssembler method getIdentPlusTypeArgsFor.

private String getIdentPlusTypeArgsFor(GroovySourceAST gpn) {
    GroovySourceAST groovySourceAST = gpn.childOfType(IDENT);
    StringBuilder ident = new StringBuilder();
    ident.append(groovySourceAST.getText());
    GroovySourceAST typeParams = (GroovySourceAST) groovySourceAST.getNextSibling();
    getTypeParameters(typeParams, ident, "def");
    return ident.toString();
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 15 with GroovySourceAST

use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.

the class SimpleGroovyClassDocAssembler method getTypeArguments.

private void getTypeArguments(GroovySourceAST child, StringBuilder result, String defaultText) {
    if (child != null && child.getType() == TYPE_ARGUMENTS && child.getNumberOfChildren() > 0) {
        result.append("<");
        GroovySourceAST typeArgumentsNext = (GroovySourceAST) child.getFirstChild();
        List<String> typeArgumentParts = new ArrayList<String>();
        while (typeArgumentsNext != null) {
            if (typeArgumentsNext.getType() == TYPE_ARGUMENT && typeArgumentsNext.getNumberOfChildren() > 0) {
                typeArgumentParts.add(getTypeNodeAsText((GroovySourceAST) typeArgumentsNext.getFirstChild(), defaultText));
            }
            typeArgumentsNext = (GroovySourceAST) typeArgumentsNext.getNextSibling();
        }
        result.append(DefaultGroovyMethods.join(typeArgumentParts, ", "));
        result.append(">");
    }
}
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