APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.main

public Class JavaCompiler

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.tools.javac.api.JavacTaskPool.ReusableContext.ReusableJavaCompiler
Imports
java.io.*, java.nio.file.FileSystemNotFoundException, .InvalidPathException, .ReadOnlyFileSystemException, java.util.Collection, .Comparator, .EnumSet, .HashMap, .HashSet, .LinkedHashMap, .LinkedHashSet, .Map, .MissingResourceException, .Queue, .ResourceBundle, .Set, java.util.function.Function, .ToIntFunction, javax.annotation.processing.Processor, javax.lang.model.SourceVersion, javax.lang.model.element.ElementVisitor, javax.tools.DiagnosticListener, .JavaFileManager, .JavaFileObject, .JavaFileObject.Kind, .StandardLocation, com.sun.source.util.TaskEvent, com.sun.tools.javac.api.MultiTaskListener, com.sun.tools.javac.code.*, .Lint.LintCategory, .Source.Feature, .Symbol.ClassSymbol, .Symbol.CompletionFailure, .Symbol.ModuleSymbol, .Symbol.PackageSymbol, com.sun.tools.javac.comp.*, .CompileStates.CompileState, com.sun.tools.javac.file.JavacFileManager, com.sun.tools.javac.jvm.*, com.sun.tools.javac.parser.*, com.sun.tools.javac.platform.PlatformDescription, com.sun.tools.javac.processing.*, com.sun.tools.javac.tree.*, .JCTree.JCClassDecl, .JCTree.JCCompilationUnit, .JCTree.JCExpression, .JCTree.JCLambda, .JCTree.JCMemberReference, .JCTree.JCMethodDecl, .JCTree.JCVariableDecl, .JCTree.JCBindingPattern, .JCTree.JCInstanceOf, .JCTree.JCModuleDecl, .JCTree.JCRecordPattern, .JCTree.JCSwitch, .JCTree.JCSwitchExpression, com.sun.tools.javac.util.*, .Context.Key, .DefinedBy.Api, .JCDiagnostic.Factory, .Log.DiagnosticHandler, .Log.DiscardDiagnosticHandler, .Log.WriterKind, com.sun.tools.javac.resources.CompilerProperties.Errors, .CompilerProperties.Fragments, .CompilerProperties.Notes, .CompilerProperties.Warnings

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 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static enum
JavaCompiler.CompilePolicy

Control how the compiler's latter phases (attr, flow, desugar, generate) are connected.

protected static enum
public static class
public static interface

Field Summary

Modifier and TypeField and Description
protected Analyzer
analyzer

The analyzer

protected Annotate
annotate

The annotation annotator.

protected boolean
annotationProcessingOccurred

Flag set if any annotation processing occurred.

protected Attr
attr

The attributor.

protected Check
chk

The attributor.

public 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

public static final Context.Key<JavaCompiler>
compilerKey

The context key for the compiler.

protected CompileStates
protected final Name
completionFailureName

Force a completion failure on this name

protected Context
protected DeferredCompletionFailureHandler
private static final JavaCompiler.CompilePolicy
pack-priv Log.DeferredDiagnosticHandler
pack-priv HashMap<Env<AttrContext>, Queue<Pair<Env<AttrContext>, JCTree.JCClassDecl>>>
protected boolean
devVerbose

Switch: should we debug ignored exceptions

pack-priv JCDiagnostic.Factory
diagFactory

Factory for creating diagnostic objects

protected JCDiagnostic.Factory
diags

The diagnostics factory

public long
protected Enter
enter

The module for the symbol table entry phases.

private boolean
protected boolean
explicitAnnotationProcessingRequested

Switch: is annotation processing requested explicitly via CompilationTask.setProcessors?

protected JavaFileManager
fileManager

Access to file objects.

protected ClassFinder
finder

The class finder.

protected Flow
flow

The flow analyzer.

protected Gen
gen

The module for code generation.

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 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.

public boolean
public boolean
lineDebugInfo

Generate code with the LineNumberTable attribute for debugging

protected LintMapper
lintMapper

The Lint mapper.

public 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 ModuleFinder
moduleFinder

