## com.google.javascript.jscomp
Class JSModule

    java.lang.Object
      com.google.javascript.jscomp.JSModule

All Implemented Interfaces:
  DependencyInfo, Serializable

    public class JSModule

extends Object
implements DependencyInfo, Serializable

A JavaScript module has a unique name, consists of a list of compiler inputs, and can depend on other modules.

See Also:
  Serialized Form

Constructor Summary
`JSModule(String name)` Creates an instance.

Method Summary
`void` | `add(CompilerInput input)` Adds a source code input to this module.
`void` | `add(SourceFile file)` Adds a source file input to this module.
`void` | `addAfter(CompilerInput input, CompilerInput other)` Adds a source code input to this module directly after other.
`void` | `addDependency(JSModule dep)` Adds a dependency on another module.
`void` | `addFirst(CompilerInput input)` Adds a source code input to this module.
`void` | `addFirst(SourceFile file)` Adds a source file input to this module.
`void` | `clearAsts()` Removes any references to nodes of the AST.
`Set<JSModule>` | `getAllDependencies()` Returns the transitive closure of dependencies starting from the dependencies of this module.
`CompilerInput` | `getByName(String name)` Returns the input with the given name or null if none.
`List<JSModule>` | `getDependencies()` Gets the list of modules that this module depends on.
`int` | `getDepth()`
`List<CompilerInput>` | `getInputs()` Gets this module's list of source code inputs.
`String` | `getName()` Gets the module name.
`String` | `getPathRelativeToClosureBase()` Gets the path of this file relative to Closure's base.js file.
`List<String>` | `getProvides()` Gets the symbols provided by this file.
`List<String>` | `getRequires()` Gets the symbols required by this file.
`Set<JSModule>` | `getThisAndAllDependencies()` Returns this module and all of its dependencies in one list.
`void` | `remove(CompilerInput input)` Removes an input from this module.
`void` | `removeAll()` Removes all of the inputs from this module.
`boolean` | `removeByName(String name)` Removes any input with the given name.
`void` | `setDepth(int dep)`
`void` | `sortInputsByDeps(Compiler compiler)` Puts the JS files into a topologically sorted order by their dependencies.
`static JSModule[]` | `sortJsModules(Collection<JSModule> modules)` Returns the given collection of modules in topological order.
`String` | `toString()` Returns the module name (primarily for debugging).

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### JSModule

    public JSModule(String name)

  Creates an instance.

  Parameters:
    `name` - A unique name for the module

Method Detail

### getName

    public String getName()

  Gets the module name.

  Specified by:
    `getName` in interface `DependencyInfo`

### getProvides

    public List<String> getProvides()

  Description copied from interface: `DependencyInfo`
  Gets the symbols provided by this file.

  Specified by:
    `getProvides` in interface `DependencyInfo`

### getRequires

    public List<String> getRequires()

  Description copied from interface: `DependencyInfo`
  Gets the symbols required by this file.

  Specified by:
    `getRequires` in interface `DependencyInfo`

### getPathRelativeToClosureBase

    public String getPathRelativeToClosureBase()

  Description copied from interface: `DependencyInfo`
  Gets the path of this file relative to Closure's base.js file.

  Specified by:
    `getPathRelativeToClosureBase` in interface `DependencyInfo`

### add

    public void add(SourceFile file)

  Adds a source file input to this module.

### addFirst

    public void addFirst(SourceFile file)

  Adds a source file input to this module.

### add

    public void add(CompilerInput input)

  Adds a source code input to this module.

### addFirst

    public void addFirst(CompilerInput input)

  Adds a source code input to this module.

### addAfter

    public void addAfter(CompilerInput input,
                         CompilerInput other)

  Adds a source code input to this module directly after other.

### addDependency

    public void addDependency(JSModule dep)

  Adds a dependency on another module.

### remove

    public void remove(CompilerInput input)

  Removes an input from this module.

### removeAll

    public void removeAll()

  Removes all of the inputs from this module.

### getDependencies

    public List<JSModule> getDependencies()

  Gets the list of modules that this module depends on.

  Returns:
    A list that may be empty but not null

### getAllDependencies

    public Set<JSModule> getAllDependencies()

  Returns the transitive closure of dependencies starting from the dependencies of this module.

### getThisAndAllDependencies

    public Set<JSModule> getThisAndAllDependencies()

  Returns this module and all of its dependencies in one list.

### getInputs

    public List<CompilerInput> getInputs()

  Gets this module's list of source code inputs.

  Returns:
    A list that may be empty but not null

### getByName

    public CompilerInput getByName(String name)

  Returns the input with the given name or null if none.

### removeByName

    public boolean removeByName(String name)

  Removes any input with the given name. Returns whether any were removed.

### toString

    public String toString()

  Returns the module name (primarily for debugging).

  Overrides:
    `toString` in class `Object`

### clearAsts

    public void clearAsts()

  Removes any references to nodes of the AST. This method is needed to allow the ASTs to be garbage collected if the modules are kept around.

### sortInputsByDeps

    public void sortInputsByDeps(Compiler compiler)

  Puts the JS files into a topologically sorted order by their dependencies.

### sortJsModules

    public static JSModule[] sortJsModules(Collection<JSModule> modules)
                                    throws SortedDependencies.CircularDependencyException

  Returns the given collection of modules in topological order. Note that this will return the modules in the same order if they are already sorted, and in general, will only change the order as necessary to satisfy the ordering dependencies. This can be important for cases where the modules do not properly specify all dependencies.

  Throws:
    `SortedDependencies.CircularDependencyException`

### setDepth

    public void setDepth(int dep)

  Parameters:
    `dep` - the depth to set

### getDepth

    public int getDepth()

  Returns:
    the depth