Class JavaStubifier
BinaryStubWriter.OUTPUT_FILENAME) for the same directory from the same
parsed compilation units.
To convert a file into a stub file means to remove:
- everything that is private or package-private,
- all comments, except for an initial copyright header,
- all method bodies,
- all field initializers,
- all initializer blocks,
- attributes to the
Deprecatedannotation (to be Java 8 compatible).
Usage: JavaStubifier [--skipUnloadableAnnotations] <directory> [<directory> ...]. By
default, an annotation whose @Target cannot be read (because its class is missing from
the stubifier's own build classpath) aborts the run with a message naming the annotation and the
source file being processed; see SKIP_UNLOADABLE_ANNOTATIONS_FLAG for the opt-in flag
that trades that safety for being able to finish the run anyway.
Each directory is processed by its own BinaryStubWriter into its own output file (see
process(java.lang.String, boolean)). An interface and its implementer being in different directories does not
weaken fake-override handling: a writer records every unannotated method it sees as a
presence-only signature unconditionally (BinaryStubWriter.addMethodRecord), with no
dependence on the interfaces that writer happened to see, and the fake-override match runs at
read time over the real class hierarchy (BinaryStubReader.applyFakeOverride,
FakeOverrideResolver).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.github.javaparser.ParserConfiguration.LanguageLevelThe language level used to parse the annotated JDK sources (by this class), the built-in.astubfiles (byBinaryStubFileGenerator), and stub and Java files at checker runtime (JavaParserUtil.DEFAULT_LANGUAGE_LEVELis this constant).static final StringCommand-line flag that makes an unloadable annotation a dropped-and-warned event rather than a fatal error. -
Method Summary
Modifier and TypeMethodDescriptionstatic PathdirnameToPath(String dir) Converts a directory name to a path.static voidProcesses each provided command-line argument; see class documentation for details.static com.github.javaparser.ParserConfigurationnewStubParserConfiguration(boolean storeTokens) Returns a new configuration for parsing a stub file.
-
Field Details
-
DEFAULT_LANGUAGE_LEVEL
public static final com.github.javaparser.ParserConfiguration.LanguageLevel DEFAULT_LANGUAGE_LEVELThe language level used to parse the annotated JDK sources (by this class), the built-in.astubfiles (byBinaryStubFileGenerator), and stub and Java files at checker runtime (JavaParserUtil.DEFAULT_LANGUAGE_LEVELis this constant). This should be the highest version of Java that the Checker Framework can process. -
SKIP_UNLOADABLE_ANNOTATIONS_FLAG
Command-line flag that makes an unloadable annotation a dropped-and-warned event rather than a fatal error. When passed,BinaryStubWriteromits, from the binary stub output, any annotation whose@Targetit cannot read -- printing one warning line to stderr naming the annotation and its source file -- and processing continues with the rest of the directory. Without the flag (the default), the same condition aborts the whole run; seeBinaryStubWriter.annotationTargets(com.github.javaparser.ast.expr.AnnotationExpr).Trade-off: dropping such an annotation is not always safe. It could be a real type qualifier that a checker's own (wider) classpath would have resolved, in which case dropping it here silently removes it from the annotated JDK with no way for a later checker run to detect the omission. Pass this flag only when the unloadable annotation is known to be irrelevant to type-checking (e.g. a JUnit annotation on a stray test source file that ended up in the JDK source tree being stubified), not as a default way to push through classpath problems.
- See Also:
-
-
Method Details
-
newStubParserConfiguration
public static com.github.javaparser.ParserConfiguration newStubParserConfiguration(boolean storeTokens) Returns a new configuration for parsing a stub file. BothBinaryStubFileGeneratorand the text stub parser (JavaParserUtil.parseStubUnit) use it, so that a binary stub file is generated from the same parse that the text parser would produce.A
ParserConfigurationaccumulates data each time it is used to parse, so callers create a new one for each parse.- Parameters:
storeTokens- whether JavaParser should retainJavaTokenobjects on the parsed AST, which precise diagnostics for malformed stub files need- Returns:
- a new stub-file parser configuration
-
main
Processes each provided command-line argument; see class documentation for details.- Parameters:
args- command-line arguments: an optionalSKIP_UNLOADABLE_ANNOTATIONS_FLAG, followed by one or more directories to process
-
dirnameToPath
Converts a directory name to a path. It issues a warning and terminates the program if the argument does not exist or is not a directory.Unlike
Paths.get, it handles "." which means the current directory in Unix.- Parameters:
dir- a directory name- Returns:
- a path for the directory name
-