Search in sources :

Example 36 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method handleDefaultValue.

private void handleDefaultValue(GroovySourceAST currentNode, SimpleGroovyParameter parameter) {
    GroovySourceAST paramPart = (GroovySourceAST) currentNode.getFirstChild();
    for (int i = 1; i < currentNode.getNumberOfChildren(); i++) {
        paramPart = (GroovySourceAST) paramPart.getNextSibling();
    }
    GroovySourceAST nodeToProcess = paramPart;
    if (paramPart.getNumberOfChildren() > 0) {
        nodeToProcess = (GroovySourceAST) paramPart.getFirstChild();
    }
    // hack warning!
    // TODO handle , and ) when they occur within Strings
    parameter.setDefaultValue(getChildTextFromSource(nodeToProcess, ",)"));
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 37 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method getAsTextCurrent.

private String getAsTextCurrent(GroovySourceAST node, String defaultText) {
    if (node == null)
        return defaultText;
    switch(node.getType()) {
        // literals
        case LITERAL_boolean:
            return "boolean";
        case LITERAL_byte:
            return "byte";
        case LITERAL_char:
            return "char";
        // note: LITERAL_def never created
        case LITERAL_double:
            return "double";
        case LITERAL_float:
            return "float";
        case LITERAL_int:
            return "int";
        case LITERAL_long:
            return "long";
        case LITERAL_short:
            return "short";
        case LITERAL_void:
            return "void";
        case ARRAY_DECLARATOR:
            String componentType = getAsText(node, defaultText);
            if (!componentType.equals("def"))
                return componentType + "[]";
            return "java/lang/Object[]";
        // identifiers
        case IDENT:
            StringBuilder ident = new StringBuilder();
            ident.append(node.getText());
            GroovySourceAST identChild = (GroovySourceAST) node.getFirstChild();
            getTypeArguments(identChild, ident, defaultText);
            return ident.toString();
        case DOT:
            StringBuilder dot = new StringBuilder();
            GroovySourceAST dotChild = (GroovySourceAST) node.getFirstChild();
            while (dotChild != null) {
                if (dotChild.getType() == IDENT || dotChild.getType() == DOT) {
                    if (dot.length() > 0)
                        dot.append("/");
                    dot.append(getAsTextCurrent(dotChild, defaultText));
                } else if (dotChild.getType() == TYPE_ARGUMENTS) {
                    getTypeArguments(dotChild, dot, defaultText);
                }
                dotChild = (GroovySourceAST) dotChild.getNextSibling();
            }
            return dot.toString();
    }
    return defaultText;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 38 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method buildName.

private String buildName(GroovySourceAST t) {
    if (t != null) {
        if (t.getType() == DOT) {
            GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild();
            GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling();
            return (buildName(firstChild) + "/" + buildName(secondChild));
        }
        if (t.getType() == IDENT) {
            return t.getText();
        }
    }
    return "";
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 39 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method getDefaultValue.

// hack warning! fragile! TODO find a better way
private String getDefaultValue(GroovySourceAST t) {
    GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
    if (t.getNumberOfChildren() != 4)
        return null;
    for (int i = 1; i < t.getNumberOfChildren(); i++) {
        child = (GroovySourceAST) child.getNextSibling();
    }
    GroovySourceAST nodeToProcess = child;
    if (child.getType() != ANNOTATION_ARRAY_INIT && child.getNumberOfChildren() > 0) {
        nodeToProcess = (GroovySourceAST) child.getFirstChild();
    }
    return getChildTextFromSource(nodeToProcess, ";");
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 40 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method visitImport.

@Override
public void visitImport(GroovySourceAST t, int visit) {
    if (visit == OPENING_VISIT) {
        String importTextWithSlashesInsteadOfDots = extractImportPath(t);
        GroovySourceAST child = t.childOfType(LITERAL_as);
        if (child != null) {
            String alias = child.childOfType(DOT).getNextSibling().getText();
            child = child.childOfType(DOT);
            importTextWithSlashesInsteadOfDots = recurseDownImportBranch(child);
            aliases.put(alias, importTextWithSlashesInsteadOfDots);
        }
        importedClassesAndPackages.add(importTextWithSlashesInsteadOfDots);
    }
}
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