public class Compiler extends AbstractCompiler implements ErrorHandler
Modifier and Type | Class and Description |
---|---|
static class |
Compiler.CodeBuilder
Stores a buffer of text to which more can be appended.
|
SourceExcerptProvider.ExcerptFormatter, SourceExcerptProvider.SourceExcerpt
Modifier and Type | Field and Description |
---|---|
static DiagnosticType |
MOTION_ITERATIONS_ERROR |
static DiagnosticType |
OPTIMIZE_LOOP_ERROR
Error strings used for reporting JSErrors
|
protected com.google.javascript.jscomp.RecentChange |
recentChange |
PerformanceTracker |
tracker |
Constructor and Description |
---|
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 a Compiler that reports errors and warnings to an output stream.
|
Modifier and Type | Method and Description |
---|---|
void |
addNewScript(JsAst ast)
Adds a new Script AST to the compile state.
|
SymbolTable |
buildKnownSymbolTable() |
void |
check() |
<T1 extends SourceFile,T2 extends SourceFile> |
compile(List<T1> externs,
List<T2> inputs,
CompilerOptions options)
Compiles a list of inputs.
|
Result |
compile(SourceFile extern,
SourceFile input,
CompilerOptions options) |
<T extends SourceFile> |
compileModules(List<T> externs,
List<JSModule> modules,
CompilerOptions options)
Compiles a list of modules.
|
protected Config |
createConfig(Config.LanguageMode mode) |
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.
|
List<Comment> |
getComments(String filename)
Returns all the comments from the given file.
|
protected DiagnosticGroups |
getDiagnosticGroups()
The warning classes that are available from the command-line, and
are suppressible 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 input id.
|
Map<InputId,CompilerInput> |
getInputsById()
Returns an unmodifiable view of the compiler inputs indexed by id.
|
double |
getProgress() |
static String |
getReleaseDate()
Returns the compiler date baked into the jar.
|
static String |
getReleaseVersion()
Returns the compiler version baked into the jar.
|
Result |
getResult()
Returns the result of the compilation.
|
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() |
com.google.debugging.sourcemap.proto.Mapping.OriginalMapping |
getSourceMapping(String sourceName,
int lineNumber,
int columnNumber)
If the source file is associated with an inputSourceMap, does a lookup
for the original file position based on this source map.
|
Region |
getSourceRegion(String sourceName,
int lineNumber)
Get a region around the indicated line number.
|
TypedScope |
getTopScope()
Gets the top scope.
|
com.google.javascript.jscomp.MemoizedScopeCreator |
getTypedScopeCreator()
Gets a memoized scope creator with type information.
|
TypeIRegistry |
getTypeIRegistry() |
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. |
<T1 extends SourceFile,T2 extends SourceFile> |
init(List<T1> externs,
List<T2> inputs,
CompilerOptions options)
Initializes the instance state needed for a compile job.
|
<T extends SourceFile> |
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)
Initializes the compiler options.
|
static String |
joinPathParts(String... pathParts)
Creates an OS specific path string from parts
|
protected CompilerOptions |
newCompilerOptions()
Allow subclasses to override the default CompileOptions object.
|
void |
normalize() |
void |
optimize() |
void |
parse() |
Node |
parse(SourceFile file) |
void |
printConfig(PrintStream printStream) |
void |
rebuildInputsFromModules()
Rebuilds the internal list of inputs by iterating over all modules.
|
protected void |
reconcileOptionsWithGuards()
When the CompilerOptions and its WarningsGuard overlap, reconcile
any discrepencies.
|
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(CheckLevel ignoredLevel,
JSError error) |
void |
report(JSError error)
Report an error or warning.
|
void |
reportCodeChange()
Report code changes.
|
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 |
setTimeout(int timeout)
Sets the timeout when Compiler is run in a thread
|
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 |
toSource(Node n)
Generates JavaScript source code for an AST, doesn't generate source
map info.
|
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.
|
void |
transpileAndDontCheck() |
void |
whitespaceOnlyPasses() |
public PerformanceTracker tracker
public static final DiagnosticType OPTIMIZE_LOOP_ERROR
public static final DiagnosticType MOTION_ITERATIONS_ERROR
protected final com.google.javascript.jscomp.RecentChange recentChange
public Compiler()
public Compiler(PrintStream stream)
public Compiler(ErrorManager errorManager)
public void setErrorManager(ErrorManager errorManager)
errorManager
- the error manager, it cannot be null
public void initOptions(CompilerOptions options)
public void printConfig(PrintStream printStream)
protected void reconcileOptionsWithGuards()
public <T1 extends SourceFile,T2 extends SourceFile> void init(List<T1> externs, List<T2> inputs, CompilerOptions options)
public <T extends SourceFile> void initModules(List<T> externs, List<JSModule> modules, CompilerOptions options)
public static String joinPathParts(String... pathParts)
public void rebuildInputsFromModules()
init(List, List, CompilerOptions)
call.public Result compile(SourceFile extern, SourceFile input, CompilerOptions options)
public <T1 extends SourceFile,T2 extends SourceFile> Result compile(List<T1> externs, List<T2> inputs, CompilerOptions options)
public <T extends SourceFile> Result compileModules(List<T> externs, List<JSModule> modules, CompilerOptions options)
public void disableThreads()
public void setTimeout(int timeout)
timeout
- seconds to wait before timeoutpublic void parse()
public void setPassConfig(PassConfig passes)
passes
- The PassConfig to use with this Compiler.NullPointerException
- if passes is nullIllegalStateException
- if this.passes has already been assignedpublic void whitespaceOnlyPasses()
public void transpileAndDontCheck()
public void check()
public Result getResult()
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 TypeIRegistry getTypeIRegistry()
getTypeIRegistry
in class AbstractCompiler
public JSTypeRegistry getTypeRegistry()
AbstractCompiler
getTypeRegistry
in class AbstractCompiler
public com.google.javascript.jscomp.MemoizedScopeCreator getTypedScopeCreator()
AbstractCompiler
public SymbolTable buildKnownSymbolTable()
public TypedScope getTopScope()
AbstractCompiler
getTopScope
in class AbstractCompiler
public ReverseAbstractInterpreter getReverseAbstractInterpreter()
AbstractCompiler
getReverseAbstractInterpreter
in class AbstractCompiler
public Node parse(SourceFile file)
protected CompilerOptions newCompilerOptions()
public String toSource()
toSource
in class AbstractCompiler
public String[] toSourceArray()
public String toSource(JSModule module)
public String[] toSourceArray(JSModule module)
public void toSource(Compiler.CodeBuilder cb, int inputSeqNum, Node root)
public String toSource(Node n)
toSource
in class AbstractCompiler
public void optimize()
public void normalize()
public void reportCodeChange()
AbstractCompiler
reportCodeChange
in class AbstractCompiler
public CodingConvention getCodingConvention()
AbstractCompiler
getCodingConvention
in class AbstractCompiler
protected Config createConfig(Config.LanguageMode mode)
protected DiagnosticGroups getDiagnosticGroups()
@suppress
annotation.public void report(JSError error)
AbstractCompiler
report
in class AbstractCompiler
public void report(CheckLevel ignoredLevel, JSError error)
report
in interface ErrorHandler
ignoredLevel
- the reporting levelerror
- the error to reportpublic 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.canContinueAfterErrors()
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 com.google.debugging.sourcemap.proto.Mapping.OriginalMapping getSourceMapping(String sourceName, int lineNumber, int columnNumber)
SourceExcerptProvider
getSourceMapping
in interface SourceExcerptProvider
public String getSourceLine(String sourceName, int lineNumber)
SourceExcerptProvider
getSourceLine
in interface SourceExcerptProvider
lineNumber
- the line number, 1 being the first line of the filenull
if it does not existpublic Region getSourceRegion(String sourceName, int lineNumber)
SourceExcerptProvider
getSourceRegion
in interface SourceExcerptProvider
lineNumber
- the line number, 1 being the first line of the filenull
if it does not existpublic 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 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@GwtIncompatible(value="java.util.ResourceBundle") public static String getReleaseVersion()
@GwtIncompatible(value="java.util.ResourceBundle") public static String getReleaseDate()
public List<Comment> getComments(String filename)
AbstractCompiler
Copyright © 2009-2016 Google. All Rights Reserved.