Package com.google.javascript.jscomp
Class CompilerInput
- java.lang.Object
-
- com.google.javascript.jscomp.CompilerInput
-
- All Implemented Interfaces:
DependencyInfo,SourceAst,java.io.Serializable
public class CompilerInput extends java.lang.Object implements SourceAst, DependencyInfo
A class for the internal representation of an input to the compiler. Wraps aSourceAstand maintain state such as module for the input and whether the input is an extern. Also calculates provided and required types.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CompilerInput(SourceAst ast)CompilerInput(SourceAst ast, boolean isExtern)CompilerInput(SourceAst ast, InputId inputId, boolean isExtern)CompilerInput(SourceAst ast, java.lang.String inputId, boolean isExtern)CompilerInput(SourceFile file)CompilerInput(SourceFile file, boolean isExtern)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearAst()Removes any references to root node of the AST.SourceAstgetAst()NodegetAstRoot(AbstractCompiler compiler)Gets the root node of the AST for the source file this represents.java.lang.StringgetCode()InputIdgetInputId()Returns a name for this input.java.lang.StringgetLine(int lineNumber)Gets the source line for the indicated line number.intgetLineOffset(int lineno)JSModulegetModule()Returns the module to which the input belongs.java.lang.StringgetName()Returns a name for this input.intgetNumLines()java.lang.StringgetPathRelativeToClosureBase()Gets the path relative to closure-base, if one is available.java.util.Collection<java.lang.String>getProvides()Gets a list of types provided by this input.RegiongetRegion(int lineNumber)Get a region around the indicated line number.java.util.Collection<java.lang.String>getRequires()Gets a list of types depended on by this input.SourceAstgetSourceAst()Returns the SourceAst object on which this input is based.SourceFilegetSourceFile()Returns the source file the generated AST represents.booleanisExtern()voidremoveRequire(java.lang.String require)voidsetCompiler(AbstractCompiler compiler)Sets an abstract compiler for doing parsing.voidsetModule(JSModule module)Sets the module to which the input belongs.voidsetSourceFile(SourceFile file)Sets the source file the generated AST represents.java.lang.StringtoString()
-
-
-
Constructor Detail
-
CompilerInput
public CompilerInput(SourceAst ast)
-
CompilerInput
public CompilerInput(SourceAst ast, boolean isExtern)
-
CompilerInput
public CompilerInput(SourceAst ast, java.lang.String inputId, boolean isExtern)
-
CompilerInput
public CompilerInput(SourceFile file)
-
CompilerInput
public CompilerInput(SourceFile file, boolean isExtern)
-
-
Method Detail
-
getInputId
public InputId getInputId()
Returns a name for this input. Must be unique across all inputs.- Specified by:
getInputIdin interfaceSourceAst- Returns:
- The input id associated with this AST
-
getName
public java.lang.String getName()
Returns a name for this input. Must be unique across all inputs.- Specified by:
getNamein interfaceDependencyInfo
-
getAst
public SourceAst getAst()
-
getPathRelativeToClosureBase
public java.lang.String getPathRelativeToClosureBase()
Gets the path relative to closure-base, if one is available.- Specified by:
getPathRelativeToClosureBasein interfaceDependencyInfo
-
getAstRoot
public Node getAstRoot(AbstractCompiler compiler)
Description copied from interface:SourceAstGets the root node of the AST for the source file this represents. The AST is lazily instantiated and cached.- Specified by:
getAstRootin interfaceSourceAst
-
clearAst
public void clearAst()
Description copied from interface:SourceAstRemoves 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.
-
getSourceFile
public SourceFile getSourceFile()
Description copied from interface:SourceAstReturns the source file the generated AST represents.- Specified by:
getSourceFilein interfaceSourceAst
-
setSourceFile
public void setSourceFile(SourceFile file)
Description copied from interface:SourceAstSets 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:
setSourceFilein interfaceSourceAst
-
getSourceAst
public SourceAst getSourceAst()
Returns the SourceAst object on which this input is based.
-
setCompiler
public void setCompiler(AbstractCompiler compiler)
Sets an abstract compiler for doing parsing.
-
getRequires
public java.util.Collection<java.lang.String> getRequires()
Gets a list of types depended on by this input.- Specified by:
getRequiresin interfaceDependencyInfo
-
getProvides
public java.util.Collection<java.lang.String> getProvides()
Gets a list of types provided by this input.- Specified by:
getProvidesin interfaceDependencyInfo
-
removeRequire
public void removeRequire(java.lang.String require)
-
getLine
public java.lang.String getLine(int lineNumber)
Gets the source line for the indicated line number.- Parameters:
lineNumber- the line number, 1 being the first line of the file.- Returns:
- The line indicated. Does not include the newline at the end
of the file. Returns
nullif it does not exist, or if there was an IO exception.
-
getRegion
public Region getRegion(int lineNumber)
Get a region around the indicated line number. The exact definition of a region is implementation specific, but it must contain the line indicated by the line number. A region must not start or end by a carriage return.- Parameters:
lineNumber- the line number, 1 being the first line of the file.- Returns:
- The line indicated. Returns
nullif it does not exist, or if there was an IO exception.
-
getCode
public java.lang.String getCode() throws java.io.IOException- Throws:
java.io.IOException
-
getModule
public JSModule getModule()
Returns the module to which the input belongs.
-
setModule
public void setModule(JSModule module)
Sets the module to which the input belongs.
-
isExtern
public boolean isExtern()
-
getLineOffset
public int getLineOffset(int lineno)
-
getNumLines
public int getNumLines()
- Returns:
- The number of lines in this input.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-