Package com.google.javascript.jscomp
Class CompilerInput
java.lang.Object
com.google.javascript.jscomp.CompilerInput
- All Implemented Interfaces:
DependencyInfo
,SourceAst
,Serializable
A class for the internal representation of an input to the compiler.
Wraps a
SourceAst
and maintain state such as module for the input and
whether the input is an extern. Also calculates provided and required types.- See Also:
-
Constructor Summary
ConstructorDescriptionCompilerInput
(SourceAst ast) CompilerInput
(SourceAst ast, boolean isExtern) CompilerInput
(SourceAst ast, InputId inputId, boolean isExtern) CompilerInput
(SourceAst ast, String inputId, boolean isExtern) CompilerInput
(SourceFile file) CompilerInput
(SourceFile file, boolean isExtern) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clearAst()
Removes any references to root node of the AST.getAst()
getAstRoot
(AbstractCompiler compiler) Gets the root node of the AST for the source file this represents.getCode()
Returns a name for this input.getLine
(int lineNumber) Gets the source line for the indicated line number.int
getLineOffset
(int lineno) Returns the module to which the input belongs.getName()
Returns a name for this input.int
Gets the path relative to closure-base, if one is available.Gets a list of types provided by this input.getRegion
(int lineNumber) Get a region around the indicated line number.Gets a list of types depended on by this input.Returns the SourceAst object on which this input is based.Returns the source file the generated AST represents.boolean
isExtern()
void
removeRequire
(String require) void
setCompiler
(AbstractCompiler compiler) Sets an abstract compiler for doing parsing.void
Sets the module to which the input belongs.void
setSourceFile
(SourceFile file) Sets the source file the generated AST represents.toString()
-
Constructor Details
-
CompilerInput
-
CompilerInput
-
CompilerInput
-
CompilerInput
-
CompilerInput
-
CompilerInput
-
-
Method Details
-
getInputId
Returns a name for this input. Must be unique across all inputs.- Specified by:
getInputId
in interfaceSourceAst
- Returns:
- The input id associated with this AST
-
getName
Returns a name for this input. Must be unique across all inputs.- Specified by:
getName
in interfaceDependencyInfo
-
getAst
-
getPathRelativeToClosureBase
Gets the path relative to closure-base, if one is available.- Specified by:
getPathRelativeToClosureBase
in interfaceDependencyInfo
-
getAstRoot
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.- 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. -
getSourceFile
Description copied from interface:SourceAst
Returns the source file the generated AST represents.- Specified by:
getSourceFile
in interfaceSourceAst
-
setSourceFile
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
-
getSourceAst
Returns the SourceAst object on which this input is based. -
setCompiler
Sets an abstract compiler for doing parsing. -
getRequires
Gets a list of types depended on by this input.- Specified by:
getRequires
in interfaceDependencyInfo
-
getProvides
Gets a list of types provided by this input.- Specified by:
getProvides
in interfaceDependencyInfo
-
removeRequire
-
getLine
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
null
if it does not exist, or if there was an IO exception.
-
getRegion
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
null
if it does not exist, or if there was an IO exception.
-
getCode
- Throws:
IOException
-
getModule
Returns the module to which the input belongs. -
setModule
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
-