Search in sources :

Example 1 with PostconditionAnnotation

use of org.checkerframework.framework.qual.PostconditionAnnotation in project checker-framework by typetools.

the class ContractsUtils method getPostconditions.

/**
 * Returns the set of postconditions on the method {@code methodElement}.
 */
public Set<Postcondition> getPostconditions(ExecutableElement methodElement) {
    Set<Postcondition> result = new LinkedHashSet<>();
    // Check for a single contract.
    AnnotationMirror ensuresAnnotation = factory.getDeclAnnotation(methodElement, EnsuresQualifier.class);
    result.addAll(getPostcondition(ensuresAnnotation));
    // Check for multiple contracts.
    AnnotationMirror ensuresAnnotations = factory.getDeclAnnotation(methodElement, EnsuresQualifiers.class);
    if (ensuresAnnotations != null) {
        List<AnnotationMirror> annotations = AnnotationUtils.getElementValueArray(ensuresAnnotations, "value", AnnotationMirror.class, false);
        for (AnnotationMirror a : annotations) {
            result.addAll(getPostcondition(a));
        }
    }
    // Check type-system specific annotations.
    Class<PostconditionAnnotation> metaAnnotation = PostconditionAnnotation.class;
    List<Pair<AnnotationMirror, AnnotationMirror>> declAnnotations = factory.getDeclAnnotationWithMetaAnnotation(methodElement, metaAnnotation);
    for (Pair<AnnotationMirror, AnnotationMirror> r : declAnnotations) {
        AnnotationMirror anno = r.first;
        AnnotationMirror metaAnno = r.second;
        List<String> expressions = AnnotationUtils.getElementValueArray(anno, "value", String.class, false);
        AnnotationMirror postcondAnno = getAnnotationMirrorOfMetaAnnotation(metaAnno, anno);
        if (postcondAnno == null) {
            continue;
        }
        for (String expr : expressions) {
            result.add(new Postcondition(expr, postcondAnno));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ConditionalPostconditionAnnotation(org.checkerframework.framework.qual.ConditionalPostconditionAnnotation) PostconditionAnnotation(org.checkerframework.framework.qual.PostconditionAnnotation) Pair(org.checkerframework.javacutil.Pair)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 ConditionalPostconditionAnnotation (org.checkerframework.framework.qual.ConditionalPostconditionAnnotation)1 PostconditionAnnotation (org.checkerframework.framework.qual.PostconditionAnnotation)1 Pair (org.checkerframework.javacutil.Pair)1