Search in sources :

Example 1 with SubtypeOf

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

the class DefaultQualifierKindHierarchy method createDirectSuperMap.

/**
 * Creates a mapping from a {@link QualifierKind} to a set of its direct super qualifier kinds.
 * The direct super qualifier kinds do not contain the qualifier itself. This mapping is used to
 * create the bottom set, to create the top set, and by {@link
 * #initializeQualifierKindFields(Map)}.
 *
 * <p>This implementation uses the {@link SubtypeOf} meta-annotation. Subclasses may override this
 * method to create the direct super map some other way.
 *
 * <p>Note that this method is called from the constructor when {@link #nameToQualifierKind} and
 * {@link #qualifierKinds} are the only fields that have nonnull values. This method is not
 * static, so it can be overridden by subclasses.
 *
 * @return a mapping from each {@link QualifierKind} to a set of its direct super qualifiers
 */
@RequiresNonNull({ "this.nameToQualifierKind", "this.qualifierKinds" })
protected Map<DefaultQualifierKind, Set<DefaultQualifierKind>> createDirectSuperMap(@UnderInitialization DefaultQualifierKindHierarchy this, ) {
    Map<DefaultQualifierKind, Set<DefaultQualifierKind>> directSuperMap = new TreeMap<>();
    for (DefaultQualifierKind qualifierKind : qualifierKinds) {
        SubtypeOf subtypeOfMetaAnno = qualifierKind.getAnnotationClass().getAnnotation(SubtypeOf.class);
        if (subtypeOfMetaAnno == null) {
            // qualifierKind has no @SubtypeOf: it must be top or polymorphic
            continue;
        }
        Set<DefaultQualifierKind> directSupers = new TreeSet<>();
        for (Class<? extends Annotation> superClazz : subtypeOfMetaAnno.value()) {
            String superName = QualifierKindHierarchy.annotationClassName(superClazz);
            DefaultQualifierKind superQualifier = nameToQualifierKind.get(superName);
            if (superQualifier == null) {
                throw new TypeSystemError("%s @Subtype argument %s isn't in the hierarchy. Qualifiers: [%s]", qualifierKind, superName, StringsPlume.join(", ", qualifierKinds));
            }
            directSupers.add(superQualifier);
        }
        directSuperMap.put(qualifierKind, directSupers);
    }
    return directSuperMap;
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) TypeSystemError(org.checkerframework.javacutil.TypeSystemError) SubtypeOf(org.checkerframework.framework.qual.SubtypeOf) TreeMap(java.util.TreeMap) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1 SubtypeOf (org.checkerframework.framework.qual.SubtypeOf)1 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)1