use of org.checkerframework.framework.qual.PreconditionAnnotation in project checker-framework by typetools.
the class ContractsUtils method getPreconditions.
/**
* Returns the set of preconditions on the element {@code element}.
*/
public Set<Precondition> getPreconditions(Element element) {
Set<Precondition> result = new LinkedHashSet<>();
// Check for a single contract.
AnnotationMirror requiresAnnotation = factory.getDeclAnnotation(element, RequiresQualifier.class);
result.addAll(getPrecondition(requiresAnnotation));
// Check for multiple contracts.
AnnotationMirror requiresAnnotations = factory.getDeclAnnotation(element, RequiresQualifiers.class);
if (requiresAnnotations != null) {
List<AnnotationMirror> annotations = AnnotationUtils.getElementValueArray(requiresAnnotations, "value", AnnotationMirror.class, false);
for (AnnotationMirror a : annotations) {
result.addAll(getPrecondition(a));
}
}
// Check type-system specific annotations.
Class<PreconditionAnnotation> metaAnnotation = PreconditionAnnotation.class;
List<Pair<AnnotationMirror, AnnotationMirror>> declAnnotations = factory.getDeclAnnotationWithMetaAnnotation(element, 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 precondtionAnno = getAnnotationMirrorOfMetaAnnotation(metaAnno, anno);
if (precondtionAnno == null) {
continue;
}
for (String expr : expressions) {
result.add(new Precondition(expr, precondtionAnno));
}
}
return result;
}
Aggregations