public class JavaCompiler extends Object
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
Modifier and Type | Class and Description |
---|---|
protected static class |
JavaCompiler.CompilePolicy
Control how the compiler's latter phases (attr, flow, desugar, generate)
are connected.
|
protected static class |
JavaCompiler.ImplicitSourcePolicy |
Modifier and Type | Field and Description |
---|---|
protected Annotate |
annotate
The annotation annotator.
|
protected boolean |
annotationProcessingOccurred
Flag set if any annotation processing occurred.
|
protected Attr |
attr
The attributor.
|
boolean |
attrParseOnly
Generate attributed parse tree only.
|
protected Check |
chk
The attributor.
|
List<Closeable> |
closeables
A list of items to be closed when the compilation is complete.
|
protected JavaCompiler.CompilePolicy |
compilePolicy
The policy for the order in which to perform the compilation
|
protected static Context.Key<JavaCompiler> |
compilerKey
The context key for the compiler.
|
protected CompileStates |
compileStates |
protected Name |
completionFailureName
Force a completion failure on this name
|
protected Context |
context |
protected JavaCompiler |
delegateCompiler
Annotation processing may require and provide a new instance
of the compiler to be used for the analyze and generate phases.
|
protected boolean |
devVerbose
Switch: should we debug ignored exceptions
|
long |
elapsed_msec |
String |
encoding
The encoding to be used for source input.
|
protected Enter |
enter
The module for the symbol table entry phases.
|
protected boolean |
explicitAnnotationProcessingRequested
Switch: is annotation processing requested explicitly via
CompilationTask.setProcessors?
|
protected JavaFileManager |
fileManager
Access to file objects.
|
protected Flow |
flow
The flow analyzer.
|
protected Gen |
gen
The module for code generation.
|
boolean |
genEndPos
Switch: should we store the ending positions?
|
protected boolean |
implicitSourceFilesRead
Flag set if any implicit source files read.
|
protected JavaCompiler.ImplicitSourcePolicy |
implicitSourcePolicy
The policy for what to do with implicitly read source files
|
protected Set<JavaFileObject> |
inputFiles
The set of currently compiled inputfiles, needed to ensure
we don't accidentally overwrite an input file when -s is set.
|
protected JNIWriter |
jniWriter
The native header writer.
|
boolean |
keepComments |
boolean |
lineDebugInfo
Generate code with the LineNumberTable attribute for debugging
|
Log |
log
The log to be used for error reporting.
|
protected Lower |
lower
The syntactic sugar desweetener.
|
protected TreeMaker |
make
The tree factory module.
|
protected Names |
names
The name table.
|
protected boolean |
needRootClasses
Set needRootClasses to true, in JavaCompiler subclass constructor
that want to collect public apis of classes supplied on the command line.
|
protected Options |
options
Command line options.
|
protected ParserFactory |
parserFactory
Factory for parsers.
|
boolean |
printFlat
Debug switch: Emit Java sources after inner class flattening.
|
protected boolean |
processPcks
Switch: should we (annotation) process packages as well
|
protected ClassReader |
reader
The class reader.
|
CompileStates.CompileState |
shouldStopPolicyIfError
Policy of how far to continue compilation after errors have occurred.
|
CompileStates.CompileState |
shouldStopPolicyIfNoError
Policy of how far to continue compilation when no errors have occurred.
|
protected Source |
source
The language version.
|
boolean |
sourceOutput
Emit plain Java source files rather than class files.
|
boolean |
stubOutput
Emit stub source files rather than class files.
|
protected Symtab |
syms
The symbol table.
|
protected MultiTaskListener |
taskListener
Broadcasting listener for progress events
|
protected ClassReader.SourceCompleter |
thisCompleter
SourceCompleter that delegates to the complete-method of this class.
|
Todo |
todo
A queue of all as yet unattributed classes.
|
protected TransTypes |
transTypes
The type eraser.
|
protected Types |
types
Type utilities.
|
boolean |
verbose
Verbose output.
|
boolean |
verboseCompilePolicy
Report activity related to compilePolicy
|
protected boolean |
werror
Switch: treat warnings as errors
|
protected ClassWriter |
writer
The class writer.
|
Constructor and Description |
---|
JavaCompiler(Context context)
Construct a new compiler using a shared context.
|
Modifier and Type | Method and Description |
---|---|
Env<AttrContext> |
attribute(Env<AttrContext> env)
Attribute a parse tree.
|
Queue<Env<AttrContext>> |
attribute(Queue<Env<AttrContext>> envs)
Attribute a list of parse trees, such as found on the "todo" list.
|
void |
close()
Close the compiler, flushing the logs
|
void |
close(boolean disposeNames) |
void |
compile(List<JavaFileObject> sourceFileObject) |
void |
compile(List<JavaFileObject> sourceFileObjects,
List<String> classnames,
Iterable<? extends Processor> processors)
Main method: compile a list of files, return all compiled classes
|
void |
complete(Symbol.ClassSymbol c)
Complete compiling a source file that has been accessed
by the class file reader.
|
protected void |
desugar(Env<AttrContext> env,
Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> results)
Prepare attributed parse trees, in conjunction with their attribution contexts,
for source or code generation.
|
Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> |
desugar(Queue<Env<AttrContext>> envs)
Prepare attributed parse trees, in conjunction with their attribution contexts,
for source or code generation.
|
List<JCTree.JCCompilationUnit> |
enterTrees(List<JCTree.JCCompilationUnit> roots)
Enter the symbols found in a list of parse trees.
|
List<JCTree.JCCompilationUnit> |
enterTreesIfNeeded(List<JCTree.JCCompilationUnit> roots)
Enter the symbols found in a list of parse trees if the compilation
is expected to proceed beyond anno processing into attr.
|
int |
errorCount()
The number of errors reported so far.
|
Queue<Env<AttrContext>> |
flow(Env<AttrContext> env)
Perform dataflow checks on an attributed parse tree.
|
protected void |
flow(Env<AttrContext> env,
Queue<Env<AttrContext>> results)
Perform dataflow checks on an attributed parse tree.
|
Queue<Env<AttrContext>> |
flow(Queue<Env<AttrContext>> envs)
Perform dataflow checks on attributed parse trees.
|
static String |
fullVersion()
The current full version number as a string.
|
void |
generate(Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue)
Generates the source or class file for a list of classes.
|
void |
generate(Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue,
Queue<JavaFileObject> results) |
void |
initProcessAnnotations(Iterable<? extends Processor> processors)
Check if we should process annotations.
|
void |
initRound(JavaCompiler prev) |
static JavaCompiler |
instance(Context context)
Get the JavaCompiler instance for this context.
|
protected boolean |
keepComments() |
JCTree.JCCompilationUnit |
parse(JavaFileObject filename)
Parse contents of file.
|
protected JCTree.JCCompilationUnit |
parse(JavaFileObject filename,
CharSequence content)
Parse contents of input stream.
|
JCTree.JCCompilationUnit |
parse(String filename)
Deprecated.
|
List<JCTree.JCCompilationUnit> |
parseFiles(Iterable<JavaFileObject> fileObjects)
Parses a list of files.
|
void |
printCount(String kind,
int count)
Print numbers of errors and warnings.
|
protected void |
printNote(String lines) |
JavaCompiler |
processAnnotations(List<JCTree.JCCompilationUnit> roots) |
JavaCompiler |
processAnnotations(List<JCTree.JCCompilationUnit> roots,
List<String> classnames)
Process any annotations found in the specified compilation units.
|
CharSequence |
readSource(JavaFileObject filename)
Try to open input stream with given name.
|
void |
reportDeferredDiagnostics() |
void |
reportPublicApi(Symbol.ClassSymbol sym)
Report the public api of a class that was supplied explicitly for compilation,
for example on the command line to javac.
|
Symbol |
resolveBinaryNameOrIdent(String name)
Resolve an identifier which may be the binary name of a class or
the Java name of a class or package.
|
Symbol |
resolveIdent(String name)
Resolve an identifier.
|
protected boolean |
shouldStop(CompileStates.CompileState cs) |
protected <T> List<T> |
stopIfError(CompileStates.CompileState cs,
List<T> list) |
protected <T> Queue<T> |
stopIfError(CompileStates.CompileState cs,
Queue<T> queue) |
static String |
version()
The current version number as a string.
|
int |
warningCount()
The number of warnings reported so far.
|
protected static final Context.Key<JavaCompiler> compilerKey
public Log log
protected TreeMaker make
protected ClassReader reader
protected ClassWriter writer
protected JNIWriter jniWriter
protected Enter enter
protected Symtab syms
protected Source source
protected Gen gen
protected Names names
protected Attr attr
protected Check chk
protected Flow flow
protected TransTypes transTypes
protected Lower lower
protected Annotate annotate
protected final Name completionFailureName
protected Types types
protected JavaFileManager fileManager
protected ParserFactory parserFactory
protected MultiTaskListener taskListener
protected JavaCompiler delegateCompiler
protected final ClassReader.SourceCompleter thisCompleter
protected Options options
protected Context context
protected boolean annotationProcessingOccurred
protected boolean implicitSourceFilesRead
protected CompileStates compileStates
public boolean verbose
public boolean sourceOutput
public boolean stubOutput
public boolean attrParseOnly
public boolean printFlat
public String encoding
public boolean lineDebugInfo
public boolean genEndPos
protected boolean devVerbose
protected boolean processPcks
protected boolean werror
protected boolean explicitAnnotationProcessingRequested
protected JavaCompiler.CompilePolicy compilePolicy
protected JavaCompiler.ImplicitSourcePolicy implicitSourcePolicy
public boolean verboseCompilePolicy
public CompileStates.CompileState shouldStopPolicyIfError
public CompileStates.CompileState shouldStopPolicyIfNoError
public Todo todo
public List<Closeable> closeables
protected Set<JavaFileObject> inputFiles
public boolean keepComments
public long elapsed_msec
protected boolean needRootClasses
public JavaCompiler(Context context)
public static JavaCompiler instance(Context context)
public static String version()
public static String fullVersion()
protected boolean shouldStop(CompileStates.CompileState cs)
public int errorCount()
protected final <T> Queue<T> stopIfError(CompileStates.CompileState cs, Queue<T> queue)
protected final <T> List<T> stopIfError(CompileStates.CompileState cs, List<T> list)
public int warningCount()
public CharSequence readSource(JavaFileObject filename)
filename
- The file name of the input stream to be opened.protected JCTree.JCCompilationUnit parse(JavaFileObject filename, CharSequence content)
filename
- The name of the file from which input stream comes.content
- The characters to be parsed.protected boolean keepComments()
@Deprecated public JCTree.JCCompilationUnit parse(String filename)
filename
- The name of the file to be parsed.public JCTree.JCCompilationUnit parse(JavaFileObject filename)
filename
- The name of the file to be parsed.public Symbol resolveBinaryNameOrIdent(String name)
name
- The name to resolvepublic Symbol resolveIdent(String name)
name
- The identifier to resolvepublic void complete(Symbol.ClassSymbol c) throws Symbol.CompletionFailure
c
- The class the source file of which needs to be compiled.Symbol.CompletionFailure
public void compile(List<JavaFileObject> sourceFileObject) throws Throwable
Throwable
public void compile(List<JavaFileObject> sourceFileObjects, List<String> classnames, Iterable<? extends Processor> processors)
sourceFileObjects
- file objects to be compiledclassnames
- class names to process for annotationsprocessors
- user provided annotation processors to bypass
discovery, null
means that no processors were providedpublic List<JCTree.JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects)
public List<JCTree.JCCompilationUnit> enterTreesIfNeeded(List<JCTree.JCCompilationUnit> roots)
public List<JCTree.JCCompilationUnit> enterTrees(List<JCTree.JCCompilationUnit> roots)
public void initProcessAnnotations(Iterable<? extends Processor> processors)
processors
- user provided annotation processors to bypass
discovery, null
means that no processors were providedpublic JavaCompiler processAnnotations(List<JCTree.JCCompilationUnit> roots)
public JavaCompiler processAnnotations(List<JCTree.JCCompilationUnit> roots, List<String> classnames)
roots
- a list of compilation unitspublic Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs)
public Env<AttrContext> attribute(Env<AttrContext> env)
public void reportPublicApi(Symbol.ClassSymbol sym)
sym
- The symbol of the class.public Queue<Env<AttrContext>> flow(Queue<Env<AttrContext>> envs)
public Queue<Env<AttrContext>> flow(Env<AttrContext> env)
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results)
public Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> desugar(Queue<Env<AttrContext>> envs)
protected void desugar(Env<AttrContext> env, Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> results)
public void generate(Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue)
public void generate(Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue, Queue<JavaFileObject> results)
public void reportDeferredDiagnostics()
public void close()
public void close(boolean disposeNames)
protected void printNote(String lines)
public void printCount(String kind, int count)
public void initRound(JavaCompiler prev)
Copyright © 2017 earcam. All rights reserved.