Search in sources :

Example 16 with BodyDeclaration

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();
}
Also used : ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration)

Example 17 with BodyDeclaration

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());
}
Also used : BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 18 with BodyDeclaration

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();
}
Also used : ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration)

Example 19 with BodyDeclaration

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);
        }
    }
}
Also used : BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Example 20 with BodyDeclaration

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;
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) Comment(com.github.javaparser.ast.comments.Comment) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Aggregations

BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)29 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)10 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)9 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)9 CompilationUnit (com.github.javaparser.ast.CompilationUnit)7 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)7 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)7 NodeList (com.github.javaparser.ast.NodeList)6 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)6 ArrayList (java.util.ArrayList)6 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)5 BlockComment (com.github.javaparser.ast.comments.BlockComment)5 Comment (com.github.javaparser.ast.comments.Comment)5 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)5 LineComment (com.github.javaparser.ast.comments.LineComment)5 List (java.util.List)5 Parameter (com.github.javaparser.ast.body.Parameter)4 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)3 Expression (com.github.javaparser.ast.expr.Expression)3 Type (com.github.javaparser.ast.type.Type)3