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);
}
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;
}
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);
}
}
}
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));
}
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()));
}
}
}
Aggregations