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 aSourceAst
and 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 void
clearAst()
Removes any references to root node of the AST.SourceAst
getAst()
Node
getAstRoot(AbstractCompiler compiler)
Gets the root node of the AST for the source file this represents.java.lang.String
getCode()
InputId
getInputId()
Returns a name for this input.java.lang.String
getLine(int lineNumber)
Gets the source line for the indicated line number.int
getLineOffset(int lineno)
JSModule
getModule()
Returns the module to which the input belongs.java.lang.String
getName()
Returns a name for this input.int
getNumLines()
java.lang.String
getPathRelativeToClosureBase()
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.Region
getRegion(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.SourceAst
getSourceAst()
Returns the SourceAst object on which this input is based.SourceFile
getSourceFile()
Returns the source file the generated AST represents.boolean
isExtern()
void
removeRequire(java.lang.String require)
void
setCompiler(AbstractCompiler compiler)
Sets an abstract compiler for doing parsing.void
setModule(JSModule module)
Sets the module to which the input belongs.void
setSourceFile(SourceFile file)
Sets the source file the generated AST represents.java.lang.String
toString()
-
-
-
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:
getInputId
in 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:
getName
in interfaceDependencyInfo
-
getAst
public SourceAst getAst()
-
getPathRelativeToClosureBase
public java.lang.String getPathRelativeToClosureBase()
Gets the path relative to closure-base, if one is available.- Specified by:
getPathRelativeToClosureBase
in interfaceDependencyInfo
-
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.- 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
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
-
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:
getRequires
in interfaceDependencyInfo
-
getProvides
public java.util.Collection<java.lang.String> getProvides()
Gets a list of types provided by this input.- Specified by:
getProvides
in 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
null
if 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
null
if 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:
toString
in classjava.lang.Object
-
-