Search in sources :

Example 51 with GroovySourceAST

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

the class TraversalHelper method acceptChildren.

protected void acceptChildren(GroovySourceAST t) {
    if (t != null) {
        GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
        if (child != null) {
            accept(child);
            acceptSiblings(child);
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 52 with GroovySourceAST

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

the class TraversalHelper method accept_FirstChild_v_SecondChildsChildren_v.

protected void accept_FirstChild_v_SecondChildsChildren_v(GroovySourceAST t) {
    accept(t.childAt(0));
    openingVisit(t);
    GroovySourceAST secondChild = t.childAt(1);
    if (secondChild != null) {
        acceptChildren(secondChild);
    }
    closingVisit(t);
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 53 with GroovySourceAST

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

the class TraversalHelper method acceptSiblings.

protected void acceptSiblings(GroovySourceAST t) {
    if (t != null) {
        GroovySourceAST sibling = (GroovySourceAST) t.getNextSibling();
        while (sibling != null) {
            accept(sibling);
            sibling = (GroovySourceAST) sibling.getNextSibling();
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 54 with GroovySourceAST

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

the class SourceMetaDataVisitor method pop.

public GroovySourceAST pop() {
    if (!parseStack.isEmpty()) {
        GroovySourceAST ast = parseStack.removeFirst();
        ClassMetaData classMetaData = typeTokens.remove(ast);
        if (classMetaData != null) {
            assert classMetaData == classStack.getFirst();
            classStack.removeFirst();
        }
        return ast;
    }
    return null;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 55 with GroovySourceAST

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

the class SourceMetaDataVisitor method maybeAddPropertyFromField.

private void maybeAddPropertyFromField(GroovySourceAST t) {
    GroovySourceAST parentNode = getParentNode();
    boolean isField = parentNode != null && parentNode.getType() == OBJBLOCK;
    if (!isField) {
        return;
    }
    int modifiers = extractModifiers(t);
    boolean isConst = getCurrentClass().isInterface() || (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers));
    if (isConst) {
        visitConst(t);
        return;
    }
    boolean isProp = groovy && !Modifier.isStatic(modifiers) && !Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers);
    if (!isProp) {
        return;
    }
    ASTIterator children = new ASTIterator(t);
    children.skip(MODIFIERS);
    String propertyName = extractIdent(t);
    TypeMetaData propertyType = extractTypeName(children.current);
    ClassMetaData currentClass = getCurrentClass();
    MethodMetaData getterMethod = currentClass.addMethod(String.format("get%s", StringUtils.capitalize(propertyName)), propertyType, "");
    PropertyMetaData property = currentClass.addReadableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), getterMethod);
    findAnnotations(t, property);
    if (!Modifier.isFinal(modifiers)) {
        MethodMetaData setterMethod = currentClass.addMethod(String.format("set%s", StringUtils.capitalize(propertyName)), TypeMetaData.VOID, "");
        setterMethod.addParameter(propertyName, propertyType);
        currentClass.addWriteableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), setterMethod);
    }
}
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