Class BinaryStubReader
BinaryStubData.ClassRecord to a checker's AnnotationFileParser.AnnotationFileAnnotations. This translates the compact structural binary representation back
into AnnotationMirror and AnnotatedTypeMirror objects that the framework uses
during type-checking, matching the semantics of the text-based AnnotationFileParser. It
serves both the annotated JDK (annotated-jdk.bin.gz, applied lazily per requested class)
and the built-in checker stub files (*.astub.bin.gz, applied eagerly at checker
initialization with @FromStubFile marking).
Annotations that cannot be resolved (e.g. JDK-internal annotations like @DefinedBy
that are absent from the annotation-processor classpath) are silently skipped, matching the
behavior of the text-based AnnotationFileParser. Annotations that are not supported
qualifiers of the current checker are filtered out by AnnotatedTypeMirror.addAnnotation(AnnotationMirror) when they are applied to a type.
User-supplied stub files take precedence: if an entry already exists in AnnotationFileParser.AnnotationFileAnnotations.atypes it is not overwritten, and declaration annotations are merged
by annotation name rather than replaced.
A stub method that the enclosing class only inherits is applied as a fake override (see applyFakeOverride(org.checkerframework.framework.stub.BinaryStubData.TypeAnno[], java.lang.String, javax.lang.model.element.TypeElement, java.lang.String, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.stub.AnnotationFileParser.AnnotationFileAnnotations)). Classes that are not present in the binary stub -- e.g. a file the writer
failed to serialize, or a user-supplied -Astubs file, which is always text-parsed -- fall
through to the text-based AnnotationFileParser path.
Semantic equivalence of this class and the text parser is enforced by
BinaryStubDiffChecker (option -AbinaryStubDiffCheck); run
NullnessBinaryStubDiffTest after changing either side.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyClassRecord(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target) Applies the annotations from aBinaryStubData.ClassRecordto the given class and its members.static voidapplyClassRecord(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target, @Nullable AnnotationMirror fromStubFileAnno) LikeapplyClassRecord(BinaryStubData.ClassRecord, String, AnnotatedTypeFactory, AnnotationFileElementTypes, BinaryStubData, AnnotationFileAnnotations), but additionally marks every matched method and field element with the given@FromStubFilemirror.static voidapplyClassTypeParamRecords(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target, @Nullable AnnotationMirror fromStubFileAnno) Stores the class's type parameter declarations fromcrintarget, unlesstargetalready has them, asapplyClassRecord(org.checkerframework.framework.stub.BinaryStubData.ClassRecord, java.lang.String, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileParser.AnnotationFileAnnotations)would.static voidapplyPackageAndModuleRecords(BinaryStubData data, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, AnnotationFileParser.AnnotationFileAnnotations target, boolean fromLazyJdk) Applies the package and module annotations from the binary stub data.
-
Method Details
-
applyPackageAndModuleRecords
public static void applyPackageAndModuleRecords(BinaryStubData data, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, AnnotationFileParser.AnnotationFileAnnotations target, boolean fromLazyJdk) Applies the package and module annotations from the binary stub data. Called eagerly when the binary stub file is loaded, because package and module annotations are global rather than per-class.Declaration annotations are merged into
target.declAnnosby annotation name; seemergeDeclAnnos(org.checkerframework.framework.stub.AnnotationFileParser.AnnotationFileAnnotations, java.lang.String, org.checkerframework.javacutil.AnnotationMirrorSet, boolean)for howfromLazyJdkcontrols which source wins a conflict.- Parameters:
data- the complete binary stub data, providing the string pool and annotation poolatypeFactory- the factory used to create types and parse annotationselementTypes- per-factory state, including the annotation-mirror cachetarget- the annotation container to store the results infromLazyJdk- true ifdatais the lazily-loaded annotated JDK (called fromprepJdkStubs); false if it is an eagerly-applied built-in stub file (called fromapplyBinaryStubData)
-
applyClassTypeParamRecords
public static void applyClassTypeParamRecords(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target, @Nullable AnnotationMirror fromStubFileAnno) Stores the class's type parameter declarations fromcrintarget, unlesstargetalready has them, asapplyClassRecord(org.checkerframework.framework.stub.BinaryStubData.ClassRecord, java.lang.String, org.checkerframework.framework.type.AnnotatedTypeFactory, org.checkerframework.framework.stub.AnnotationFileElementTypes, org.checkerframework.framework.stub.BinaryStubData, org.checkerframework.framework.stub.AnnotationFileParser.AnnotationFileAnnotations)would. Callers apply this to every class record of a stub file, or of an annotated JDK source file, before applying any record in full, because a plain?takes the bounds of its type variable's declaration (AnnotationFileParser.annotateUnannotatedUnboundedWildcard(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType, org.checkerframework.framework.type.AnnotatedTypeFactory)), which can be in a class whose record comes later, such as a nested class. The text parser processes a file in order, so it gets the stub's bounds only for a declaration that precedes the?.- Parameters:
cr- the class record from the binary stub dataclassName- the fully-qualified name of the classatypeFactory- the factory used to create types and parse annotationselementTypes- per-factory state, including the annotation-mirror cachedata- the complete binary stub datatarget- the annotation container to store the results infromStubFileAnno- the@FromStubFilemirror for a stub file, ornullfor the annotated JDK
-
applyClassRecord
public static void applyClassRecord(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target) Applies the annotations from aBinaryStubData.ClassRecordto the given class and its members. The annotations are converted toAnnotationMirrors and stored intarget, which is usuallyelementTypes.annotationFileAnnosbut may be a scratch container (seeBinaryStubDiffChecker).- Parameters:
cr- the class record from the binary stub dataclassName- the fully-qualified name of the classatypeFactory- the factory used to create types and parse annotationselementTypes- per-factory state, including the annotation-mirror cachedata- the complete binary stub data, providing the string pool and annotation pooltarget- the annotation container to store the results in
-
applyClassRecord
public static void applyClassRecord(BinaryStubData.ClassRecord cr, String className, AnnotatedTypeFactory atypeFactory, AnnotationFileElementTypes elementTypes, BinaryStubData data, AnnotationFileParser.AnnotationFileAnnotations target, @Nullable AnnotationMirror fromStubFileAnno) LikeapplyClassRecord(BinaryStubData.ClassRecord, String, AnnotatedTypeFactory, AnnotationFileElementTypes, BinaryStubData, AnnotationFileAnnotations), but additionally marks every matched method and field element with the given@FromStubFilemirror. Used for built-in checker stub files, whose elements the text parser marks (seeAnnotationFileParser.markAsFromStubFile); the annotated JDK is never marked.- Parameters:
cr- the class record from the binary stub dataclassName- the fully-qualified name of the classatypeFactory- the factory used to create types and parse annotationselementTypes- per-factory state, including the annotation-mirror cachedata- the complete binary stub data, providing the string pool and annotation pooltarget- the annotation container to store the results infromStubFileAnno- the@FromStubFilemirror to mark matched members with, ornullto not mark (the annotated-JDK case)
-