Class BinaryStubFileGenerator
java.lang.Object
org.checkerframework.framework.stubifier.BinaryStubFileGenerator
Build-time generator that pre-parses
.astub files into the binary stub format read by
org.checkerframework.framework.stub.BinaryStubReader. Has two modes:
BinaryStubFileGenerator <outputDir> <inputRoot>...: each input root is a single.astubfile, a directory searched recursively for.astubfiles, or a.jarfile searched for.astubentries. For every one found, writes a sibling-named.astub.bin.gzfile or entry: under the output root for a file or directory root (preserving the relative path for a directory, so the binary is packaged as a sibling resource of the text stub), or -- ignoring the output root -- as a new entry inside the JAR itself for a.jarroot (seegenerateForJar(java.nio.file.Path)). One.astubfile or entry always maps to one such binary. This is the mode the build uses to pre-parse a checker's built-in stub files.BinaryStubFileGenerator --bundle <inputRoot>...: for each input root (a directory), combines the binary form of every.astubfile under it into one bundle file, written beside the root itself (not under any output directory) asorg.checkerframework.framework.stub.BinaryStubBundle#SUFFIXnames it. This is the mode a user runs by hand to pre-parse a whole-Astubsdirectory into a single file, whichorg.checkerframework.framework.stub.AnnotationFileElementTypeslooks for before falling back to per-file siblings or text parsing.
AnnotationFileElementTypes loads the binary form of a stub file if
present and falls back to text parsing otherwise.
A file is skipped -- no binary is emitted for it, so the checker text-parses it -- if it cannot be parsed, or fails to serialize. Skipping is always safe; it only forgoes the speedup for that file.
This tool reflectively loads every annotation type a stub file uses, so those classes must be
on its own classpath, not just on the classpath of the checker or project the stub file is
written for. That already holds for a checker's built-in stub files, whose qualifiers ship in
checker.jar alongside this tool, but commonly not for a -Astubs file using custom
qualifiers defined in the downstream project. A missing one fails with an error naming it.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidThe main entry point; see the class documentation for the two modes.static byte[]Reads all ofin's remaining bytes.
-
Method Details
-
main
The main entry point; see the class documentation for the two modes.- Parameters:
args---bundlefollowed by one or more input root directories, or an output directory followed by one or more input roots (each a directory, a single.astubfile, or a.jarfile)- Throws:
IOException- if walking an input root, or reading or writing its output, fails
-
readAllBytes
Reads all ofin's remaining bytes. Equivalent toInputStream.readAllBytes()(Java 9+), avoided because this project is meant to run under a Java 8 runtime. Also used byorg.checkerframework.framework.stub.AnnotationFileElementTypes.- Parameters:
in- the stream to read- Returns:
- the bytes read
- Throws:
IOException- if reading fails
-