use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
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-core by groovy.
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);
}
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
the class SimpleGroovyClassDocAssembler method processModifiers.
// return true if a property is found
private boolean processModifiers(GroovySourceAST t, SimpleGroovyAbstractableElementDoc memberOrClass) {
GroovySourceAST modifiers = t.childOfType(MODIFIERS);
boolean hasNonPublicVisibility = false;
boolean hasPublicVisibility = false;
if (modifiers != null) {
AST currentModifier = modifiers.getFirstChild();
while (currentModifier != null) {
int type = currentModifier.getType();
switch(type) {
case LITERAL_public:
memberOrClass.setPublic(true);
hasPublicVisibility = true;
break;
case LITERAL_protected:
memberOrClass.setProtected(true);
hasNonPublicVisibility = true;
break;
case LITERAL_private:
memberOrClass.setPrivate(true);
hasNonPublicVisibility = true;
break;
case LITERAL_static:
memberOrClass.setStatic(true);
break;
case FINAL:
memberOrClass.setFinal(true);
break;
case ABSTRACT:
memberOrClass.setAbstract(true);
break;
}
currentModifier = currentModifier.getNextSibling();
}
if (!hasNonPublicVisibility && isGroovy && !(memberOrClass instanceof GroovyFieldDoc)) {
// in groovy, methods and classes are assumed public, unless informed otherwise
if (isPackageScope(modifiers)) {
memberOrClass.setPackagePrivate(true);
hasNonPublicVisibility = true;
} else {
memberOrClass.setPublic(true);
}
} else if (!hasNonPublicVisibility && !hasPublicVisibility && !isGroovy) {
if (insideInterface(memberOrClass) || insideAnnotationDef(memberOrClass)) {
memberOrClass.setPublic(true);
} else {
memberOrClass.setPackagePrivate(true);
}
}
if (memberOrClass instanceof GroovyFieldDoc && isGroovy && !hasNonPublicVisibility & !hasPublicVisibility) {
if (isPackageScope(modifiers)) {
memberOrClass.setPackagePrivate(true);
hasNonPublicVisibility = true;
}
}
if (memberOrClass instanceof GroovyFieldDoc && !hasNonPublicVisibility && !hasPublicVisibility && isGroovy)
return true;
} else if (isGroovy && !(memberOrClass instanceof GroovyFieldDoc)) {
// in groovy, methods and classes are assumed public, unless informed otherwise
memberOrClass.setPublic(true);
} else if (!isGroovy) {
if (insideInterface(memberOrClass) || insideAnnotationDef(memberOrClass)) {
memberOrClass.setPublic(true);
} else {
memberOrClass.setPackagePrivate(true);
}
}
return memberOrClass instanceof GroovyFieldDoc && isGroovy && !hasNonPublicVisibility & !hasPublicVisibility;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy-core by groovy.
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-core by groovy.
the class TraversalHelper method accept_v_FirstChild_v_SecondChild_v___LastChild_v.
protected void accept_v_FirstChild_v_SecondChild_v___LastChild_v(GroovySourceAST t) {
openingVisit(t);
GroovySourceAST child = (GroovySourceAST) t.getFirstChild();
if (child != null) {
accept(child);
GroovySourceAST sibling = (GroovySourceAST) child.getNextSibling();
while (sibling != null) {
subsequentVisit(t);
accept(sibling);
sibling = (GroovySourceAST) sibling.getNextSibling();
}
}
closingVisit(t);
}
Aggregations