Search in sources :

Example 1 with AnnotationExpr

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

the class StubParser method annotateAsArray.

/**
 * Add the annotations from {@code type} to {@code atype}. Type annotations that parsed as
 * declaration annotations (ie those in {@code declAnnos} are applied to the innermost component
 * type.
 *
 * @param atype annotated type to which to add annotations
 * @param type parsed type
 * @param declAnnos annotations stored on the declaration of the variable with this type or null
 */
private void annotateAsArray(AnnotatedArrayType atype, ReferenceType type, NodeList<AnnotationExpr> declAnnos) {
    annotateInnermostComponentType(atype, declAnnos);
    Type typeDef = type;
    AnnotatedTypeMirror currentAtype = atype;
    while (typeDef.isArrayType() && currentAtype.getKind() == TypeKind.ARRAY) {
        // handle generic type
        clearAnnotations(currentAtype, typeDef);
        List<AnnotationExpr> annotations = typeDef.getAnnotations();
        if (annotations != null) {
            annotate(currentAtype, annotations);
        }
        typeDef = ((com.github.javaparser.ast.type.ArrayType) typeDef).getComponentType();
        currentAtype = ((AnnotatedArrayType) currentAtype).getComponentType();
        if (typeDef.isArrayType() ^ currentAtype.getKind() == TypeKind.ARRAY) {
            stubWarn("Mismatched array lengths; atype: " + atype + "%n  type: " + type);
        }
    }
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) Type(com.github.javaparser.ast.type.Type) ArrayType(javax.lang.model.type.ArrayType) AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) ReferenceType(com.github.javaparser.ast.type.ReferenceType) AnnotatedWildcardType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) WildcardType(com.github.javaparser.ast.type.WildcardType) 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) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 2 with AnnotationExpr

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

the class ToIndexFileConverter method visit.

@Override
public Void visit(VariableDeclarationExpr expr, AElement elem) {
    List<AnnotationExpr> annos = expr.getAnnotations();
    AMethod method = (AMethod) elem;
    List<VariableDeclarator> varDecls = expr.getVariables();
    for (int i = 0; i < varDecls.size(); i++) {
        VariableDeclarator decl = varDecls.get(i);
        LocalLocation loc = new LocalLocation(decl.getNameAsString(), i);
        AField field = method.body.locals.vivify(loc);
        visitType(expr.getCommonType(), field.type);
        if (annos != null) {
            for (AnnotationExpr annoExpr : annos) {
                Annotation anno = extractAnnotation(annoExpr);
                field.tlAnnotationsHere.add(anno);
            }
        }
    }
    return null;
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) LocalLocation(scenelib.annotations.el.LocalLocation) AMethod(scenelib.annotations.el.AMethod) Annotation(scenelib.annotations.Annotation) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) AField(scenelib.annotations.el.AField)

Example 3 with AnnotationExpr

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

the class ToIndexFileConverter method visit.

@Override
public Void visit(MethodDeclaration decl, AElement elem) {
    Type type = decl.getType();
    List<Parameter> params = decl.getParameters();
    List<TypeParameter> typeParams = decl.getTypeParameters();
    Optional<ReceiverParameter> rcvrParam = decl.getReceiverParameter();
    BlockStmt body = decl.getBody().orElse(null);
    StringBuilder sb = new StringBuilder(decl.getNameAsString()).append('(');
    AClass clazz = (AClass) elem;
    AMethod method;
    if (params != null) {
        for (Parameter param : params) {
            Type ptype = param.getType();
            sb.append(getJVML(ptype));
        }
    }
    sb.append(')').append(getJVML(type));
    method = clazz.methods.vivify(sb.toString());
    visitDecl(decl, method);
    visitType(type, method.returnType);
    if (params != null) {
        for (int i = 0; i < params.size(); i++) {
            Parameter param = params.get(i);
            AField field = method.parameters.vivify(i);
            visitType(param.getType(), field.type);
        }
    }
    if (rcvrParam.isPresent()) {
        for (AnnotationExpr expr : rcvrParam.get().getAnnotations()) {
            Annotation anno = extractAnnotation(expr);
            method.receiver.type.tlAnnotationsHere.add(anno);
        }
    }
    if (typeParams != null) {
        for (int i = 0; i < typeParams.size(); i++) {
            TypeParameter typeParam = typeParams.get(i);
            List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
            if (bounds != null) {
                for (int j = 0; j < bounds.size(); j++) {
                    ClassOrInterfaceType bound = bounds.get(j);
                    BoundLocation loc = new BoundLocation(i, j);
                    bound.accept(this, method.bounds.vivify(loc));
                }
            }
        }
    }
    return body == null ? null : body.accept(this, method);
}
Also used : TypeParameter(com.github.javaparser.ast.type.TypeParameter) AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Annotation(scenelib.annotations.Annotation) AField(scenelib.annotations.el.AField) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) ReferenceType(com.github.javaparser.ast.type.ReferenceType) VoidType(com.github.javaparser.ast.type.VoidType) ArrayType(com.github.javaparser.ast.type.ArrayType) PrimitiveType(com.github.javaparser.ast.type.PrimitiveType) WildcardType(com.github.javaparser.ast.type.WildcardType) ReceiverParameter(com.github.javaparser.ast.body.ReceiverParameter) ReceiverParameter(com.github.javaparser.ast.body.ReceiverParameter) Parameter(com.github.javaparser.ast.body.Parameter) TypeParameter(com.github.javaparser.ast.type.TypeParameter) AClass(scenelib.annotations.el.AClass) BoundLocation(scenelib.annotations.el.BoundLocation) AMethod(scenelib.annotations.el.AMethod)

Example 4 with AnnotationExpr

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

the class DefaultUpdatingVisitor method removeUnnecessaryKeyAnnotations.

/**
 * Remove {@code Key} annotations with the same name as the method.
 */
private void removeUnnecessaryKeyAnnotations(MethodDeclaration decl) {
    ListIterator<AnnotationExpr> it = decl.getAnnotations().listIterator();
    while (it.hasNext()) {
        AnnotationExpr annotation = it.next();
        if (annotation.getName().getName().equals("Key")) {
            String keyName = tryGetAnnotationValue(annotation);
            if (Objects.equals(keyName, decl.getName())) {
                it.remove();
                dirty = true;
            }
        }
    }
}
Also used : AnnotationExpr(com.github.javaparser.ast.expr.AnnotationExpr) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr)

Example 5 with AnnotationExpr

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

the class CloneVisitor method visit.

@Override
public Node visit(ArrayType _n, Object _arg) {
    List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg);
    Type<?> type_ = cloneNodes(_n.getComponentType(), _arg);
    ArrayType r = new ArrayType(_n.getRange(), type_, 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)

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