Class CheckerMain
java.lang.Object
org.checkerframework.framework.util.CheckerMain
This class behaves similarly to javac. CheckerMain does the following:
- parse and implement any special options used by the Checker Framework, e.g., using "shortnames" for annotation processors
- pass all remaining command-line arguments to the real javac
-AoutputArgsToFile=FILENAME command-line argument or
-AoutputArgsToFile=- to output to standard out.
Note for developers: Try to limit the work done (and options interpreted) by CheckerMain, because its functionality is not available to users who choose not to use the Checker Framework javac script.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringProcessor shorthand is enabled for processors in this directory in checker.jar.static final StringOption name for specifying an alternative checker-qual.jar location.static final StringOption name for specifying an alternative checker-util.jar location.protected final FileThe path to the jar containing CheckerMain.class (i.e.protected final FileThe path to checker-qual.jar.protected final FileThe path to checker-util.jar.protected static final StringProcessor shorthand is enabled for processors in this directory in checker.jar.protected static final PatternMatches all-Jarguments. -
Constructor Summary
ConstructorsConstructorDescriptionCheckerMain(File checkerJar, List<String> args) Construct all the relevant file locations and Java version given the path to this jar and a set of directories in which to search for jars. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAssert that required jars exist.collectArgFiles(List<String> args) Returns the arguments that start with @ and therefore are files that contain javac arguments.expandArgFiles(List<File> files) Returns all the lines in all the files.extractArg(String argumentName, List<String> args) Remove the argument given by argumentName and the subsequent value from the list args if present.extractCpOpts(List<String> args) Returns the last-cpor-classpathoption.protected static FileextractFileArg(String argumentName, File alternative, List<String> args) Remove the argument given by argumentName and the subsequent value from the list args if present.extractJvmOpts(List<String> args) Remove all-Jarguments fromargsand add them to the returned list (without the-Jprefix).extractPpOpts(List<String> args) Remove all-processorpathoptions and their arguments from args.static StringfindPathTo(@Nullable Class<?> cls, boolean errIfFromDirectory) Find the jar file or directory containing the .class file from which cls was loaded.Returns a list of arguments to pass to javac.intInvoke the compiler with all relevant jars on its classpath and/or bootclasspath.static voidAny exception thrown by the Checker Framework escapes to the command line.static booleanmatchesCheckerOrSubcheckerFromList(String processorString, List<@FullyQualifiedName String> fullyQualifiedCheckerNames) Returns true if processorString, once transformed into fully-qualified form, is present in fullyQualifiedCheckerNames.static booleanmatchesFullyQualifiedProcessor(String processorName, List<@FullyQualifiedName String> fullyQualifiedCheckerNames, boolean allowSubcheckers) Given a shorthand processor name, returns true if it can be expanded to a checker in the fullyQualifiedCheckerNames list.protected voidreplaceShorthandProcessor(List<String> args) For every "-processor" argument in args, replace its immediate successor argument using unabbreviateProcessorNames.protected static StringunshorthandProcessorNames(String processorsString, List<@FullyQualifiedName String> fullyQualifiedCheckerNames, boolean allowSubcheckers) Takes a string of comma-separated processor names, and expands any shorthands to fully-qualified names from the fullyQualifiedCheckerNames list.
-
Field Details
-
checkerJar
The path to the jar containing CheckerMain.class (i.e. checker.jar). -
checkerQualJar
The path to checker-qual.jar. -
checkerUtilJar
The path to checker-util.jar. -
CHECKER_QUAL_PATH_OPT
Option name for specifying an alternative checker-qual.jar location. The accompanying value MUST be the path to the jar file (NOT the path to its encompassing directory)- See Also:
-
CHECKER_UTIL_PATH_OPT
Option name for specifying an alternative checker-util.jar location. The accompanying value MUST be the path to the jar file (NOT the path to its encompassing directory)- See Also:
-
JVM_OPTS_REGEX
Matches all-Jarguments. -
CHECKER_BASE_DIR_NAME
Processor shorthand is enabled for processors in this directory in checker.jar.- See Also:
-
COMMON_BASE_DIR_NAME
Processor shorthand is enabled for processors in this directory in checker.jar.- See Also:
-
-
Constructor Details
-
CheckerMain
Construct all the relevant file locations and Java version given the path to this jar and a set of directories in which to search for jars.
-
-
Method Details
-
main
Any exception thrown by the Checker Framework escapes to the command line.- Parameters:
args- command-line arguments
-
assertValidState
protected void assertValidState()Assert that required jars exist. -
collectArgFiles
Returns the arguments that start with @ and therefore are files that contain javac arguments.- Parameters:
args- a list of command-line arguments; is not modified- Returns:
- a List of files representing all arguments that started with @
-
extractArg
Remove the argument given by argumentName and the subsequent value from the list args if present. Return the subsequent value or null if not found.- Parameters:
argumentName- a command-line option name whose argument to extractargs- the current list of arguments- Returns:
- the string that follows argumentName if argumentName is in args, or null if argumentName is not present in args
-
extractFileArg
Remove the argument given by argumentName and the subsequent value from the list args if present. Return the subsequent value wrapped as a File.- Parameters:
argumentName- argument to extractalternative- file to return if argumentName is not found in argsargs- the current list of arguments- Returns:
- the string that follows argumentName wrapped as a File if argumentName is in args or alternative if argumentName is not present in args
-
extractJvmOpts
Remove all-Jarguments fromargsand add them to the returned list (without the-Jprefix).- Parameters:
args- the arguments to extract from- Returns:
- all
-Jarguments (without the-Jprefix) or an empty list if there were none
-
extractCpOpts
Returns the last-cpor-classpathoption. If no-cpor-classpatharguments were present, then return the CLASSPATH environment variable (if set) followed by the current directory.Also removes all
-cpand-classpathoptions from args.- Parameters:
args- a list of arguments to extract from; is side-effected by this- Returns:
- collection of classpaths to concatenate to use when calling javac.jar
-
extractPpOpts
Remove all-processorpathoptions and their arguments from args. Return the last argument.- Parameters:
args- a list of arguments to extract from- Returns:
- the arguments that should be put on the processorpath when calling javac.jar
-
getExecArguments
Returns a list of arguments to pass to javac.- Returns:
- a list of arguments to pass to javac
-
invokeCompiler
public int invokeCompiler()Invoke the compiler with all relevant jars on its classpath and/or bootclasspath.- Returns:
- error code
-
expandArgFiles
Returns all the lines in all the files.- Parameters:
files- a list of files- Returns:
- a list of all the lines in all the files
-
findPathTo
public static String findPathTo(@Nullable Class<?> cls, boolean errIfFromDirectory) throws IllegalStateException Find the jar file or directory containing the .class file from which cls was loaded.- Parameters:
cls- the class whose .class file we wish to locate; if null, CheckerMain.classerrIfFromDirectory- if false, throw an exception if the file was loaded from a directory- Throws:
IllegalStateException
-
matchesCheckerOrSubcheckerFromList
public static boolean matchesCheckerOrSubcheckerFromList(String processorString, List<@FullyQualifiedName String> fullyQualifiedCheckerNames) Returns true if processorString, once transformed into fully-qualified form, is present in fullyQualifiedCheckerNames. Used by SourceChecker to determine whether a class is annotated for any processor that is being run.- Parameters:
processorString- the name of a single processor, not a comma-separated list of processorsfullyQualifiedCheckerNames- a list of fully-qualified checker names- Returns:
- true if the fully-qualified version of
processorStringis infullyQualifiedCheckerNames
-
replaceShorthandProcessor
For every "-processor" argument in args, replace its immediate successor argument using unabbreviateProcessorNames. -
unshorthandProcessorNames
protected static String unshorthandProcessorNames(String processorsString, List<@FullyQualifiedName String> fullyQualifiedCheckerNames, boolean allowSubcheckers) Takes a string of comma-separated processor names, and expands any shorthands to fully-qualified names from the fullyQualifiedCheckerNames list. For example:NullnessChecker → org.checkerframework.checker.nullness.NullnessChecker nullness → org.checkerframework.checker.nullness.NullnessChecker NullnessChecker,RegexChecker → org.checkerframework.checker.nullness.NullnessChecker,org.checkerframework.checker.regex.RegexChecker
Note, a processor entry only gets replaced if it contains NO "." (i.e., it is not qualified by a package name) and can be found under the package org.checkerframework.checker in checker.jar.- Parameters:
processorsString- a comma-separated string identifying processors; often just one processorfullyQualifiedCheckerNames- a list of fully-qualified checker names to match processorsString againstallowSubcheckers- if true, match against fully qualified checker names ending with "Subchecker"- Returns:
- processorsString where all shorthand references to Checker Framework built-in checkers are replaced with fully-qualified references
-
matchesFullyQualifiedProcessor
public static boolean matchesFullyQualifiedProcessor(String processorName, List<@FullyQualifiedName String> fullyQualifiedCheckerNames, boolean allowSubcheckers) Given a shorthand processor name, returns true if it can be expanded to a checker in the fullyQualifiedCheckerNames list.- Parameters:
processorName- a string identifying one processorfullyQualifiedCheckerNames- a list of fully-qualified checker names to match processorName againstallowSubcheckers- if true, match against fully qualified checker names ending with "Subchecker"- Returns:
- true if the shorthand processor name can be expanded to a checker in
fullyQualifiedCheckerNames
-