Package com.google.javascript.jscomp
Class CompilerInput
- java.lang.Object
-
- com.google.javascript.jscomp.deps.DependencyInfo.Base
-
- com.google.javascript.jscomp.CompilerInput
-
- All Implemented Interfaces:
DependencyInfo,SourceAst,java.io.Serializable
public class CompilerInput extends DependencyInfo.Base implements SourceAst
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCompilerInput.ModuleTypeJavaScript module type.-
Nested classes/interfaces inherited from interface com.google.javascript.jscomp.deps.DependencyInfo
DependencyInfo.Base, DependencyInfo.Require, DependencyInfo.Util
-
-
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 booleanaddDynamicRequire(java.lang.String require)Registers a type that this input depends on in the order seen in the file.booleanaddOrderedRequire(DependencyInfo.Require require)Registers a type that this input depends on in the order seen in the file.voidaddProvide(java.lang.String provide)Registers a type that this input defines.voidaddRequire(DependencyInfo.Require require)Registers a type that this input depends on.voidclearAst()Removes any references to root node of the AST.NodegetAstRoot(AbstractCompiler compiler)Gets the root node of the AST for the source file this represents.java.lang.StringgetCode()com.google.common.collect.ImmutableList<java.lang.String>getDynamicRequires()Returns the types that this input dynamically depends on in the order seen in the file.booleangetHasExternsAnnotation()Whether the file '@externs' annotation.booleangetHasNoCompileAnnotation()Whether the file has the '@nocompile' annotation.InputIdgetInputId()Returns a name for this input.CompilerInput.ModuleTypegetJsModuleType()intgetLineOffset(int lineno)com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String>getLoadFlags()Gets the loading information for this file.JSModulegetModule()Returns the module to which the input belongs.java.lang.StringgetName()Returns a name for this input.intgetNumLines()ModuleLoader.ModulePathgetPath()java.lang.StringgetPathRelativeToClosureBase()Gets the path relative to closure-base, if one is available.com.google.common.collect.ImmutableList<java.lang.String>getProvides()Gets a list of types provided by this input.com.google.common.collect.ImmutableList<DependencyInfo.Require>getRequires()Gets a list of types depended on by this input.SourceFilegetSourceFile()Returns the source file the generated AST represents.com.google.common.collect.ImmutableList<java.lang.String>getTypeRequires()Gets the symbols type-required by this file (i.e.booleanisExtern()voidsetCompiler(AbstractCompiler compiler)Sets an abstract compiler for doing parsing.voidsetHasFullParseDependencyInfo(boolean hasFullParseDependencyInfo)voidsetJsModuleType(CompilerInput.ModuleType moduleType)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()-
Methods inherited from class com.google.javascript.jscomp.deps.DependencyInfo.Base
getRequiredSymbols, isModule
-
-
-
-
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
-
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. This node is always non-null, even in the case of parse errors.- 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
-
setCompiler
public void setCompiler(AbstractCompiler compiler)
Sets an abstract compiler for doing parsing.
-
getRequires
public com.google.common.collect.ImmutableList<DependencyInfo.Require> getRequires()
Gets a list of types depended on by this input.- Specified by:
getRequiresin interfaceDependencyInfo
-
getTypeRequires
public com.google.common.collect.ImmutableList<java.lang.String> getTypeRequires()
Description copied from interface:DependencyInfoGets the symbols type-required by this file (i.e. for typechecking only).- Specified by:
getTypeRequiresin interfaceDependencyInfo
-
getProvides
public com.google.common.collect.ImmutableList<java.lang.String> getProvides()
Gets a list of types provided by this input.- Specified by:
getProvidesin interfaceDependencyInfo
-
getHasExternsAnnotation
public boolean getHasExternsAnnotation()
Description copied from interface:DependencyInfoWhether the file '@externs' annotation.- Specified by:
getHasExternsAnnotationin interfaceDependencyInfo
-
getHasNoCompileAnnotation
public boolean getHasNoCompileAnnotation()
Description copied from interface:DependencyInfoWhether the file has the '@nocompile' annotation.- Specified by:
getHasNoCompileAnnotationin interfaceDependencyInfo
-
addProvide
public void addProvide(java.lang.String provide)
Registers a type that this input defines. Includes both explicitly declared namespaces via goog.provide and goog.module calls as well as implicit namespaces provided by module rewriting.
-
addOrderedRequire
public boolean addOrderedRequire(DependencyInfo.Require require)
Registers a type that this input depends on in the order seen in the file.
-
getDynamicRequires
public com.google.common.collect.ImmutableList<java.lang.String> getDynamicRequires()
Returns the types that this input dynamically depends on in the order seen in the file. The returned types were loaded dynamically so while they are part of the dependency graph, they do not need sorted before this input.
-
addDynamicRequire
public boolean addDynamicRequire(java.lang.String require)
Registers a type that this input depends on in the order seen in the file. The type was loaded dynamically so while it is part of the dependency graph, it does not need sorted before this input.
-
setHasFullParseDependencyInfo
public void setHasFullParseDependencyInfo(boolean hasFullParseDependencyInfo)
-
getJsModuleType
public CompilerInput.ModuleType getJsModuleType()
-
setJsModuleType
public void setJsModuleType(CompilerInput.ModuleType moduleType)
-
addRequire
public void addRequire(DependencyInfo.Require require)
Registers a type that this input depends on.
-
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
-
getLoadFlags
public com.google.common.collect.ImmutableMap<java.lang.String,java.lang.String> getLoadFlags()
Description copied from interface:DependencyInfoGets the loading information for this file.- Specified by:
getLoadFlagsin interfaceDependencyInfo
-
getPath
public ModuleLoader.ModulePath getPath()
-
-