Search in sources :

Example 1 with MemberValuePair

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

the class StubParser method getAnnotation.

/**
 * Convert {@code annotation} into an AnnotationMirror. Returns null if the annotation isn't
 * supported by the checker or if some error occurred while converting it.
 */
private AnnotationMirror getAnnotation(AnnotationExpr annotation, Map<String, AnnotationMirror> allStubAnnotations) {
    AnnotationMirror annoMirror;
    if (annotation instanceof MarkerAnnotationExpr) {
        String annoName = ((MarkerAnnotationExpr) annotation).getNameAsString();
        annoMirror = allStubAnnotations.get(annoName);
    } else if (annotation instanceof NormalAnnotationExpr) {
        NormalAnnotationExpr nrmanno = (NormalAnnotationExpr) annotation;
        String annoName = nrmanno.getNameAsString();
        annoMirror = allStubAnnotations.get(annoName);
        if (annoMirror == null) {
            // Not a supported qualifier -> ignore
            return null;
        }
        AnnotationBuilder builder = new AnnotationBuilder(processingEnv, annoMirror);
        List<MemberValuePair> pairs = nrmanno.getPairs();
        if (pairs != null) {
            for (MemberValuePair mvp : pairs) {
                String member = mvp.getNameAsString();
                Expression exp = mvp.getValue();
                boolean success = handleExpr(builder, member, exp);
                if (!success) {
                    stubWarn("Annotation expression, %s, could not be processed for annotation: %s. ", exp, annotation);
                    return null;
                }
            }
        }
        return builder.build();
    } else if (annotation instanceof SingleMemberAnnotationExpr) {
        SingleMemberAnnotationExpr sglanno = (SingleMemberAnnotationExpr) annotation;
        String annoName = sglanno.getNameAsString();
        annoMirror = allStubAnnotations.get(annoName);
        if (annoMirror == null) {
            // Not a supported qualifier -> ignore
            return null;
        }
        AnnotationBuilder builder = new AnnotationBuilder(processingEnv, annoMirror);
        Expression valexpr = sglanno.getMemberValue();
        boolean success = handleExpr(builder, "value", valexpr);
        if (!success) {
            stubWarn("Annotation expression, %s, could not be processed for annotation: %s. ", valexpr, annotation);
            return null;
        }
        return builder.build();
    } else {
        ErrorReporter.errorAbort("StubParser: unknown annotation type: " + annotation);
        // dead code
        annoMirror = null;
    }
    return annoMirror;
}
Also used : SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) AnnotationMirror(javax.lang.model.element.AnnotationMirror) MemberValuePair(com.github.javaparser.ast.expr.MemberValuePair) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) List(java.util.List) ArrayList(java.util.ArrayList) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) NormalAnnotationExpr(com.github.javaparser.ast.expr.NormalAnnotationExpr)

Example 2 with MemberValuePair

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

the class VoidVisitorAdapter method visit.

@Override
public void visit(final NormalAnnotationExpr n, final A arg) {
    visitComment(n.getComment(), arg);
    n.getName().accept(this, arg);
    if (n.getPairs() != null) {
        for (final MemberValuePair m : n.getPairs()) {
            m.accept(this, arg);
        }
    }
}
Also used : MemberValuePair(com.github.javaparser.ast.expr.MemberValuePair)

Aggregations

MemberValuePair (com.github.javaparser.ast.expr.MemberValuePair)2 NodeList (com.github.javaparser.ast.NodeList)1 Expression (com.github.javaparser.ast.expr.Expression)1 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)1 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)1 SingleMemberAnnotationExpr (com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)1