use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
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 by apache.
the class SimpleGroovyClassDocAssembler method getTypeParameters.
private void getTypeParameters(GroovySourceAST child, StringBuilder result, String defaultText) {
if (child != null && child.getType() == TYPE_PARAMETERS && child.getNumberOfChildren() > 0) {
result.append("<");
GroovySourceAST typeParametersNext = (GroovySourceAST) child.getFirstChild();
List<String> typeParameterParts = new ArrayList<String>();
while (typeParametersNext != null) {
if (typeParametersNext.getType() == TYPE_PARAMETER && typeParametersNext.getNumberOfChildren() > 0) {
typeParameterParts.add(getTypeNodeAsText((GroovySourceAST) typeParametersNext.getFirstChild(), defaultText));
}
typeParametersNext = (GroovySourceAST) typeParametersNext.getNextSibling();
}
result.append(DefaultGroovyMethods.join(typeParameterParts, ", "));
result.append(">");
}
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method addParametersTo.
private void addParametersTo(GroovySourceAST t, SimpleGroovyExecutableMemberDoc executableMemberDoc) {
// parameters
GroovySourceAST parametersNode = t.childOfType(PARAMETERS);
if (parametersNode != null && parametersNode.getNumberOfChildren() > 0) {
GroovySourceAST currentNode = (GroovySourceAST) parametersNode.getFirstChild();
while (currentNode != null) {
String parameterTypeName = getTypeOrDefault(currentNode);
String parameterName = getText(currentNode.childOfType(IDENT));
SimpleGroovyParameter parameter = new SimpleGroovyParameter(parameterName);
parameter.setVararg(currentNode.getType() == VARIABLE_PARAMETER_DEF);
parameter.setTypeName(parameterTypeName);
GroovySourceAST modifiers = currentNode.childOfType(MODIFIERS);
if (modifiers != null) {
List<GroovySourceAST> annotations = modifiers.childrenOfType(ANNOTATION);
for (GroovySourceAST a : annotations) {
addAnnotationRef(parameter, a);
}
}
executableMemberDoc.add(parameter);
if (currentNode.getNumberOfChildren() == 4) {
handleDefaultValue(currentNode, parameter);
}
currentNode = (GroovySourceAST) currentNode.getNextSibling();
}
}
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method getParentNode.
private GroovySourceAST getParentNode() {
GroovySourceAST parentNode = null;
GroovySourceAST currentNode = stack.pop();
if (!stack.empty()) {
parentNode = stack.peek();
}
stack.push(currentNode);
return parentNode;
}
use of org.codehaus.groovy.antlr.GroovySourceAST in project groovy by apache.
the class SimpleGroovyClassDocAssembler method getCurrentClassDoc.
private SimpleGroovyClassDoc getCurrentClassDoc() {
if (stack.isEmpty())
return null;
GroovySourceAST node = getParentNode();
if (isTopLevelConstruct(node) && foundClasses != null) {
return foundClasses.get(getIdentFor(node));
}
GroovySourceAST saved = stack.pop();
SimpleGroovyClassDoc result = getCurrentClassDoc();
stack.push(saved);
return result;
}
Aggregations