public class CheckerMain extends Object
javac.jar
to the runtime classpath of the process that runs the Checker
Framework.
-AoutputArgsToFile=FILENAME
command-line argument or -AoutputArgsToFile=-
to output to standard out.
"To run the Checker Framework" really means to run java, where the program being run is javac
and javac is passed a -processor
command-line argument that mentions a Checker Framework
checker. There are 5 relevant classpaths: The classpath and bootclasspath when running java, and
the classpath, bootclasspath, and processorpath used by javac. The latter three are the only
important ones.
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.
Modifier and Type | Field and Description |
---|---|
protected static Pattern |
BOOT_CLASS_PATH_REGEX
A pattern to match bootclasspath prepend entries, used to construct one
-Xbootclasspath/p: command-line argument. |
protected static String |
CHECKER_BASE_DIR_NAME
Processor shorthand is enabled for processors in this directory in checker.jar.
|
static String |
CHECKER_QUAL_PATH_OPT
Option name for specifying an alternative checker-qual.jar location.
|
static String |
CHECKER_UTIL_PATH_OPT
Option name for specifying an alternative checker-util.jar location.
|
protected File |
checkerJar
The path to the jar containing CheckerMain.class (i.e.
|
protected File |
checkerQualJar
The path to checker-qual.jar.
|
protected File |
checkerUtilJar
The path to checker-util.jar.
|
protected static String |
COMMON_BASE_DIR_NAME
Processor shorthand is enabled for processors in this directory in checker.jar.
|
static String |
JAVAC_PATH_OPT
Option name for specifying an alternative javac.jar location.
|
protected File |
javacJar
The path to the javacJar to use.
|
static String |
JDK_PATH_OPT
Option name for specifying an alternative jdk.jar location.
|
protected static Pattern |
JVM_OPTS_REGEX
Matches all
-J arguments. |
Constructor and Description |
---|
CheckerMain(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.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addMainToArgs(List<String> args) |
void |
addToClasspath(List<String> cpOpts) |
void |
addToProcessorpath(List<String> ppOpts) |
void |
addToRuntimeClasspath(List<String> runtimeClasspathOpts) |
protected void |
assertValidState()
Assert that required jars exist.
|
protected List<File> |
collectArgFiles(List<String> args)
Return the arguments that start with @ and therefore are files that contain javac arguments.
|
protected List<String> |
createCompilationBootclasspath(List<String> argsList)
Returns the compilation bootclasspath from
argsList . |
protected List<String> |
createCpOpts(List<String> argsList) |
protected List<String> |
createPpOpts(List<String> argsList)
Returns processor path options.
|
protected List<String> |
createRuntimeClasspath(List<String> argsList) |
protected static List<String> |
expandArgFiles(List<File> files)
Return all the lines in all the files.
|
protected static String |
extractArg(String argumentName,
String alternative,
List<String> args)
Remove the argument given by argumentName and the subsequent value from the list args if
present.
|
protected static List<String> |
extractBootClassPath(List<String> args)
Remove all
-Xbootclasspath/p: or -J-Xbootclasspath/p: arguments from args and
add them to the returned list. |
protected static List<String> |
extractCpOpts(List<String> args)
Return the last
-cp or -classpath option. |
protected static File |
extractFileArg(String argumentName,
File alternative,
List<String> args)
Remove the argument given by argumentName and the subsequent value from the list args if
present.
|
protected static List<String> |
extractJvmOpts(List<String> args)
Remove all
-J arguments from args and add them to the returned list (without
the -J prefix). |
protected static List<String> |
extractOptWithPattern(Pattern pattern,
boolean allowEmpties,
List<String> args)
Find all args that match the given pattern and extract their index 1 group.
|
protected static List<String> |
extractPpOpts(List<String> args)
Remove the
-processorpath options and their arguments from args. |
static String |
findPathTo(Class<?> cls,
boolean errIfFromDirectory)
Find the jar file or directory containing the .class file from which cls was loaded.
|
List<String> |
getExecArguments()
Invoke the compiler with all relevant jars on its classpath and/or bootclasspath.
|
int |
invokeCompiler()
Invoke the compiler with all relevant jars on its classpath and/or bootclasspath.
|
static void |
main(String[] args)
Any exception thrown by the Checker Framework escapes to the command line.
|
static boolean |
matchesCheckerOrSubcheckerFromList(String processorString,
List<String> fullyQualifiedCheckerNames)
Returns true if processorString, once transformed into fully-qualified form, is present in
fullyQualifiedCheckerNames.
|
static boolean |
matchesFullyQualifiedProcessor(String processorName,
List<String> fullyQualifiedCheckerNames,
boolean allowSubcheckers)
Given a shorthand processor name, returns true if it can be expanded to a checker in the
fullyQualifiedCheckerNames list.
|
protected void |
replaceShorthandProcessor(List<String> args)
For every "-processor" argument in args, replace its immediate successor argument using
unabbreviateProcessorNames.
|
protected static String |
unshorthandProcessorNames(String processorsString,
List<String> fullyQualifiedCheckerNames,
boolean allowSubcheckers)
Takes a string of comma-separated processor names, and expands any shorthands to
fully-qualified names from the fullyQualifiedCheckerNames list.
|
protected final File javacJar
protected final File checkerJar
protected final File checkerQualJar
protected final File checkerUtilJar
public static final String CHECKER_QUAL_PATH_OPT
public static final String CHECKER_UTIL_PATH_OPT
public static final String JAVAC_PATH_OPT
public static final String JDK_PATH_OPT
protected static final Pattern BOOT_CLASS_PATH_REGEX
-Xbootclasspath/p:
command-line argument.protected static final Pattern JVM_OPTS_REGEX
-J
arguments.protected static final String CHECKER_BASE_DIR_NAME
protected static final String COMMON_BASE_DIR_NAME
public static void main(String[] args)
args
- command-line argumentsprotected void assertValidState()
protected List<String> createCompilationBootclasspath(List<String> argsList)
argsList
.argsList
- args to addargsList
protected List<String> createPpOpts(List<String> argsList)
This method assumes that createCpOpts has already been run.
argsList
- argumentsprotected List<File> collectArgFiles(List<String> args)
args
- a list of command-line arguments; is not modifiedprotected static String extractArg(String argumentName, String alternative, List<String> args)
argumentName
- a command-line option name whose argument to extractalternative
- default value to return if argumentName does not appear in argsargs
- the current list of argumentsprotected static File extractFileArg(String argumentName, File alternative, List<String> args)
argumentName
- argument to extractalternative
- file to return if argumentName is not found in argsargs
- the current list of argumentsprotected static List<String> extractOptWithPattern(Pattern pattern, boolean allowEmpties, List<String> args)
pattern
- a pattern with at least one matching groupallowEmpties
- whether or not to add empty group(1) matches to the returned listargs
- the arguments to extract fromprotected static List<String> extractBootClassPath(List<String> args)
-Xbootclasspath/p:
or -J-Xbootclasspath/p:
arguments from args and
add them to the returned list.args
- the arguments to extract fromprotected static List<String> extractJvmOpts(List<String> args)
-J
arguments from args
and add them to the returned list (without
the -J
prefix).args
- the arguments to extract from-J
arguments (without the -J
prefix) or an empty list if there were
noneprotected static List<String> extractCpOpts(List<String> args)
-cp
or -classpath
option. If no -cp
or -classpath
arguments were present, then return the CLASSPATH environment variable (if set)
followed by the current directory.
Also removes all -cp
and -classpath
options from args.
args
- a list of arguments to extract from; is side-effected by thisprotected static List<String> extractPpOpts(List<String> args)
-processorpath
options and their arguments from args. Return the last
argument.args
- a list of arguments to extract frompublic List<String> getExecArguments()
public int invokeCompiler()
protected static List<String> expandArgFiles(List<File> files)
files
- a list of filespublic static String findPathTo(Class<?> cls, boolean errIfFromDirectory) throws IllegalStateException
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 directoryIllegalStateException
public static boolean matchesCheckerOrSubcheckerFromList(String processorString, List<String> fullyQualifiedCheckerNames)
processorString
- the name of a single processor, not a comma-separated list of processorsfullyQualifiedCheckerNames
- a list of fully-qualified checker namesprocessorString
is in fullyQualifiedCheckerNames
protected void replaceShorthandProcessor(List<String> args)
protected static String unshorthandProcessorNames(String processorsString, List<String> fullyQualifiedCheckerNames, boolean allowSubcheckers)
NullnessChecker → org.checkerframework.checker.nullness.NullnessChecker nullness → org.checkerframework.checker.nullness.NullnessChecker NullnessChecker,RegexChecker → org.checkerframework.checker.nullness.NullnessChecker,org.checkerframework.checker.regex.RegexCheckerNote, 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.
processorsString
- a comma-separated string identifying processorsfullyQualifiedCheckerNames
- a list of fully-qualified checker names to match
processorsString againstallowSubcheckers
- whether to match against fully qualified checker names ending with
"Subchecker"public static boolean matchesFullyQualifiedProcessor(String processorName, List<String> fullyQualifiedCheckerNames, boolean allowSubcheckers)
processorName
- a string identifying one processorfullyQualifiedCheckerNames
- a list of fully-qualified checker names to match
processorName againstallowSubcheckers
- whether to match against fully qualified checker names ending with
"Subchecker"fullyQualifiedCheckerNames