public class CheckerMain extends Object
javac.jar
to the runtime bootclasspath of the process that
runs the Checker Framework. This specifies which classes are used to run javac
jdk7.jar
or jdk8.jar
to the compile time bootclasspath of the javac
argument list passed to javac
-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 a
special version of 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 |
protected static String |
CHECKER_BASE_PACKAGE
All "built-in" Checker Framework checkers, except SubtypingChecker, start with this package
file path.
|
protected File |
checkerJar
The path to the jar containing CheckerMain.class (i.e.
|
protected File |
checkerQualJar
The path to checker-qual.jar.
|
protected static String |
FULLY_QUALIFIED_SUBTYPING_CHECKER |
protected File |
javacJar
The path to the jsr308 Langtools Type Annotations Compiler.
|
protected File |
jdkJar
The path to the annotated jdk jar to use.
|
protected static Pattern |
JVM_OPTS_REGEX
Matches all
-J arguments. |
protected static String |
SUBTYPING_CHECKER_NAME |
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() |
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) |
protected List<String> |
createCpOpts(List<String> argsList) |
protected List<String> |
createPpOpts(List<String> argsList) |
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 JSR308 Type Annotations Compiler with all relevant jars on its classpath or boot
classpath.
|
int |
invokeCompiler()
Invoke the JSR308 Type Annotations Compiler with all relevant jars on its classpath or boot
classpath.
|
static void |
main(String[] args)
Invoke the JSR 308 Type Annotations Compiler.
|
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 processor,
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 jdkJar
protected final File javacJar
protected final File checkerJar
protected final File checkerQualJar
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_PACKAGE
protected static final String CHECKER_BASE_DIR_NAME
protected static final String FULLY_QUALIFIED_SUBTYPING_CHECKER
protected static final String SUBTYPING_CHECKER_NAME
public static void main(String[] args)
protected void assertValidState()
protected List<String> createCompilationBootclasspath(List<String> argsList)
protected 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.class.errIfFromDirectory
- 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 namesprotected 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 processor, List<String> fullyQualifiedCheckerNames, boolean allowSubcheckers)
processor
- a string identifying one processorfullyQualifiedCheckerNames
- a list of fully-qualified checker names to match processor
againstallowSubcheckers
- whether to match against fully qualified checker names ending with
"Subchecker"