Search in sources :

Example 56 with GroovySourceAST

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

the class SourceMetaDataVisitor method visitConst.

private void visitConst(GroovySourceAST t) {
    String constName = extractIdent(t);
    GroovySourceAST assign = t.childOfType(ASSIGN);
    String value = null;
    if (assign != null) {
        value = extractLiteral(assign.getFirstChild());
    }
    getCurrentClass().getConstants().put(constName, value);
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 57 with GroovySourceAST

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

the class SourceMetaDataVisitor method extractModifiers.

private int extractModifiers(GroovySourceAST ast) {
    GroovySourceAST modifiers = ast.childOfType(MODIFIERS);
    if (modifiers == null) {
        return 0;
    }
    int modifierFlags = 0;
    for (GroovySourceAST child = (GroovySourceAST) modifiers.getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) {
        switch(child.getType()) {
            case LITERAL_private:
                modifierFlags |= Modifier.PRIVATE;
                break;
            case LITERAL_protected:
                modifierFlags |= Modifier.PROTECTED;
                break;
            case LITERAL_public:
                modifierFlags |= Modifier.PUBLIC;
                break;
            case FINAL:
                modifierFlags |= Modifier.FINAL;
                break;
            case LITERAL_static:
                modifierFlags |= Modifier.STATIC;
                break;
        }
    }
    return modifierFlags;
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 58 with GroovySourceAST

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

the class SourceMetaDataVisitor method findAnnotations.

private void findAnnotations(GroovySourceAST t, AbstractLanguageElement currentElement) {
    GroovySourceAST modifiers = t.childOfType(MODIFIERS);
    if (modifiers != null) {
        List<GroovySourceAST> children = modifiers.childrenOfType(ANNOTATION);
        for (GroovySourceAST child : children) {
            String identifier = extractIdent(child);
            currentElement.addAnnotationTypeName(identifier);
        }
    }
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 59 with GroovySourceAST

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

the class SourceMetaDataVisitor method extractName.

private String extractName(GroovySourceAST t) {
    if (t.getType() == DOT) {
        GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild();
        GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling();
        return extractName(firstChild) + "." + extractName(secondChild);
    }
    if (t.getType() == IDENT) {
        return t.getText();
    }
    if (t.getType() == STAR) {
        return t.getText();
    }
    GroovySourceAST child = t.childOfType(DOT);
    if (child != null) {
        return extractName(child);
    }
    child = t.childOfType(IDENT);
    if (child != null) {
        return extractName(child);
    }
    throw new RuntimeException(String.format("Unexpected token in name: %s", t));
}
Also used : GroovySourceAST(org.codehaus.groovy.antlr.GroovySourceAST)

Example 60 with GroovySourceAST

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

the class SourceMetaDataVisitor method extractTypeName.

private void extractTypeName(GroovySourceAST ast, TypeMetaData type) {
    if (ast == null) {
        type.setName("java.lang.Object");
        return;
    }
    switch(ast.getType()) {
        case LITERAL_boolean:
            type.setName("boolean");
            return;
        case LITERAL_byte:
            type.setName("byte");
            return;
        case LITERAL_char:
            type.setName("char");
            return;
        case LITERAL_double:
            type.setName("double");
            return;
        case LITERAL_float:
            type.setName("float");
            return;
        case LITERAL_int:
            type.setName("int");
            return;
        case LITERAL_long:
            type.setName("long");
            return;
        case LITERAL_void:
            type.setName("void");
            return;
        case ARRAY_DECLARATOR:
            extractTypeName((GroovySourceAST) ast.getFirstChild(), type);
            type.addArrayDimension();
            return;
    }
    type.setName(extractName(ast));
    GroovySourceAST typeArgs = ast.childOfType(TYPE_ARGUMENTS);
    if (typeArgs != null) {
        for (GroovySourceAST child = (GroovySourceAST) typeArgs.getFirstChild(); child != null; child = (GroovySourceAST) child.getNextSibling()) {
            assert child.getType() == TYPE_ARGUMENT;
            type.addTypeArg(extractTypeName((GroovySourceAST) child.getFirstChild()));
        }
    }
}
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