Search in sources :

Example 21 with RequiresNonNull

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;
}
Also used : Format(com.google.android.exoplayer2.Format) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 22 with RequiresNonNull

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

Example 23 with RequiresNonNull

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);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) NonNull(org.checkerframework.checker.nullness.qual.NonNull) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull) QualifierKind(org.checkerframework.framework.util.QualifierKind) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 24 with RequiresNonNull

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));
    }
}
Also used : TypeSystemError(org.checkerframework.javacutil.TypeSystemError) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 25 with RequiresNonNull

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;
    }
}
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)43 Nullable (androidx.annotation.Nullable)12 Format (com.google.android.exoplayer2.Format)10 SuppressLint (android.annotation.SuppressLint)4 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)3 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 TextPaint (android.text.TextPaint)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 Transformer (com.google.android.exoplayer2.transformer.Transformer)2 EnsuresNonNull (org.checkerframework.checker.nullness.qual.EnsuresNonNull)2 UnderlyingAST (org.checkerframework.dataflow.cfg.UnderlyingAST)2 SpecialBlock (org.checkerframework.dataflow.cfg.block.SpecialBlock)2 TypeSystemError (org.checkerframework.javacutil.TypeSystemError)2