|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.javascript.jscomp.AbstractCompiler com.google.javascript.jscomp.Compiler
public class Compiler
Compiler (and the other classes in this package) does the following:
Nested Class Summary | |
---|---|
static class |
Compiler.CodeBuilder
Stores a buffer of text to which more can be appended. |
static class |
Compiler.IntermediateState
Stores the internal compiler state just before optimization is performed. |
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.SourceExcerptProvider |
---|
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt |
Field Summary | |
---|---|
static DiagnosticType |
MOTION_ITERATIONS_ERROR
|
static DiagnosticType |
OPTIMIZE_LOOP_ERROR
Error strings used for reporting JSErrors |
protected CodeChangeHandler.RecentChange |
recentChange
|
PerformanceTracker |
tracker
|
Constructor Summary | |
---|---|
Compiler()
Creates a Compiler that reports errors and warnings to its logger. |
|
Compiler(ErrorManager errorManager)
Creates a Compiler that uses a custom error manager. |
|
Compiler(PrintStream stream)
Creates n Compiler that reports errors and warnings to an output stream. |
Method Summary | ||
---|---|---|
boolean |
acceptConstKeyword()
|
|
boolean |
acceptEcmaScript5()
|
|
void |
addNewScript(JsAst ast)
Adds a new Script AST to the compile state. |
|
SymbolTable |
buildKnownSymbolTable()
|
|
void |
check()
|
|
Result |
compile(JSSourceFile[] externs,
JSModule[] modules,
CompilerOptions options)
Compiles a list of modules. |
|
Result |
compile(JSSourceFile[] externs,
JSSourceFile[] inputs,
CompilerOptions options)
Compiles a list of inputs. |
|
Result |
compile(JSSourceFile extern,
JSModule[] modules,
CompilerOptions options)
|
|
|
compile(List<T1> externs,
List<T2> inputs,
CompilerOptions options)
Compiles a list of inputs. |
|
Result |
compile(SourceFile extern,
JSSourceFile[] input,
CompilerOptions options)
|
|
Result |
compile(SourceFile extern,
SourceFile input,
CompilerOptions options)
|
|
|
compileModules(List<T> externs,
List<JSModule> modules,
CompilerOptions options)
Compiles a list of modules. |
|
void |
disableThreads()
Disable threads. |
|
String |
getAstDotGraph()
Gets the DOT graph of the AST generated at the end of compilation. |
|
CodingConvention |
getCodingConvention()
Gets the current coding convention. |
|
protected DiagnosticGroups |
getDiagnosticGroups()
The warning classes that are available from the command-line, and are suppressable by the @suppress annotation. |
|
int |
getErrorCount()
Gets the number of errors. |
|
CheckLevel |
getErrorLevel(JSError error)
|
|
ErrorManager |
getErrorManager()
Gets the error manager. |
|
JSError[] |
getErrors()
Returns the array of errors (never null). |
|
CompilerInput |
getInput(InputId id)
Looks up an input (possibly an externs input) by name. |
|
Map<InputId,CompilerInput> |
getInputsById()
Returns an unmodifiable view of the compiler inputs indexed by id. |
|
JSError[] |
getMessages()
Returns an array constructed from errors + temporary warnings. |
|
double |
getProgress()
|
|
Result |
getResult()
Returns the result of the compilation. |
|
com.google.javascript.jscomp.ReverseAbstractInterpreter |
getReverseAbstractInterpreter()
Get an interpreter for type analysis. |
|
Node |
getRoot()
Returns the root node of the AST, which includes both externs and source. |
|
String |
getSourceLine(String sourceName,
int lineNumber)
Get the line indicated by the line number. |
|
SourceMap |
getSourceMap()
|
|
Region |
getSourceRegion(String sourceName,
int lineNumber)
Get a region around the indicated line number. |
|
Compiler.IntermediateState |
getState()
Returns the current internal state, excluding the input files and modules. |
|
Scope |
getTopScope()
Gets the top scope. |
|
com.google.javascript.jscomp.MemoizedScopeCreator |
getTypedScopeCreator()
Gets a memoized scope creator with type information. |
|
JSTypeRegistry |
getTypeRegistry()
Gets a central registry of type information from the compiled JS. |
|
int |
getWarningCount()
Gets the number of warnings. |
|
JSError[] |
getWarnings()
Returns the array of warnings (never null). |
|
boolean |
hasErrors()
Consults the ErrorManager to see if we've encountered errors
that should halt compilation. |
|
void |
init(JSSourceFile[] externs,
JSModule[] modules,
CompilerOptions options)
Initializes the instance state needed for a compile job if the sources are in modules. |
|
void |
init(JSSourceFile[] externs,
JSSourceFile[] inputs,
CompilerOptions options)
Initializes the instance state needed for a compile job. |
|
|
init(List<T1> externs,
List<T2> inputs,
CompilerOptions options)
Initializes the instance state needed for a compile job. |
|
|
initModules(List<T> externs,
List<JSModule> modules,
CompilerOptions options)
Initializes the instance state needed for a compile job if the sources are in modules. |
|
void |
initOptions(CompilerOptions options)
Initialize the compiler options. |
|
boolean |
isIdeMode()
Returns true if compiling in IDE mode. |
|
boolean |
isTypeCheckingEnabled()
Returns true if type checking is enabled. |
|
CompilerOptions.LanguageMode |
languageMode()
|
|
protected CompilerOptions |
newCompilerOptions()
Allow subclasses to override the default CompileOptions object. |
|
CompilerInput |
newExternInput(String name)
Creates a new externs file. |
|
void |
normalize()
|
|
void |
optimize()
|
|
void |
parse()
|
|
Node |
parse(SourceFile file)
|
|
void |
processDefines()
Reprocesses the current defines over the AST. |
|
void |
rebuildInputsFromModules()
Rebuilds the internal list of inputs by iterating over all modules. |
|
protected void |
removeExternInput(InputId id)
Removes an input file from AST. |
|
void |
replaceScript(JsAst ast)
Replaces one file in a hot-swap mode. |
|
void |
report(JSError error)
Report an error or warning. |
|
void |
reportCodeChange()
All passes should call reportCodeChange() when they alter the JS tree structure. |
|
void |
setErrorManager(ErrorManager errorManager)
Sets the error manager. |
|
static void |
setLoggingLevel(Level level)
Sets the logging level for the com.google.javascript.jscomp package. |
|
void |
setPassConfig(PassConfig passes)
|
|
void |
setState(Compiler.IntermediateState state)
Sets the internal state to the capture given. |
|
String |
toSource()
Converts the main parse tree back to js code. |
|
void |
toSource(Compiler.CodeBuilder cb,
int inputSeqNum,
Node root)
Writes out js code from a root node. |
|
String |
toSource(JSModule module)
Converts the parse tree for a module back to js code. |
|
String[] |
toSourceArray()
Converts the parse tree for each input back to js code. |
|
String[] |
toSourceArray(JSModule module)
Converts the parse tree for each input in a module back to js code. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public PerformanceTracker tracker
public static final DiagnosticType OPTIMIZE_LOOP_ERROR
public static final DiagnosticType MOTION_ITERATIONS_ERROR
protected final CodeChangeHandler.RecentChange recentChange
Constructor Detail |
---|
public Compiler()
public Compiler(PrintStream stream)
public Compiler(ErrorManager errorManager)
Method Detail |
---|
public void setErrorManager(ErrorManager errorManager)
errorManager
- the error manager, it cannot be null
public void initOptions(CompilerOptions options)
public void init(JSSourceFile[] externs, JSSourceFile[] inputs, CompilerOptions options)
public <T1 extends SourceFile,T2 extends SourceFile> void init(List<T1> externs, List<T2> inputs, CompilerOptions options)
public void init(JSSourceFile[] externs, JSModule[] modules, CompilerOptions options)
public <T extends SourceFile> void initModules(List<T> externs, List<JSModule> modules, CompilerOptions options)
public void rebuildInputsFromModules()
init(JSSourceFile[], JSModule[], CompilerOptions)
call.
public Result compile(SourceFile extern, SourceFile input, CompilerOptions options)
public Result compile(SourceFile extern, JSSourceFile[] input, CompilerOptions options)
public Result compile(JSSourceFile extern, JSModule[] modules, CompilerOptions options)
public Result compile(JSSourceFile[] externs, JSSourceFile[] inputs, CompilerOptions options)
public <T1 extends SourceFile,T2 extends SourceFile> Result compile(List<T1> externs, List<T2> inputs, CompilerOptions options)
public Result compile(JSSourceFile[] externs, JSModule[] modules, CompilerOptions options)
public <T extends SourceFile> Result compileModules(List<T> externs, List<JSModule> modules, CompilerOptions options)
public void disableThreads()
public void parse()
public void setPassConfig(PassConfig passes)
passes
- The PassConfig to use with this Compiler.
NullPointerException
- if passes is null
IllegalStateException
- if this.passes has already been assignedpublic void check()
public Result getResult()
public JSError[] getMessages()
public JSError[] getErrors()
public JSError[] getWarnings()
public Node getRoot()
AbstractCompiler
public CompilerInput getInput(InputId id)
AbstractCompiler
getInput
in class AbstractCompiler
protected void removeExternInput(InputId id)
id
- The id of the input to be removed.public CompilerInput newExternInput(String name)
AbstractCompiler
name
- A name for the new externs file.public JSTypeRegistry getTypeRegistry()
AbstractCompiler
getTypeRegistry
in class AbstractCompiler
public com.google.javascript.jscomp.MemoizedScopeCreator getTypedScopeCreator()
AbstractCompiler
public SymbolTable buildKnownSymbolTable()
public Scope getTopScope()
AbstractCompiler
getTopScope
in class AbstractCompiler
public com.google.javascript.jscomp.ReverseAbstractInterpreter getReverseAbstractInterpreter()
AbstractCompiler
getReverseAbstractInterpreter
in class AbstractCompiler
public Node parse(SourceFile file)
protected CompilerOptions newCompilerOptions()
public String toSource()
public String[] toSourceArray()
public String toSource(JSModule module)
public String[] toSourceArray(JSModule module)
public void toSource(Compiler.CodeBuilder cb, int inputSeqNum, Node root)
public void optimize()
public void processDefines()
processDefines
and then optimize
to optimize the AST
specifically for that target.
public void normalize()
public void reportCodeChange()
reportCodeChange
in class AbstractCompiler
public CodingConvention getCodingConvention()
AbstractCompiler
getCodingConvention
in class AbstractCompiler
public boolean isIdeMode()
AbstractCompiler
public boolean acceptEcmaScript5()
public CompilerOptions.LanguageMode languageMode()
public boolean acceptConstKeyword()
public boolean isTypeCheckingEnabled()
AbstractCompiler
protected DiagnosticGroups getDiagnosticGroups()
@suppress
annotation.
public void report(JSError error)
AbstractCompiler
report
in class AbstractCompiler
public CheckLevel getErrorLevel(JSError error)
public int getErrorCount()
public int getWarningCount()
public boolean hasErrors()
ErrorManager
to see if we've encountered errors
that should halt compilation.
If CompilerOptions.ideMode
is true
, this function
always returns false
without consulting the error manager. The
error manager will continue to be told about new errors and warnings, but
the compiler will complete compilation of all inputs.
public String getSourceLine(String sourceName, int lineNumber)
SourceExcerptProvider
lineNumber
- the line number, 1 being the first line of the file
null
if it does not existpublic Region getSourceRegion(String sourceName, int lineNumber)
SourceExcerptProvider
lineNumber
- the line number, 1 being the first line of the file
null
if it does not exist
public SourceMap getSourceMap()
public static void setLoggingLevel(Level level)
public String getAstDotGraph() throws IOException
IOException
public ErrorManager getErrorManager()
AbstractCompiler
getErrorManager
in class AbstractCompiler
public Map<InputId,CompilerInput> getInputsById()
public Compiler.IntermediateState getState()
public void setState(Compiler.IntermediateState state)
public double getProgress()
getProgress
in class AbstractCompiler
public void replaceScript(JsAst ast)
ast
- the ast of the file that is being replacedpublic void addNewScript(JsAst ast)
ast
- the ast of the new file
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |