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(JSSourceFile file)
           
CompilerInput(JSSourceFile file, boolean isExtern)
           
CompilerInput(SourceAst ast)
           
CompilerInput(SourceAst ast, boolean isExtern)
           
CompilerInput(SourceAst ast, String inputName, boolean isExtern)
           
 
Method Summary
 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.
 String getCode()
           
 String getLine(int lineNumber)
          Gets the source line for the indicated line number.
 JSModule getModule()
          Returns the module to which the input belongs.
 String getName()
          Returns a name for this input.
 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 setCompiler(AbstractCompiler compiler)
          Sets an abstract compiler for doing parsing.
 void setErrorManager(ErrorManager errorManager)
          Sets an error manager for routing error messages.
 void setModule(JSModule module)
          Sets the module to which the input belongs.
 void setSourceFile(SourceFile file)
          Sets the source file the generated AST represents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompilerInput

public CompilerInput(SourceAst ast)

CompilerInput

public CompilerInput(SourceAst ast,
                     boolean isExtern)

CompilerInput

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

CompilerInput

public CompilerInput(JSSourceFile file)

CompilerInput

public CompilerInput(JSSourceFile file,
                     boolean isExtern)
Method Detail

getName

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

Specified by:
getName in interface DependencyInfo

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.


setErrorManager

public void setErrorManager(ErrorManager errorManager)
Sets an error manager for routing error messages.


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

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()