Class BinaryStubFileGenerator

java.lang.Object
org.checkerframework.framework.stubifier.BinaryStubFileGenerator

public class BinaryStubFileGenerator extends Object
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 .astub file, a directory searched recursively for .astub files, or a .jar file searched for .astub entries. For every one found, writes a sibling-named .astub.bin.gz file 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 .jar root (see generateForJar(java.nio.file.Path)). One .astub file 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 .astub file under it into one bundle file, written beside the root itself (not under any output directory) as org.checkerframework.framework.stub.BinaryStubBundle#SUFFIX names it. This is the mode a user runs by hand to pre-parse a whole -Astubs directory into a single file, which org.checkerframework.framework.stub.AnnotationFileElementTypes looks for before falling back to per-file siblings or text parsing.
At checker startup, 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 Details

    • main

      public static void main(String[] args) throws IOException
      The main entry point; see the class documentation for the two modes.
      Parameters:
      args - --bundle followed by one or more input root directories, or an output directory followed by one or more input roots (each a directory, a single .astub file, or a .jar file)
      Throws:
      IOException - if walking an input root, or reading or writing its output, fails
    • readAllBytes

      public static byte[] readAllBytes(InputStream in) throws IOException
      Reads all of in's remaining bytes. Equivalent to InputStream.readAllBytes() (Java 9+), avoided because this project is meant to run under a Java 8 runtime. Also used by org.checkerframework.framework.stub.AnnotationFileElementTypes.
      Parameters:
      in - the stream to read
      Returns:
      the bytes read
      Throws:
      IOException - if reading fails