use of com.github.javaparser.ast.body.BodyDeclaration in project libgdx by libgdx.
the class RobustJavaMethodParser method getJavaMethods.
private void getJavaMethods(ArrayList<JavaMethod> methods, TypeDeclaration type) {
classStack.push(type);
if (type.getMembers() != null) {
for (BodyDeclaration member : type.getMembers()) {
if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) {
getJavaMethods(methods, (TypeDeclaration) member);
} else {
if (member instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) member;
if (!ModifierSet.hasModifier(((MethodDeclaration) member).getModifiers(), ModifierSet.NATIVE))
continue;
methods.add(createMethod(method));
}
}
}
}
classStack.pop();
}
use of com.github.javaparser.ast.body.BodyDeclaration in project butterknife by JakeWharton.
the class FinalRClassBuilder method addResourceType.
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result, TypeDeclaration node) {
if (!supportedTypes.contains(node.getName())) {
return;
}
String type = node.getName();
TypeSpec.Builder resourceType = TypeSpec.classBuilder(type).addModifiers(PUBLIC, STATIC, FINAL);
for (BodyDeclaration field : node.getMembers()) {
if (field instanceof FieldDeclaration) {
addResourceField(resourceType, ((FieldDeclaration) field).getVariables().get(0), getSupportAnnotationClass(type));
}
}
result.addType(resourceType.build());
}
use of com.github.javaparser.ast.body.BodyDeclaration in project checker-framework by typetools.
the class StubParser method processTypeDecl.
/**
* @param outertypeName the name of the containing class, when processing a nested class
*/
private void processTypeDecl(TypeDeclaration<?> typeDecl, String outertypeName, List<AnnotationExpr> packageAnnos) {
assert parseState != null;
String innerName = (outertypeName == null ? "" : outertypeName + ".") + typeDecl.getNameAsString();
parseState = new FqName(parseState.packageName, innerName);
String fqTypeName = parseState.toString();
TypeElement typeElt = elements.getTypeElement(fqTypeName);
if (typeElt == null) {
if (debugStubParser || (!hasNoStubParserWarning(typeDecl.getAnnotations()) && !hasNoStubParserWarning(packageAnnos))) {
stubWarnNotFound("Type not found: " + fqTypeName);
}
return;
}
if (typeElt.getKind() == ElementKind.ENUM) {
typeParameters.addAll(processEnum((EnumDeclaration) typeDecl, typeElt));
} else if (typeElt.getKind() == ElementKind.ANNOTATION_TYPE) {
stubWarnNotFound("Skipping annotation type: " + fqTypeName);
} else if (typeDecl instanceof ClassOrInterfaceDeclaration) {
typeParameters.addAll(processType((ClassOrInterfaceDeclaration) typeDecl, typeElt));
}
// else it's an EmptyTypeDeclaration. TODO: An EmptyTypeDeclaration can have
// annotations, right?
Map<Element, BodyDeclaration<?>> elementsToDecl = getMembers(typeElt, typeDecl);
for (Map.Entry<Element, BodyDeclaration<?>> entry : elementsToDecl.entrySet()) {
final Element elt = entry.getKey();
final BodyDeclaration<?> decl = entry.getValue();
switch(elt.getKind()) {
case FIELD:
case ENUM_CONSTANT:
processField((FieldDeclaration) decl, (VariableElement) elt);
break;
case CONSTRUCTOR:
case METHOD:
processCallableDeclaration((CallableDeclaration<?>) decl, (ExecutableElement) elt);
break;
case CLASS:
case INTERFACE:
processTypeDecl((ClassOrInterfaceDeclaration) decl, innerName, packageAnnos);
break;
case ENUM:
processTypeDecl((EnumDeclaration) decl, innerName, packageAnnos);
break;
default:
/* do nothing */
stubWarnNotFound("StubParser ignoring: " + elt);
break;
}
}
typeParameters.clear();
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class VoidVisitorAdapter method visit.
@Override
public void visit(final ObjectCreationExpr n, final A arg) {
visitComment(n.getComment(), arg);
if (n.getScope() != null) {
n.getScope().accept(this, arg);
}
if (n.getTypeArgs() != null) {
for (final Type t : n.getTypeArgs()) {
t.accept(this, arg);
}
}
n.getType().accept(this, arg);
if (n.getArgs() != null) {
for (final Expression e : n.getArgs()) {
e.accept(this, arg);
}
}
if (n.getAnonymousClassBody() != null) {
for (final BodyDeclaration member : n.getAnonymousClassBody()) {
member.accept(this, arg);
}
}
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(ObjectCreationExpr _n, Object _arg) {
Expression scope = cloneNodes(_n.getScope(), _arg);
ClassOrInterfaceType type_ = cloneNodes(_n.getType(), _arg);
List<Type> typeArgs = visit(_n.getTypeArgs(), _arg);
List<Expression> args = visit(_n.getArgs(), _arg);
List<BodyDeclaration> anonymousBody = visit(_n.getAnonymousClassBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ObjectCreationExpr r = new ObjectCreationExpr(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), scope, type_, typeArgs, args, anonymousBody);
r.setComment(comment);
return r;
}
Aggregations