com.google.javascript.jscomp
Class JSModuleGraph

java.lang.Object
  extended by com.google.javascript.jscomp.JSModuleGraph

public class JSModuleGraph
extends Object

A JSModule dependency graph that assigns a depth to each module and can answer depth-related queries about them. For the purposes of this class, a module's depth is defined as the number of hops in the longest path from the module to a module with no dependencies.


Nested Class Summary
protected static class JSModuleGraph.ModuleDependenceException
           
 
Constructor Summary
JSModuleGraph(JSModule[] modulesInDepOrder)
          Creates a module graph from a list of modules in dependency order.
JSModuleGraph(List<JSModule> modulesInDepOrder)
          Creates a module graph from a list of modules in dependency order.
 
Method Summary
 void coalesceDuplicateFiles()
          Replaces any files that are found multiple times with a single instance in the closest parent module that is common to all modules where it appears.
 boolean dependsOn(JSModule src, JSModule m)
          Determines whether this module depends on a given module.
 JSModule getDeepestCommonDependencyInclusive(Collection<JSModule> modules)
          Returns the deepest common dependency of the given modules.
 JSModule getDeepestCommonDependencyInclusive(JSModule m1, JSModule m2)
          Finds the deepest common dependency of two modules, including the modules themselves.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSModuleGraph

public JSModuleGraph(JSModule[] modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.


JSModuleGraph

public JSModuleGraph(List<JSModule> modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.

Method Detail

dependsOn

public boolean dependsOn(JSModule src,
                         JSModule m)
Determines whether this module depends on a given module. Note that a module never depends on itself, as that dependency would be cyclic.


getDeepestCommonDependencyInclusive

public JSModule getDeepestCommonDependencyInclusive(JSModule m1,
                                                    JSModule m2)
Finds the deepest common dependency of two modules, including the modules themselves.

Parameters:
m1 - A module in this graph
m2 - A module in this graph
Returns:
The deepest common dep of m1 and m2, or null if they have no common dependencies

getDeepestCommonDependencyInclusive

public JSModule getDeepestCommonDependencyInclusive(Collection<JSModule> modules)
Returns the deepest common dependency of the given modules.


coalesceDuplicateFiles

public void coalesceDuplicateFiles()
Replaces any files that are found multiple times with a single instance in the closest parent module that is common to all modules where it appears. JSCompiler normally errors if you attempt to compile modules containing the same file. This method can be used to remove duplicates before compiling to avoid such an error.