The module finder

protected Modules
modules

The modules visitor

protected Names
names

The name table.

protected Options
options

Command line options.

protected ParserFactory
parserFactory

Factory for parsers.

private JavacProcessingEnvironment
procEnvImpl

Object to handle annotation processing.

pack-priv 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.

private List<JCTree.JCClassDecl>
rootClasses

The list of classes explicitly supplied on the command line for compilation.

public CompileStates.CompileState
shouldStopPolicyIfError

Policy of how far to continue compilation after errors have occurred.

public CompileStates.CompileState
shouldStopPolicyIfNoError

Policy of how far to continue compilation when no errors have occurred.

private final Symbol
silentFail

Used by the resolveBinaryNameOrIdent to say that the given type cannot be found, and that an error has already been produced about that.

protected Source
source

The language version.

protected final Symbol.Completer
sourceCompleter

SourceCompleter that delegates to the readSourceFile method of this class.

public boolean
sourceOutput

Emit plain Java source files rather than class files.

private long
protected Symtab
syms

The symbol table.

protected MultiTaskListener
taskListener

Broadcasting listener for progress events

public Todo
todo

A queue of all as yet unattributed classes.

protected TransTypes
transTypes

The type eraser.

protected Types
types

Type utilities.

public boolean
verbose

Verbose output.

public boolean
verboseCompilePolicy

Report activity related to compilePolicy

private static ResourceBundle
private static final String
protected WarningAnalyzer
warningAnalyzer

The warning analyzer.

protected EnumSet<Lint.LintCategory>
werrorLint

Switch: treat lint warnings in the specified LintCategorys as errors.

protected boolean
werrorNonLint

Switch: treat non-lint warnings as errors.

protected ClassWriter
writer

The class writer.

Constructor Summary

AccessConstructor and Description
public
JavaCompiler(Context context)

Construct a new compiler using a shared context.

Method Summary

Modifier and TypeMethod and Description
public Queue<Env<AttrContext>>

Returns:

a list of environments for attribute classes.
attribute
(Queue<Env<AttrContext>> envs)

Attribute a list of parse trees, such as found on the "todo" list.

public Env<AttrContext>

Returns:

the attributed parse tree
attribute
(Env<AttrContext> env)

Attribute a parse tree.

protected void
public void
close()

Close the compiler, flushing the logs

public void
compile(List<JavaFileObject> sourceFileObject)

public void
compile(Collection<JavaFileObject>
file objects to be compiled
sourceFileObjects
,
Collection<String>
class names to process for annotations
classnames
,
Iterable<? extends Processor>
user provided annotation processors to bypass discovery, null means that no processors were provided
processors
,
Collection<String>
additional root modules to be used during module resolution.
addModules
)

Main method: compile a list of files, return all compiled classes

public boolean
continueAfterProcessAnnotations()

Returns true iff the compilation will continue after annotation processing is done.

public Queue<Pair<Env<AttrContext>, JCTree.JCClassDecl>>

Returns:

a list containing the classes to be generated
desugar
(Queue<Env<AttrContext>> envs)

Prepare attributed parse trees, in conjunction with their attribution contexts, for source or code generation.

