public final class JSModuleGraph
extends java.lang.Object
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 (non cyclic)
path from the module to a module with no dependencies.Modifier and Type | Class and Description |
---|---|
private static class |
JSModuleGraph.InverseDepthComparator
A module depth comparator that considers a deeper module to be "less than"
a shallower module.
|
static class |
JSModuleGraph.MissingModuleException
Another exception class
|
protected static class |
JSModuleGraph.ModuleDependenceException
Exception class for declaring when the modules being fed into a
JSModuleGraph as input aren't in dependence order, and so can't be
processed for caching of various dependency-related queries.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<JSModule,java.util.Set<JSModule>> |
dependencyMap
dependencyMap is a cache of dependencies that makes the dependsOn
function faster.
|
private java.util.List<JSModule> |
modules |
private java.util.List<java.util.List<JSModule>> |
modulesByDepth
Lists of modules at each depth.
|
Constructor and Description |
---|
JSModuleGraph(JSModule[] modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.
|
JSModuleGraph(java.util.List<JSModule> modulesInDepOrder)
Creates a module graph from a list of modules in dependency order.
|
Modifier and Type | Method and Description |
---|---|
private static void |
addDeps(java.util.Set<JSModule> deps,
JSModule m)
Adds a module's transitive dependencies to a set.
|
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.
|
private java.util.Collection<CompilerInput> |
createEntryPointInputs(DependencyOptions depOptions,
java.util.List<CompilerInput> inputs,
SortedDependencies<CompilerInput> sorter) |
boolean |
dependsOn(JSModule src,
JSModule m)
Determines whether this module depends on a given module.
|
private static int |
depthCompare(JSModule m1,
JSModule m2) |
(package private) java.lang.Iterable<JSModule> |
getAllModules()
Gets an iterable over all modules in dependency order.
|
(package private) JSModule |
getDeepestCommonDependency(JSModule m1,
JSModule m2)
Finds the deepest common dependency of two modules, not including the two
modules themselves.
|
JSModule |
getDeepestCommonDependencyInclusive(java.util.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.
|
(package private) int |
getModuleCount()
Gets the total number of modules.
|
(package private) java.util.Map<java.lang.String,JSModule> |
getModulesByName()
Gets all modules indexed by name.
|
(package private) JSModule |
getRootModule()
Gets the root module.
|
(package private) java.util.Set<JSModule> |
getTransitiveDepsDeepestFirst(JSModule m)
Creates an iterable over the transitive dependencies of module
m
in a non-increasing depth ordering. |
java.util.List<CompilerInput> |
manageDependencies(DependencyOptions depOptions,
java.util.List<CompilerInput> inputs)
Apply the dependency options to the list of sources, returning a new
source list re-ordering and dropping files as necessary.
|
java.util.List<CompilerInput> |
manageDependencies(java.util.List<ModuleIdentifier> entryPoints,
java.util.List<CompilerInput> inputs)
Applies a DependencyOptions in "dependency sorting" and "dependency pruning"
mode to the given list of inputs.
|
(package private) LinkedDirectedGraph<JSModule,java.lang.String> |
toGraphvizGraph() |
(package private) com.google.gson.JsonArray |
toJson()
Returns a JSON representation of the JSModuleGraph.
|
private java.util.List<JSModule> modules
private java.util.List<java.util.List<JSModule>> modulesByDepth
modulesByDepth.get(3)
is a
list of the modules at depth 3, for example.private java.util.Map<JSModule,java.util.Set<JSModule>> dependencyMap
public JSModuleGraph(JSModule[] modulesInDepOrder)
public JSModuleGraph(java.util.List<JSModule> modulesInDepOrder)
java.lang.Iterable<JSModule> getAllModules()
java.util.Map<java.lang.String,JSModule> getModulesByName()
int getModuleCount()
JSModule getRootModule()
@GwtIncompatible(value="com.google.gson") com.google.gson.JsonArray toJson()
public boolean dependsOn(JSModule src, JSModule m)
JSModule getDeepestCommonDependency(JSModule m1, JSModule m2)
m1
- A module in this graphm2
- A module in this graphm1
and m2
, or null if
they have no common dependenciespublic JSModule getDeepestCommonDependencyInclusive(JSModule m1, JSModule m2)
m1
- A module in this graphm2
- A module in this graphm1
and m2
, or null if
they have no common dependenciespublic JSModule getDeepestCommonDependencyInclusive(java.util.Collection<JSModule> modules)
java.util.Set<JSModule> getTransitiveDepsDeepestFirst(JSModule m)
m
in a non-increasing depth ordering. The result does not include the module
m
.m
- A module in this graphm
private static void addDeps(java.util.Set<JSModule> deps, JSModule m)
public void coalesceDuplicateFiles()
public java.util.List<CompilerInput> manageDependencies(java.util.List<ModuleIdentifier> entryPoints, java.util.List<CompilerInput> inputs) throws SortedDependencies.CircularDependencyException, JSModuleGraph.MissingModuleException, SortedDependencies.MissingProvideException
manageDependencies(DependencyOptions, List<CompilerInput>)
.entryPoints
- The entry points into the program.
Expressed as JS symbols.inputs
- The original list of sources. Used to ensure that the sort
is stable.SortedDependencies.CircularDependencyException
- if there is a circular dependency
between the provides and requires.SortedDependencies.MissingProvideException
- if an entry point was not provided
by any of the inputs.JSModuleGraph.MissingModuleException
for more info on how this works.
public java.util.List<CompilerInput> manageDependencies(DependencyOptions depOptions, java.util.List<CompilerInput> inputs) throws SortedDependencies.CircularDependencyException, SortedDependencies.MissingProvideException, JSModuleGraph.MissingModuleException
inputs
- The original list of sources. Used to ensure that the sort
is stable.SortedDependencies.CircularDependencyException
- if there is a circular dependency
between the provides and requires.SortedDependencies.MissingProvideException
- if an entry point was not provided
by any of the inputs.JSModuleGraph.MissingModuleException
for more info on how this works.
private java.util.Collection<CompilerInput> createEntryPointInputs(DependencyOptions depOptions, java.util.List<CompilerInput> inputs, SortedDependencies<CompilerInput> sorter) throws JSModuleGraph.MissingModuleException, SortedDependencies.MissingProvideException
LinkedDirectedGraph<JSModule,java.lang.String> toGraphvizGraph()