Search in sources :

Example 31 with GroovySourceAST

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

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 32 with GroovySourceAST

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

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 33 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method addParametersTo.

private void addParametersTo(GroovySourceAST t, SimpleGroovyExecutableMemberDoc executableMemberDoc) {
    // parameters
    GroovySourceAST parametersNode = t.childOfType(PARAMETERS);
    if (parametersNode != null && parametersNode.getNumberOfChildren() > 0) {
        GroovySourceAST currentNode = (GroovySourceAST) parametersNode.getFirstChild();
        while (currentNode != null) {
            String parameterTypeName = getTypeOrDefault(currentNode);
            String parameterName = getText(currentNode.childOfType(IDENT));
            SimpleGroovyParameter parameter = new SimpleGroovyParameter(parameterName);
            parameter.setVararg(currentNode.getType() == VARIABLE_PARAMETER_DEF);
            parameter.setTypeName(parameterTypeName);
            GroovySourceAST modifiers = currentNode.childOfType(MODIFIERS);
            if (modifiers != null) {
                List<GroovySourceAST> annotations = modifiers.childrenOfType(ANNOTATION);
                for (GroovySourceAST a : annotations) {
                    addAnnotationRef(parameter, a);
                }
            }
            executableMemberDoc.add(parameter);
            if (currentNode.getNumberOfChildren() == 4) {
                handleDefaultValue(currentNode, parameter);
            }
            currentNode = (GroovySourceAST) currentNode.getNextSibling();
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 34 with GroovySourceAST

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

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) {
                    if (dot.length() > 0)
                        dot.append("/");
                    dot.append(getAsTextCurrent(dotChild, defaultText));
                } else if (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 35 with GroovySourceAST

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

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 "";
}
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