protected void
desugar(final 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.

private static long
elapsed(long then)

public void
public List<JCTree.JCCompilationUnit>
enterTrees(List<JCTree.JCCompilationUnit> roots)

Enter the symbols found in a list of parse trees.

public int
errorCount()

The number of errors reported so far.

pack-priv boolean
pack-priv static boolean
private Name
public Queue<Env<AttrContext>>

Returns:

the list of attributed parse trees
flow
(Queue<Env<AttrContext>> envs)

Perform dataflow checks on attributed parse trees.

public 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.

public static String
fullVersion()

The current full version number as a string.

pack-priv JavaFileObject
genCode(Env<AttrContext>
The attribution environment of the outermost class containing this class.
env
,
JCTree.JCClassDecl
The class definition from which code is generated.
cdef
)

Generate code and emit a class file for a given class

public void
generate(Queue<Pair<Env<AttrContext>, JCTree.JCClassDecl>> queue)

Generates the source or class file for a list of classes.

public void
pack-priv Map<JCTree.JCCompilationUnit, Queue<Env<AttrContext>>>
public List<JCTree.JCCompilationUnit>
public void
initProcessAnnotations(Iterable<? extends Processor>
user provided annotation processors to bypass discovery, null means that no processors were provided
processors
,
Collection<? extends JavaFileObject> initialFiles, Collection<String> initialClassNames)

Check if we should process annotations.

public static JavaCompiler
instance(Context context)

Get the JavaCompiler instance for this context.

public boolean
public boolean
isWerror(Lint.LintCategory lc)

Should warnings in the given lint category be treated as errors due to a -Werror flag?

protected boolean
private TaskEvent
public void
private static long
now()

protected JCTree.JCCompilationUnit
parse(JavaFileObject
The name of the file from which input stream comes.
filename
,
CharSequence
The characters to be parsed.
content
)

Parse contents of input stream.

private JCTree.JCCompilationUnit
parse(JavaFileObject
The name of the file from which input stream comes.
filename
,
CharSequence
The characters to be parsed.
content
,
boolean
true if TaskListeners should not be notified
silent
)

Parse contents of input stream.

public JCTree.JCCompilationUnit
parse(String
The name of the file to be parsed.
filename
)
Deprecated

Parse contents of file.

public JCTree.JCCompilationUnit
parse(JavaFileObject
The name of the file to be parsed.
filename
)

Parse contents of file.

private Name
public List<JCTree.JCCompilationUnit>
parseFiles(Iterable<JavaFileObject> fileObjects)

Parses a list of files.

public List<JCTree.JCCompilationUnit>
parseFiles(Iterable<JavaFileObject> fileObjects, boolean force)

public void
printCount(String kind, int count)

Print numbers of errors and warnings.

protected void
pack-priv JavaFileObject
printSource(Env<AttrContext>
The attribution environment of the outermost class containing this class.
env
,
JCTree.JCClassDecl
The class definition to be printed.
cdef
)

Emit plain Java source for a class.

private void
printSuppressedCount(int shown, int suppressed, String diagKey)

public void
public void
processAnnotations(List<JCTree.JCCompilationUnit>
a list of compilation units
roots
,
Collection<String> classnames)

Process any annotations found in the specified compilation units.

private Name
public CharSequence
readSource(JavaFileObject
The file name of the input stream to be opened.
filename
)

Try to open input stream with given name.

private void
readSourceFile(Symbol.ClassSymbol
The class the source file of which needs to be compiled.
c
)

Compile a source file that has been accessed by the class finder.

public void
readSourceFile(JCTree.JCCompilationUnit
the compilation unit in which the given ClassSymbol resides, or null if should be parsed from source
tree
,
Symbol.ClassSymbol
the ClassSymbol to complete
c
)

Compile a ClassSymbol from source, optionally using the given compilation unit as the source tree.

pack-priv JCTree.JCClassDecl
public void
public void
public Symbol
resolveBinaryNameOrIdent(String
The name to resolve
name
)

Resolve an identifier which may be the binary name of a class or the Java name of a class or package.

public Symbol
resolveBinaryNameOrIdent(Symbol.ModuleSymbol
The module in which the search should be performed
msym
,
String
The name to resolve
name
)

Resolve an identifier which may be the binary name of a class or the Java name of a class or package.

public Symbol
resolveIdent(Symbol.ModuleSymbol
The module in which the search should be performed
msym
,
String
The identifier to resolve
name
)

Resolve an identifier.

public void
protected boolean
protected final <T> Queue<T>
protected final <T> List<T>
private boolean
public static String
version()

The current version number as a string.

private static String
public Queue<Env<AttrContext>>

Returns:

the list of attributed parse trees
warn
(Queue<Env<AttrContext>> envs)

Check for various things to warn about.

public Queue<Env<AttrContext>>
warn(Env<AttrContext> env)

Check for various things to warn about in an attributed parse tree.

protected void
warn(Env<AttrContext> env, Queue<Env<AttrContext>> results)

Check for various things to warn about in an attributed parse tree.

public int
warningCount()

The number of warnings reported so far.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait