Search in sources :

Example 1 with ConditionalPostconditionAnnotation

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

the class ContractsUtils method getConditionalPostconditions.

/**
 * Returns a set of triples {@code (expr, (result, annotation))} of conditional postconditions
 * on the method {@code methodElement}.
 */
public Set<ConditionalPostcondition> getConditionalPostconditions(ExecutableElement methodElement) {
    Set<ConditionalPostcondition> result = new LinkedHashSet<>();
    // Check for a single contract.
    AnnotationMirror ensuresQualifierIf = factory.getDeclAnnotation(methodElement, EnsuresQualifierIf.class);
    result.addAll(getConditionalPostcondition(ensuresQualifierIf));
    // Check for multiple contracts.
    AnnotationMirror ensuresAnnotationsIf = factory.getDeclAnnotation(methodElement, EnsuresQualifiersIf.class);
    if (ensuresAnnotationsIf != null) {
        List<AnnotationMirror> annotations = AnnotationUtils.getElementValueArray(ensuresAnnotationsIf, "value", AnnotationMirror.class, false);
        for (AnnotationMirror a : annotations) {
            result.addAll(getConditionalPostcondition(a));
        }
    }
    // Check type-system specific annotations.
    Class<ConditionalPostconditionAnnotation> metaAnnotation = ConditionalPostconditionAnnotation.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, "expression", String.class, false);
        AnnotationMirror postcondAnno = getAnnotationMirrorOfMetaAnnotation(metaAnno, anno);
        if (postcondAnno == null) {
            continue;
        }
        boolean annoResult = AnnotationUtils.getElementValue(anno, "result", Boolean.class, false);
        for (String expr : expressions) {
            result.add(new ConditionalPostcondition(expr, annoResult, postcondAnno));
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ConditionalPostconditionAnnotation(org.checkerframework.framework.qual.ConditionalPostconditionAnnotation) 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 Pair (org.checkerframework.javacutil.Pair)1