public class CheckerMain
extends java.lang.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 java.util.regex.Pattern |
BOOT_CLASS_PATH_REGEX
A pattern to match bootclasspath prepend entries, used to construct one
-Xbootclasspath/p: command-line argument |
protected static java.lang.String |
CHECKER_BASE_DIR_NAME |
protected static java.lang.String |
CHECKER_BASE_PACKAGE
All "built-in" Checker Framework checkers, except SubtypingChecker, start with this package
file path.
|
protected java.io.File |
checkerJar
The path to the jar containing CheckerMain.class (i.e.
|
protected java.io.File |
checkerQualJar
The path to checker-qual.jar
|
protected static java.lang.String |
FULLY_QUALIFIED_SUBTYPING_CHECKER |
protected java.io.File |
javacJar
The path to the jsr308 Langtools Type Annotations Compiler
|
protected java.io.File |
jdkJar
The path to the annotated jdk jar to use
|
protected static java.util.regex.Pattern |
JVM_OPTS_REGEX
Matches all
-J arguments |
protected static java.lang.String |
SUBTYPING_CHECKER_NAME |
Constructor and Description |
---|
CheckerMain(java.io.File checkerJar,
java.util.List<java.lang.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(java.util.List<java.lang.String> args) |
void |
addToClasspath(java.util.List<java.lang.String> cpOpts) |
void |
addToProcessorpath(java.util.List<java.lang.String> ppOpts) |
void |
addToRuntimeClasspath(java.util.List<java.lang.String> runtimeClasspathOpts) |
protected void |
assertValidState() |
protected java.util.List<java.io.File> |
collectArgFiles(java.util.List<java.lang.String> args)
Return the arguments that start with @ and therefore are files that contain javac arguments.
|
protected java.util.List<java.lang.String> |
createCompilationBootclasspath(java.util.List<java.lang.String> argsList) |
protected java.util.List<java.lang.String> |
createCpOpts(java.util.List<java.lang.String> argsList) |
protected java.util.List<java.lang.String> |
createPpOpts(java.util.List<java.lang.String> argsList) |
protected java.util.List<java.lang.String> |
createRuntimeClasspath(java.util.List<java.lang.String> argsList) |
protected static java.util.List<java.lang.String> |
expandArgFiles(java.util.List<java.io.File> files)
Return all the lines in all the files.
|
protected static java.lang.String |
extractArg(java.lang.String argumentName,
java.lang.String alternative,
java.util.List<java.lang.String> args)
Remove the argument given by argumentName and the subsequent value from the list args if
present.
|
protected static java.util.List<java.lang.String> |
extractBootClassPath(java.util.List<java.lang.String> args)
Remove all
-Xbootclasspath/p: or -J-Xbootclasspath/p: arguments from args and
add them to the returned list. |
protected static java.util.List<java.lang.String> |
extractCpOpts(java.util.List<java.lang.String> args)
Remove the
-cp and -classpath options and their arguments from args. |
protected static java.io.File |
extractFileArg(java.lang.String argumentName,
java.io.File alternative,
java.util.List<java.lang.String> args)
Remove the argument given by argumentName and the subsequent value from the list args if
present.
|
protected static java.util.List<java.lang.String> |
extractJvmOpts(java.util.List<java.lang.String> args)
Remove all
-J arguments from args and add them to the returned list (without
the -J prefix) |
protected static java.util.List<java.lang.String> |
extractOptWithPattern(java.util.regex.Pattern pattern,
boolean allowEmpties,
java.util.List<java.lang.String> args)
Find all args that match the given pattern and extract their index 1 group.
|
protected static java.util.List<java.lang.String> |
extractPpOpts(java.util.List<java.lang.String> args)
Remove the
-processorpath options and their arguments from args. |
static java.lang.String |
findPathTo(java.lang.Class<?> cls,
boolean errIfFromDirectory)
Find the jar file or directory containing the .class file from which cls was loaded
|
java.util.List<java.lang.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(java.lang.String[] args)
Invoke the JSR 308 Type Annotations Compiler.
|
static boolean |
matchesCheckerOrSubcheckerFromList(java.lang.String processorString,
java.util.List<java.lang.String> fullyQualifiedCheckerNames)
Returns true if processorString, once transformed into fully-qualified form, is present in
fullyQualifiedCheckerNames.
|
static boolean |
matchesFullyQualifiedProcessor(java.lang.String processor,
java.util.List<java.lang.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(java.util.List<java.lang.String> args)
For every "-processor" argument in args, replace its immediate successor argument using
unabbreviateProcessorNames
|
protected static java.lang.String |
unshorthandProcessorNames(java.lang.String processorsString,
java.util.List<java.lang.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 java.io.File jdkJar
protected final java.io.File javacJar
protected final java.io.File checkerJar
protected final java.io.File checkerQualJar
protected static final java.util.regex.Pattern BOOT_CLASS_PATH_REGEX
-Xbootclasspath/p:
command-line argumentprotected static final java.util.regex.Pattern JVM_OPTS_REGEX
-J
argumentsprotected static final java.lang.String CHECKER_BASE_PACKAGE
protected static final java.lang.String CHECKER_BASE_DIR_NAME
protected static final java.lang.String FULLY_QUALIFIED_SUBTYPING_CHECKER
protected static final java.lang.String SUBTYPING_CHECKER_NAME
public CheckerMain(java.io.File checkerJar, java.util.List<java.lang.String> args)
public static void main(java.lang.String[] args)
protected void assertValidState()
public void addToClasspath(java.util.List<java.lang.String> cpOpts)
public void addToProcessorpath(java.util.List<java.lang.String> ppOpts)
public void addToRuntimeClasspath(java.util.List<java.lang.String> runtimeClasspathOpts)
protected java.util.List<java.lang.String> createRuntimeClasspath(java.util.List<java.lang.String> argsList)
protected java.util.List<java.lang.String> createCompilationBootclasspath(java.util.List<java.lang.String> argsList)
protected java.util.List<java.lang.String> createCpOpts(java.util.List<java.lang.String> argsList)
protected java.util.List<java.lang.String> createPpOpts(java.util.List<java.lang.String> argsList)
protected java.util.List<java.io.File> collectArgFiles(java.util.List<java.lang.String> args)
args
- a list of command-line arguments; is not modifiedprotected static java.lang.String extractArg(java.lang.String argumentName, java.lang.String alternative, java.util.List<java.lang.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 java.io.File extractFileArg(java.lang.String argumentName, java.io.File alternative, java.util.List<java.lang.String> args)
argumentName
- argument to extractalternative
- file to return if argumentName is not found in argsargs
- the current list of argumentsprotected static java.util.List<java.lang.String> extractOptWithPattern(java.util.regex.Pattern pattern, boolean allowEmpties, java.util.List<java.lang.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 java.util.List<java.lang.String> extractBootClassPath(java.util.List<java.lang.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 java.util.List<java.lang.String> extractJvmOpts(java.util.List<java.lang.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 java.util.List<java.lang.String> extractCpOpts(java.util.List<java.lang.String> args)
-cp
and -classpath
options and their arguments from args. Return
the last argument. If no -cp
or -classpath
arguments were present then return
the CLASSPATH environment variable followed by the current directory.args
- a list of arguments to extract fromprotected static java.util.List<java.lang.String> extractPpOpts(java.util.List<java.lang.String> args)
-processorpath
options and their arguments from args. Return the last
argument.args
- a list of arguments to extract fromprotected void addMainToArgs(java.util.List<java.lang.String> args)
public java.util.List<java.lang.String> getExecArguments()
public int invokeCompiler()
protected static java.util.List<java.lang.String> expandArgFiles(java.util.List<java.io.File> files)
files
- a list of filespublic static java.lang.String findPathTo(java.lang.Class<?> cls, boolean errIfFromDirectory) throws java.lang.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
directoryjava.lang.IllegalStateException
public static boolean matchesCheckerOrSubcheckerFromList(java.lang.String processorString, java.util.List<java.lang.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(java.util.List<java.lang.String> args)
protected static java.lang.String unshorthandProcessorNames(java.lang.String processorsString, java.util.List<java.lang.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(java.lang.String processor, java.util.List<java.lang.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"