Search in sources :

Example 41 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method processModifiers.

// return true if a property is found
private boolean processModifiers(GroovySourceAST t, SimpleGroovyAbstractableElementDoc memberOrClass) {
    GroovySourceAST modifiers = t.childOfType(MODIFIERS);
    boolean hasNonPublicVisibility = false;
    boolean hasPublicVisibility = false;
    if (modifiers != null) {
        AST currentModifier = modifiers.getFirstChild();
        while (currentModifier != null) {
            int type = currentModifier.getType();
            switch(type) {
                case LITERAL_public:
                    memberOrClass.setPublic(true);
                    hasPublicVisibility = true;
                    break;
                case LITERAL_protected:
                    memberOrClass.setProtected(true);
                    hasNonPublicVisibility = true;
                    break;
                case LITERAL_private:
                    memberOrClass.setPrivate(true);
                    hasNonPublicVisibility = true;
                    break;
                case LITERAL_static:
                    memberOrClass.setStatic(true);
                    break;
                case FINAL:
                    memberOrClass.setFinal(true);
                    break;
                case ABSTRACT:
                    memberOrClass.setAbstract(true);
                    break;
            }
            currentModifier = currentModifier.getNextSibling();
        }
        if (!hasNonPublicVisibility && isGroovy && !(memberOrClass instanceof GroovyFieldDoc)) {
            // in groovy, methods and classes are assumed public, unless informed otherwise
            if (isPackageScope(modifiers)) {
                memberOrClass.setPackagePrivate(true);
                hasNonPublicVisibility = true;
            } else {
                memberOrClass.setPublic(true);
            }
        } else if (!hasNonPublicVisibility && !hasPublicVisibility && !isGroovy) {
            if (insideInterface(memberOrClass) || insideAnnotationDef(memberOrClass)) {
                memberOrClass.setPublic(true);
            } else {
                memberOrClass.setPackagePrivate(true);
            }
        }
        if (memberOrClass instanceof GroovyFieldDoc && isGroovy && !hasNonPublicVisibility & !hasPublicVisibility) {
            if (isPackageScope(modifiers)) {
                memberOrClass.setPackagePrivate(true);
                hasNonPublicVisibility = true;
            }
        }
        if (memberOrClass instanceof GroovyFieldDoc && !hasNonPublicVisibility && !hasPublicVisibility && isGroovy)
            return true;
    } else if (isGroovy && !(memberOrClass instanceof GroovyFieldDoc)) {
        // in groovy, methods and classes are assumed public, unless informed otherwise
        memberOrClass.setPublic(true);
    } else if (!isGroovy) {
        if (insideInterface(memberOrClass) || insideAnnotationDef(memberOrClass)) {
            memberOrClass.setPublic(true);
        } else {
            memberOrClass.setPackagePrivate(true);
        }
    }
    return memberOrClass instanceof GroovyFieldDoc && isGroovy && !hasNonPublicVisibility & !hasPublicVisibility;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST) AST(antlr.collections.AST) GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 42 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method getTypeParameters.

private void getTypeParameters(GroovySourceAST child, StringBuilder result, String defaultText) {
    if (child != null && child.getType() == TYPE_PARAMETERS && child.getNumberOfChildren() > 0) {
        result.append("<");
        GroovySourceAST typeParametersNext = (GroovySourceAST) child.getFirstChild();
        List<String> typeParameterParts = new ArrayList<String>();
        while (typeParametersNext != null) {
            if (typeParametersNext.getType() == TYPE_PARAMETER && typeParametersNext.getNumberOfChildren() > 0) {
                typeParameterParts.add(getTypeNodeAsText((GroovySourceAST) typeParametersNext.getFirstChild(), defaultText));
            }
            typeParametersNext = (GroovySourceAST) typeParametersNext.getNextSibling();
        }
        result.append(DefaultGroovyMethods.join(typeParameterParts, ", "));
        result.append(">");
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 43 with GroovySourceAST

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

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

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

the class SimpleGroovyClassDocAssembler method getParentNode.

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

Example 45 with GroovySourceAST

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

the class SimpleGroovyClassDocAssembler method getCurrentClassDoc.

private SimpleGroovyClassDoc getCurrentClassDoc() {
    if (stack.isEmpty())
        return null;
    GroovySourceAST node = getParentNode();
    if (isTopLevelConstruct(node) && foundClasses != null) {
        return foundClasses.get(getIdentFor(node));
    }
    GroovySourceAST saved = stack.pop();
    SimpleGroovyClassDoc result = getCurrentClassDoc();
    stack.push(saved);
    return result;
}
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