use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method handleDefaultValue.
private void handleDefaultValue(GroovySourceAST currentNode, SimpleGroovyParameter parameter) {
GroovySourceAST paramPart = (GroovySourceAST) currentNode.getFirstChild();
for (int i = 1; i < currentNode.getNumberOfChildren(); i++) {
paramPart = (GroovySourceAST) paramPart.getNextSibling();
}
GroovySourceAST nodeToProcess = paramPart;
if (paramPart.getNumberOfChildren() > 0) {
nodeToProcess = (GroovySourceAST) paramPart.getFirstChild();
}
// hack warning!
// TODO handle , and ) when they occur within Strings
parameter.setDefaultValue(getChildTextFromSource(nodeToProcess, ",)"));
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method getAsTextCurrent.
private String getAsTextCurrent(GroovySourceAST node, String defaultText) {
if (node == null)
return defaultText;
switch(node.getType()) {
// literals
case LITERAL_boolean:
return "boolean";
case LITERAL_byte:
return "byte";
case LITERAL_char:
return "char";
// note: LITERAL_def never created
case LITERAL_double:
return "double";
case LITERAL_float:
return "float";
case LITERAL_int:
return "int";
case LITERAL_long:
return "long";
case LITERAL_short:
return "short";
case LITERAL_void:
return "void";
case ARRAY_DECLARATOR:
String componentType = getAsText(node, defaultText);
if (!componentType.equals("def"))
return componentType + "[]";
return "java/lang/Object[]";
// identifiers
case IDENT:
StringBuilder ident = new StringBuilder();
ident.append(node.getText());
GroovySourceAST identChild = (GroovySourceAST) node.getFirstChild();
getTypeArguments(identChild, ident, defaultText);
return ident.toString();
case DOT:
StringBuilder dot = new StringBuilder();
GroovySourceAST dotChild = (GroovySourceAST) node.getFirstChild();
while (dotChild != null) {
if (dotChild.getType() == IDENT || dotChild.getType() == DOT) {
if (dot.length() > 0)
dot.append("/");
dot.append(getAsTextCurrent(dotChild, defaultText));
} else if (dotChild.getType() == TYPE_ARGUMENTS) {
getTypeArguments(dotChild, dot, defaultText);
}
dotChild = (GroovySourceAST) dotChild.getNextSibling();
}
return dot.toString();
}
return defaultText;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method buildName.
private String buildName(GroovySourceAST t) {
if (t != null) {
if (t.getType() == DOT) {
GroovySourceAST firstChild = (GroovySourceAST) t.getFirstChild();
GroovySourceAST secondChild = (GroovySourceAST) firstChild.getNextSibling();
return (buildName(firstChild) + "/" + buildName(secondChild));
}
if (t.getType() == IDENT) {
return t.getText();
}
}
return "";
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method getDefaultValue.
// hack warning! fragile! TODO find a better way
private String getDefaultValue(GroovySourceAST t) {
GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
if (t.getNumberOfChildren() != 4)
return null;
for (int i = 1; i < t.getNumberOfChildren(); i++) {
child = (GroovySourceAST) child.getNextSibling();
}
GroovySourceAST nodeToProcess = child;
if (child.getType() != ANNOTATION_ARRAY_INIT && child.getNumberOfChildren() > 0) {
nodeToProcess = (GroovySourceAST) child.getFirstChild();
}
return getChildTextFromSource(nodeToProcess, ";");
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method visitImport.
@Override
public void visitImport(GroovySourceAST t, int visit) {
if (visit == OPENING_VISIT) {
String importTextWithSlashesInsteadOfDots = extractImportPath(t);
GroovySourceAST child = t.childOfType(LITERAL_as);
if (child != null) {
String alias = child.childOfType(DOT).getNextSibling().getText();
child = child.childOfType(DOT);
importTextWithSlashesInsteadOfDots = recurseDownImportBranch(child);
aliases.put(alias, importTextWithSlashesInsteadOfDots);
}
importedClassesAndPackages.add(importTextWithSlashesInsteadOfDots);
}
}
Aggregations