use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project ExoPlayer by google.
the class WebvttExtractor method buildTrackOutput.
@RequiresNonNull("output")
private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
trackOutput.format(new Format.Builder().setSampleMimeType(MimeTypes.TEXT_VTT).setLanguage(language).setSubsampleOffsetUs(subsampleOffsetUs).build());
output.endTracks();
return trackOutput;
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull 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;
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project checker-framework by typetools.
the class NoElementQualifierHierarchy method createTops.
/**
* Creates and returns the unmodifiable set of top {@link AnnotationMirror}s.
*
* @return the unmodifiable set of top {@link AnnotationMirror}s
*/
@RequiresNonNull({ "this.kindToAnnotationMirror", "this.qualifierKindHierarchy" })
protected Set<AnnotationMirror> createTops(@UnderInitialization NoElementQualifierHierarchy this, ) {
Set<AnnotationMirror> tops = AnnotationUtils.createAnnotationSet();
for (QualifierKind top : qualifierKindHierarchy.getTops()) {
@SuppressWarnings(// All QualifierKinds are keys in kindToAnnotationMirror
"nullness:assignment") @NonNull AnnotationMirror topAnno = kindToAnnotationMirror.get(top);
tops.add(topAnno);
}
return Collections.unmodifiableSet(tops);
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull in project checker-framework by typetools.
the class DefaultQualifierKindHierarchy method verifyHierarchy.
/**
* Verifies that the {@link DefaultQualifierKindHierarchy} is a valid hierarchy.
*
* @param directSuperMap mapping from qualifier to its direct supertypes; used to verify that a
* polymorphic annotation does not have a {@link SubtypeOf} meta-annotation
* @throws TypeSystemError if the hierarchy isn't valid
*/
@RequiresNonNull({ "this.qualifierKinds", "this.tops", "this.bottoms" })
protected void verifyHierarchy(@UnderInitialization DefaultQualifierKindHierarchy this, Map<DefaultQualifierKind, Set<DefaultQualifierKind>> directSuperMap) {
for (DefaultQualifierKind qualifierKind : qualifierKinds) {
boolean isPoly = qualifierKind.isPoly();
boolean hasSubtypeOfAnno = directSuperMap.containsKey(qualifierKind);
if (isPoly && hasSubtypeOfAnno) {
// Polymorphic qualifiers with upper and lower bounds are currently not supported.
throw new TypeSystemError("AnnotatedTypeFactory: " + qualifierKind + " is polymorphic and specifies super qualifiers.%n" + "Remove the @PolymorphicQualifier or @SubtypeOf annotation from it.");
} else if (!isPoly && !hasSubtypeOfAnno) {
throw new TypeSystemError("AnnotatedTypeFactory: %s does not specify its super qualifiers.%n" + "Add an @SubtypeOf or @PolymorphicQualifier annotation to it,%n" + "or if it is an alias, exclude it from `createSupportedTypeQualifiers()`.", qualifierKind);
} else if (isPoly) {
if (qualifierKind.top == null) {
throw new TypeSystemError("PolymorphicQualifier, %s, has to specify a type hierarchy in its" + " @PolymorphicQualifier meta-annotation, if more than one exists; top types:" + " [%s].", qualifierKind, StringsPlume.join(", ", tops));
} else if (!tops.contains(qualifierKind.top)) {
throw new TypeSystemError("Polymorphic qualifier %s has invalid top %s. Top qualifiers: %s", qualifierKind, qualifierKind.top, StringsPlume.join(", ", tops));
}
}
}
if (bottoms.size() != tops.size()) {
throw new TypeSystemError("Number of tops not equal to number of bottoms: Tops: [%s] Bottoms: [%s]", StringsPlume.join(", ", tops), StringsPlume.join(", ", bottoms));
}
}
use of org.checkerframework.checker.nullness.qual.RequiresNonNull 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;
}
}
Aggregations