Search in sources :

Example 6 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.

the class CloneVisitor method visit.

@Override
public Node visit(ArrayCreationLevel _n, Object _arg) {
    List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg);
    Expression dimension_ = cloneNodes(_n.getDimension(), _arg);
    ArrayCreationLevel r = new ArrayCreationLevel(_n.getRange(), dimension_, ann);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    r.setComment(comment);
    return r;
}
Also used : Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr) Expression(com.github.javaparser.ast.expr.Expression)

Example 7 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.

the class CloneVisitor method visit.

@Override
public Node visit(IntersectionType _n, Object _arg) {
    List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
    List<ReferenceType> elements = visit(_n.getElements(), _arg);
    IntersectionType r = new IntersectionType(_n.getRange(), elements);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    r.setComment(comment);
    r.setAnnotations(annotations);
    return r;
}
Also used : Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr)

Example 8 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.

the class ModifierVisitorAdapter method visit.

@Override
public Node visit(final VariableDeclarationExpr n, final A arg) {
    visitComment(n, arg);
    final List<AnnotationExpr> annotations = n.getAnnotations();
    if (annotations != null) {
        for (int i = 0; i < annotations.size(); i++) {
            annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
        }
        removeNulls(annotations);
    }
    final Type type = (Type) n.getElementType().accept(this, arg);
    if (type == null) {
        return null;
    }
    n.setElementType(type);
    final List<VariableDeclarator> vars = n.getVariables();
    for (int i = 0; i < vars.size(); ) {
        final VariableDeclarator decl = (VariableDeclarator) vars.get(i).accept(this, arg);
        if (decl == null) {
            vars.remove(i);
        } else {
            vars.set(i++, decl);
        }
    }
    if (vars.isEmpty()) {
        return null;
    }
    return n;
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator)

Example 9 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project actframework by actframework.

the class ApiManager method exploreDeclaration.

private void exploreDeclaration(ClassOrInterfaceDeclaration classDeclaration, Map<String, Javadoc> methodJavaDocs, String prefix) {
    String className = classDeclaration.getName();
    String newPrefix = S.blank(prefix) ? className : S.concat(prefix, ".", className);
    for (Node node : classDeclaration.getChildrenNodes()) {
        if (node instanceof ClassOrInterfaceDeclaration) {
            exploreDeclaration((ClassOrInterfaceDeclaration) node, methodJavaDocs, newPrefix);
        } else if (node instanceof MethodDeclaration) {
            MethodDeclaration methodDeclaration = (MethodDeclaration) node;
            List<AnnotationExpr> annoList = methodDeclaration.getAnnotations();
            boolean needJavadoc = false;
            if (null != annoList && !annoList.isEmpty()) {
                for (AnnotationExpr anno : annoList) {
                    String annoName = anno.getName().getName();
                    if (actionAnnotations.contains(annoName)) {
                        needJavadoc = true;
                        break;
                    }
                }
            }
            if (!needJavadoc) {
                continue;
            }
            Comment comment = methodDeclaration.getComment();
            if (!(comment instanceof JavadocComment)) {
                continue;
            }
            JavadocComment javadocComment = (JavadocComment) comment;
            Javadoc javadoc = JavadocParser.parse(javadocComment);
            methodJavaDocs.put(S.concat(newPrefix, ".", methodDeclaration.getName()), javadoc);
        }
    }
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Node(com.github.javaparser.ast.Node) Javadoc(act.apidoc.javadoc.Javadoc)

Example 10 with AnnotationExpr

use of com.github.javaparser.ast.expr.AnnotationExpr in project checker-framework by typetools.

the class StubParser method annotateDecl.

private void annotateDecl(Map<String, Set<AnnotationMirror>> declAnnos, Element elt, List<AnnotationExpr> annotations) {
    if (annotations == null) {
        return;
    }
    Set<AnnotationMirror> annos = AnnotationUtils.createAnnotationSet();
    for (AnnotationExpr annotation : annotations) {
        AnnotationMirror annoMirror = getAnnotation(annotation, allStubAnnotations);
        if (annoMirror != null) {
            Target target = annoMirror.getAnnotationType().asElement().getAnnotation(Target.class);
            // Only add the declaration annotation if the annotation applies to the element.
            if (AnnotationUtils.getElementKindsForTarget(target).contains(elt.getKind())) {
                annos.add(annoMirror);
            }
        }
    }
    String key = ElementUtils.getVerboseName(elt);
    putOrAddToMap(declAnnos, key, annos);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) Target(java.lang.annotation.Target) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr)

Aggregations

AnnotationExpr (com.github.javaparser.ast.expr.AnnotationExpr)19 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)11 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)9 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)9 Comment (com.github.javaparser.ast.comments.Comment)5 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)5 Annotation (scenelib.annotations.Annotation)5 BlockComment (com.github.javaparser.ast.comments.BlockComment)4 LineComment (com.github.javaparser.ast.comments.LineComment)4 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)4 WildcardType (com.github.javaparser.ast.type.WildcardType)4 ReferenceType (com.github.javaparser.ast.type.ReferenceType)3 Type (com.github.javaparser.ast.type.Type)3 AField (scenelib.annotations.el.AField)3 AMethod (scenelib.annotations.el.AMethod)3 Parameter (com.github.javaparser.ast.body.Parameter)2 ReceiverParameter (com.github.javaparser.ast.body.ReceiverParameter)2 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)2 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 ArrayType (com.github.javaparser.ast.type.ArrayType)2