Search in sources :

Example 1 with PolymorphicQualifier

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

the class DefaultQualifierKindHierarchy method initializePolymorphicQualifiers.

/**
 * Iterates over all the qualifier kinds and adds all polymorphic qualifier kinds to
 * polymorphicQualifiers. Also sets {@link DefaultQualifierKind#poly} and {@link
 * DefaultQualifierKind#top} for the polymorphic qualifiers, and sets {@link
 * DefaultQualifierKind#poly} for the top qualifiers.
 *
 * <p>Requires that tops has been initialized.
 */
@RequiresNonNull({ "this.nameToQualifierKind", "this.qualifierKinds", "this.tops" })
protected void initializePolymorphicQualifiers(@UnderInitialization DefaultQualifierKindHierarchy this, ) {
    for (DefaultQualifierKind qualifierKind : qualifierKinds) {
        Class<? extends Annotation> clazz = qualifierKind.getAnnotationClass();
        PolymorphicQualifier polyMetaAnno = clazz.getAnnotation(PolymorphicQualifier.class);
        if (polyMetaAnno == null) {
            continue;
        }
        qualifierKind.poly = qualifierKind;
        String topName = QualifierKindHierarchy.annotationClassName(polyMetaAnno.value());
        if (nameToQualifierKind.containsKey(topName)) {
            qualifierKind.top = nameToQualifierKind.get(topName);
        } else if (topName.equals(Annotation.class.getCanonicalName())) {
            // then there must be exactly one top.
            if (tops.size() == 1) {
                qualifierKind.top = tops.iterator().next();
            } else {
                throw new TypeSystemError("Polymorphic qualifier %s did not specify a top annotation class. Tops: [%s]", qualifierKind, StringsPlume.join(", ", tops));
            }
        } else {
            throw new TypeSystemError("Polymorphic qualifier %s's top, %s, is not a qualifier.", qualifierKind, topName);
        }
        qualifierKind.strictSuperTypes = Collections.singleton(qualifierKind.top);
        qualifierKind.top.poly = qualifierKind;
    }
}
Also used : PolymorphicQualifier(org.checkerframework.framework.qual.PolymorphicQualifier) TypeSystemError(org.checkerframework.javacutil.TypeSystemError) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1 PolymorphicQualifier (org.checkerframework.framework.qual.PolymorphicQualifier)1 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)1