|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.main.JavaCompiler
public class JavaCompiler
This class could be the main entry point for GJC when GJC is used as a component in a larger software system. It provides operations to construct a new compiler, and to run a new compiler on a set of source files.
This is NOT part of any API supported by Sun Microsystems. 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.
| Nested Class Summary | |
|---|---|
protected static class |
JavaCompiler.CompilePolicy
Control how the compiler's latter phases (attr, flow, desugar, generate) are connected. |
protected static class |
JavaCompiler.CompileState
|
protected class |
JavaCompiler.CompileStates
|
protected static class |
JavaCompiler.ImplicitSourcePolicy
|
| Field Summary | |
|---|---|
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. |
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. |
private JavaCompiler.CompileStates |
compileStates
|
protected Name |
completionFailureName
Force a completion failure on this name |
protected Context |
context
|
private static JavaCompiler.CompilePolicy |
DEFAULT_COMPILE_POLICY
|
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 |
(package private) JCDiagnostic.Factory |
diagFactory
Factory for creating diagnostic objects |
long |
elapsed_msec
|
java.lang.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 explitly 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? |
private boolean |
hasBeenUsed
Track when the JavaCompiler has been used to compile something. |
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 java.util.Set<JavaFileObject> |
inputFiles
The set of currently compiled inputfiles, needed to ensure we don't accidentally overwrite an input file when -s is set. |
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. |
private boolean |
parseErrors
Track whether any errors occurred while parsing source text. |
protected ParserFactory |
parserFactory
Factory for parsers. |
boolean |
printFlat
Debug switch: Emit Java sources after inner class flattening. |
(package private) JavacProcessingEnvironment |
procEnvImpl
Object to handle annotation processing. |
(package private) boolean |
processAnnotations
Set to true to enable skeleton annotation processing code. |
protected boolean |
processPcks
Switch: should we (annotation) process packages as well |
protected ClassReader |
reader
The class reader. |
(package private) boolean |
relax
Switch: relax some constraints for producing the jsr14 prototype. |
private List<JCTree.JCClassDecl> |
rootClasses
|
protected Source |
source
The language version. |
boolean |
sourceOutput
Emit plain Java source files rather than class files. |
private long |
start_msec
|
boolean |
stubOutput
Emit stub source files rather than class files. |
protected Symtab |
syms
The symbol table. |
protected TaskListener |
taskListener
Optional listener for progress events |
Todo |
todo
A queue of all as yet unattributed classes. |
protected TransStaging |
transStaging
The staging eraser. |
protected TransTypes |
transTypes
The type eraser. |
protected Types |
types
Type utilities. |
boolean |
verbose
Verbose output. |
boolean |
verboseCompilePolicy
Report activity related to compilePolicy |
private static java.util.ResourceBundle |
versionRB
|
private static java.lang.String |
versionRBName
|
protected ClassWriter |
writer
The class writer. |
| Constructor Summary | |
|---|---|
JavaCompiler(Context context)
Construct a new compiler using a shared context. |
|
| Method Summary | ||
|---|---|---|
Env<AttrContext> |
attribute(Env<AttrContext> env)
Attribute a parse tree. |
|
java.util.Queue<Env<AttrContext>> |
attribute(java.util.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<java.lang.String> classnames,
java.lang.Iterable<? extends Processor> processors)
Main method: compile a list of files, return all compiled classes |
|
private void |
compile2()
The phases following annotation processing: attribution, desugar, and finally code generation. |
|
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,
java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> results)
Prepare attributed parse trees, in conjunction with their attribution contexts, for source or code generation. |
|
java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> |
desugar(java.util.Queue<Env<AttrContext>> envs)
Prepare attributed parse trees, in conjunction with their attribution contexts, for source or code generation. |
|
private static long |
elapsed(long then)
|
|
static void |
enableLogging()
|
|
List<JCTree.JCCompilationUnit> |
enterTrees(List<JCTree.JCCompilationUnit> roots)
Enter the symbols found in a list of parse trees. |
|
int |
errorCount()
The number of errors reported so far. |
|
(package private) boolean |
explicitAnnotationProcessingRequested()
|
|
java.util.Queue<Env<AttrContext>> |
flow(Env<AttrContext> env)
Perform dataflow checks on an attributed parse tree. |
|
protected void |
flow(Env<AttrContext> env,
java.util.Queue<Env<AttrContext>> results)
Perform dataflow checks on an attributed parse tree. |
|
java.util.Queue<Env<AttrContext>> |
flow(java.util.Queue<Env<AttrContext>> envs)
Perform dataflow checks on attributed parse trees. |
|
static java.lang.String |
fullVersion()
The current full version number as a string. |
|
(package private) JavaFileObject |
genCode(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
Generate code and emit a class file for a given class |
|
void |
generate(java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue)
Generates the source or class file for a list of classes. |
|
void |
generate(java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue,
java.util.Queue<JavaFileObject> results)
|
|
(package private) java.util.Map<JCTree.JCCompilationUnit,java.util.Queue<Env<AttrContext>>> |
groupByFile(java.util.Queue<Env<AttrContext>> envs)
|
|
void |
initProcessAnnotations(java.lang.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()
|
|
private static long |
now()
|
|
JCTree.JCCompilationUnit |
parse(JavaFileObject filename)
Parse contents of file. |
|
protected JCTree.JCCompilationUnit |
parse(JavaFileObject filename,
java.lang.CharSequence content)
Parse contents of input stream. |
|
JCTree.JCCompilationUnit |
parse(java.lang.String filename)
Deprecated. |
|
boolean |
parseErrors()
Whether or not any parse errors have occurred. |
|
List<JCTree.JCCompilationUnit> |
parseFiles(List<JavaFileObject> fileObjects)
Parses a list of files. |
|
protected void |
printCount(java.lang.String kind,
int count)
Print numbers of errors and warnings. |
|
(package private) JavaFileObject |
printSource(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
Emit plain Java source for a class. |
|
protected void |
printVerbose(java.lang.String key,
java.lang.Object arg)
Output for "-verbose" option. |
|
JavaCompiler |
processAnnotations(List<JCTree.JCCompilationUnit> roots)
|
|
JavaCompiler |
processAnnotations(List<JCTree.JCCompilationUnit> roots,
List<java.lang.String> classnames)
Process any anotations found in the specifed compilation units. |
|
java.lang.CharSequence |
readSource(JavaFileObject filename)
Try to open input stream with given name. |
|
(package private) JCTree.JCClassDecl |
removeMethodBodies(JCTree.JCClassDecl cdef)
|
|
void |
reportDeferredDiagnostics()
|
|
Symbol |
resolveIdent(java.lang.String name)
Resolve an identifier. |
|
protected
|
stopIfError(List<T> list)
|
|
protected
|
stopIfError(java.util.Queue<T> queue)
|
|
static java.lang.String |
version()
The current version number as a string. |
|
private static java.lang.String |
version(java.lang.String key)
|
|
int |
warningCount()
The number of warnings reported so far. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final Context.Key<JavaCompiler> compilerKey
private static final java.lang.String versionRBName
private static java.util.ResourceBundle versionRB
private static JavaCompiler.CompilePolicy DEFAULT_COMPILE_POLICY
public Log log
JCDiagnostic.Factory diagFactory
protected TreeMaker make
protected ClassReader reader
protected ClassWriter writer
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 TransStaging transStaging
protected Lower lower
protected Annotate annotate
protected final Name completionFailureName
protected Types types
protected JavaFileManager fileManager
protected ParserFactory parserFactory
protected TaskListener taskListener
protected JavaCompiler delegateCompiler
protected boolean annotationProcessingOccurred
protected boolean implicitSourceFilesRead
protected Context context
public boolean verbose
public boolean sourceOutput
public boolean stubOutput
public boolean attrParseOnly
boolean relax
public boolean printFlat
public java.lang.String encoding
public boolean lineDebugInfo
public boolean genEndPos
protected boolean devVerbose
protected boolean processPcks
protected boolean explicitAnnotationProcessingRequested
protected JavaCompiler.CompilePolicy compilePolicy
protected JavaCompiler.ImplicitSourcePolicy implicitSourcePolicy
public boolean verboseCompilePolicy
public Todo todo
private JavaCompiler.CompileStates compileStates
protected java.util.Set<JavaFileObject> inputFiles
public boolean keepComments
private boolean hasBeenUsed
private long start_msec
public long elapsed_msec
private boolean parseErrors
private List<JCTree.JCClassDecl> rootClasses
boolean processAnnotations
JavacProcessingEnvironment procEnvImpl
| Constructor Detail |
|---|
public JavaCompiler(Context context)
| Method Detail |
|---|
public static JavaCompiler instance(Context context)
public static java.lang.String version()
public static java.lang.String fullVersion()
private static java.lang.String version(java.lang.String key)
public int errorCount()
protected final <T> java.util.Queue<T> stopIfError(java.util.Queue<T> queue)
protected final <T> List<T> stopIfError(List<T> list)
public int warningCount()
public boolean parseErrors()
public java.lang.CharSequence readSource(JavaFileObject filename)
filename - The file name of the input stream to be opened.
protected JCTree.JCCompilationUnit parse(JavaFileObject filename,
java.lang.CharSequence content)
filename - The name of the file from which input stream comes.input - The input stream to be parsed.protected boolean keepComments()
@Deprecated
public JCTree.JCCompilationUnit parse(java.lang.String filename)
throws java.io.IOException
filename - The name of the file to be parsed.
java.io.IOExceptionpublic JCTree.JCCompilationUnit parse(JavaFileObject filename)
filename - The name of the file to be parsed.public Symbol resolveIdent(java.lang.String name)
name - The identifier to resolve
JavaFileObject printSource(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
throws java.io.IOException
env - The attribution environment of the outermost class
containing this class.cdef - The class definition to be printed.
java.io.IOException
JavaFileObject genCode(Env<AttrContext> env,
JCTree.JCClassDecl cdef)
throws java.io.IOException
env - The attribution environment of the outermost class
containing this class.cdef - The class definition from which code is generated.
java.io.IOException
public void complete(Symbol.ClassSymbol c)
throws Symbol.CompletionFailure
complete in interface ClassReader.SourceCompleterc - The class the source file of which needs to be compiled.filename - The name of the source file.f - An input stream that reads the source file.
Symbol.CompletionFailure
public void compile(List<JavaFileObject> sourceFileObject)
throws java.lang.Throwable
java.lang.Throwable
public void compile(List<JavaFileObject> sourceFileObjects,
List<java.lang.String> classnames,
java.lang.Iterable<? extends Processor> processors)
throws java.io.IOException
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 provided
java.io.IOExceptionprivate void compile2()
public List<JCTree.JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects)
throws java.io.IOException
java.io.IOExceptionpublic List<JCTree.JCCompilationUnit> enterTrees(List<JCTree.JCCompilationUnit> roots)
public void initProcessAnnotations(java.lang.Iterable<? extends Processor> processors)
processors - user provided annotation processors to bypass
discovery, null means that no processors were provided
public JavaCompiler processAnnotations(List<JCTree.JCCompilationUnit> roots)
throws java.io.IOException
java.io.IOException
public JavaCompiler processAnnotations(List<JCTree.JCCompilationUnit> roots,
List<java.lang.String> classnames)
throws java.io.IOException
roots - a list of compilation units
java.io.IOExceptionboolean explicitAnnotationProcessingRequested()
public java.util.Queue<Env<AttrContext>> attribute(java.util.Queue<Env<AttrContext>> envs)
public Env<AttrContext> attribute(Env<AttrContext> env)
public java.util.Queue<Env<AttrContext>> flow(java.util.Queue<Env<AttrContext>> envs)
public java.util.Queue<Env<AttrContext>> flow(Env<AttrContext> env)
protected void flow(Env<AttrContext> env,
java.util.Queue<Env<AttrContext>> results)
public java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> desugar(java.util.Queue<Env<AttrContext>> envs)
protected void desugar(Env<AttrContext> env,
java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> results)
public void generate(java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue)
public void generate(java.util.Queue<Pair<Env<AttrContext>,JCTree.JCClassDecl>> queue,
java.util.Queue<JavaFileObject> results)
java.util.Map<JCTree.JCCompilationUnit,java.util.Queue<Env<AttrContext>>> groupByFile(java.util.Queue<Env<AttrContext>> envs)
JCTree.JCClassDecl removeMethodBodies(JCTree.JCClassDecl cdef)
public void reportDeferredDiagnostics()
public void close()
public void close(boolean disposeNames)
protected void printVerbose(java.lang.String key,
java.lang.Object arg)
key - The key to look up the correct internationalized string.arg - An argument for substitution into the output string.
protected void printCount(java.lang.String kind,
int count)
private static long now()
private static long elapsed(long then)
public void initRound(JavaCompiler prev)
public static void enableLogging()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||