com.google.javascript.jscomp
Class CompilerInput

java.lang.Object
  extended by com.google.javascript.jscomp.CompilerInput
All Implemented Interfaces:
DependencyInfo, SourceAst, Serializable

public class CompilerInput
extends Object
implements SourceAst, DependencyInfo

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:
Serialized Form

Constructor Summary
CompilerInput(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
 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.
 String getCode()
           
 InputId getInputId()
          Returns a name for this input.
 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.
 String getName()
          Returns a name for this input.
 int getNumLines()
           
 String getPathRelativeToClosureBase()
          Gets the path relative to closure-base, if one is available.
 Collection<String> getProvides()
          Gets a list of types provided by this input.
 Region getRegion(int lineNumber)
          Get a region around the indicated line number.
 Collection<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(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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompilerInput

public CompilerInput(SourceAst ast)

CompilerInput

public CompilerInput(SourceAst ast,
                     boolean isExtern)

CompilerInput

public CompilerInput(SourceAst ast,
                     String inputId,
                     boolean isExtern)

CompilerInput

public CompilerInput(SourceAst ast,
                     InputId 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 interface SourceAst
Returns:
The input id associated with this AST

getName

public String getName()
Returns a name for this input. Must be unique across all inputs.

Specified by:
getName in interface DependencyInfo

getAst

public SourceAst getAst()

getPathRelativeToClosureBase

public String getPathRelativeToClosureBase()
Gets the path relative to closure-base, if one is available.

Specified by:
getPathRelativeToClosureBase in interface DependencyInfo

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 interface SourceAst

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.

Specified by:
clearAst in interface SourceAst

getSourceFile

public SourceFile getSourceFile()
Description copied from interface: SourceAst
Returns the source file the generated AST represents.

Specified by:
getSourceFile in interface SourceAst

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 interface SourceAst

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 Collection<String> getRequires()
Gets a list of types depended on by this input.

Specified by:
getRequires in interface DependencyInfo

getProvides

public Collection<String> getProvides()
Gets a list of types provided by this input.

Specified by:
getProvides in interface DependencyInfo

removeRequire

public void removeRequire(String require)

getLine

public 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 String getCode()
               throws IOException
Throws:
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 String toString()
Overrides:
toString in class Object