Package com.google.javascript.jscomp
Class RecoverableJsAst
- java.lang.Object
-
- com.google.javascript.jscomp.RecoverableJsAst
-
- All Implemented Interfaces:
SourceAst
,java.io.Serializable
public class RecoverableJsAst extends java.lang.Object implements SourceAst
An implementation ofSourceAst
that avoids re-creating the AST unless it was manually cleared. This creates a single defensive copy of the AST; however, it is not safe for multiple compilations to use this simultaneously, as all compilations mutate this. Since this class copies the tree, you instead should create a central RecoverableJsAst that does the caching across compilations, and create new RecoverableJsAst's that act as copying proxies around the original.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description RecoverableJsAst(SourceAst realSource, boolean reportParseErrors)
Wraps around an existing SourceAst that provides caching between compilations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearAst()
Removes any references to root node of the AST.Node
getAstRoot(AbstractCompiler compiler)
Gets the root node of the AST for the source file this represents.InputId
getInputId()
SourceFile
getSourceFile()
Returns the source file the generated AST represents.void
setSourceFile(SourceFile file)
Sets the source file the generated AST represents.
-
-
-
Constructor Detail
-
RecoverableJsAst
public RecoverableJsAst(SourceAst realSource, boolean reportParseErrors)
Wraps around an existing SourceAst that provides caching between compilations.
-
-
Method Detail
-
getAstRoot
public Node getAstRoot(AbstractCompiler compiler)
Description copied from interface:SourceAst
Gets the root node of the AST for the source file this represents. The AST is lazily instantiated and cached. This node is always non-null, even in the case of parse errors.- Specified by:
getAstRoot
in interfaceSourceAst
-
clearAst
public void clearAst()
Description copied from interface:SourceAst
Removes any references to root node of the AST. If it is requested again, another parse will be performed. This method is needed to allow the ASTs to be garbage collected if the inputs are still around after compilation.
-
getInputId
public InputId getInputId()
- Specified by:
getInputId
in interfaceSourceAst
- Returns:
- The input id associated with this AST
-
getSourceFile
public SourceFile getSourceFile()
Description copied from interface:SourceAst
Returns the source file the generated AST represents.- Specified by:
getSourceFile
in interfaceSourceAst
-
setSourceFile
public void setSourceFile(SourceFile file)
Description copied from interface:SourceAst
Sets the source file the generated AST represents. This can be called after deserializing if access to the source file is needed. If a different file is provided than that with which this was created, an IllegalStateException will be thrown.- Specified by:
setSourceFile
in interfaceSourceAst
-
-