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;
}
Aggregations