private String getTypeNodeAsText(GroovySourceAST typeNode, String defaultText) {
String returnValue = defaultText;
if (typeNode != null &&
typeNode.getType() == GroovyTokenTypes.TYPE &&
typeNode.getNumberOfChildren() > 0) {
GroovySourceAST child = (GroovySourceAST) typeNode.getFirstChild(); // assume type has only one child // todo type of "foo.bar.Wibble"
switch (child.getType()) {
// literals
case GroovyTokenTypes.LITERAL_boolean: returnValue = "boolean"; break;
case GroovyTokenTypes.LITERAL_byte: returnValue = "byte"; break;
case GroovyTokenTypes.LITERAL_char: returnValue = "char"; break;
// note: LITERAL_def never created
case GroovyTokenTypes.LITERAL_double: returnValue = "double"; break;
case GroovyTokenTypes.LITERAL_float: returnValue = "float"; break;
case GroovyTokenTypes.LITERAL_int: returnValue = "int"; break;
case GroovyTokenTypes.LITERAL_long: returnValue = "long"; break;
case GroovyTokenTypes.LITERAL_short: returnValue = "short"; break;
case GroovyTokenTypes.LITERAL_void: returnValue = "void"; break;
// identifiers
case GroovyTokenTypes.IDENT: returnValue = child.getText(); break;
}
}
return returnValue;
}