public final class DependencyGraph extends Object
CompilerProject
.
There are four types of dependency that may exist from one
ICompilationUnit
to another ICompilationUnit
.
ICompilationUnit
A contains a definition that extends a class
or implements an interface defined in ICompilationUnit
B, then there
is an inheritance dependency from A to B.ICompilationUnit
A refers to a definition from
ICompilationUnit
B, then there is a signature dependency from A to B.
ICompilationUnit
A depends on a namespace definition from
ICompilationUnit
B, then there is a namespace dependency from A to B.
ICompilationUnit
A contains any reference to
ICompilationUnit
B that does not result in any other type of
dependency, then there exists an expression dependency from A to B.The code in this class intends to make adding or updating a dependency edge very fast and thread safe.
Modifier and Type | Class and Description |
---|---|
static class |
DependencyGraph.Dependency |
Constructor and Description |
---|
DependencyGraph()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addCompilationUnit(ICompilationUnit cu)
Add a
ICompilationUnit to the dependency graph. |
void |
addCompilationUnits(Collection<ICompilationUnit> c)
Add a Collection of
ICompilationUnit 's to the dependency graph. |
void |
addDependency(ICompilationUnit depender,
ICompilationUnit dependee,
DependencyType dt)
Adds an anonymous dependency to the dependency graph.
|
void |
addDependency(ICompilationUnit depender,
ICompilationUnit dependee,
DependencyTypeSet dt,
String targetQName)
Adds a dependency to the dependency graph.
|
void |
addDependency(ICompilationUnit depender,
ICompilationUnit dependee,
DependencyType dt,
String targetQName)
Adds a dependency to the dependency graph.
|
void |
addEmbedCompilationUnit(EmbedCompilationUnit unit)
Adds an
EmbedCompilationUnit to the dependency graph. |
static Set<ICompilationUnit> |
computeInvalidationSet(Iterable<ICompilationUnit> roots)
Computes the set of
ICompilationUnit 's that should be cleaned
given a collection of ICompilationUnit 's that are known to need
cleaning. |
boolean |
contains(ICompilationUnit unit) |
Collection<ICompilationUnit> |
getCompilationUnits() |
Map<String,DependencyTypeSet> |
getDependencySet(ICompilationUnit from,
ICompilationUnit to)
Finds the named dependencies between two compilation unit
|
DependencyTypeSet |
getDependencyTypes(ICompilationUnit from,
ICompilationUnit to)
Finds the dependencies between two
ICompilationUnit s |
Set<ICompilationUnit> |
getDirectDependencies(ICompilationUnit cu)
Get the Set of
ICompilationUnit 's depended on directly by the specified ICompilationUnit . |
Set<ICompilationUnit> |
getDirectReverseDependencies(ICompilationUnit cu,
DependencyTypeSet types)
Get the Set of
ICompilationUnit 's that directly depended on the specified ICompilationUnit . |
void |
removeCompilationUnit(ICompilationUnit cu)
Removes an
ICompilationUnit from the dependency graph. |
void |
removeDependencies(ICompilationUnit cu)
Remove all of the outgoing dependencies on a compilation unit.
|
List<ICompilationUnit> |
topologicalSort(Collection<ICompilationUnit> roots)
Computes the list of all
ICompilationUnit 's that the specified
collection of ICompilationUnit 's depends directly or indirectly. |
List<ICompilationUnit> |
topologicalSort(Collection<ICompilationUnit> roots,
Comparator<ICompilationUnit> comparator)
Computes the list of all
ICompilationUnit 's that the specified
collection of ICompilationUnit 's depends directly or indirectly. |
public void addDependency(ICompilationUnit depender, ICompilationUnit dependee, DependencyTypeSet dt, String targetQName)
depender
- ICompilationUnit
with a reference to a definition
defined by the other ICompilationUnit
.dependee
- ICompilationUnit
with a definition referred to by
the other ICompilationUnit
.dt
- The dependency types to add from the "depender" to the "dependee".targetQName
- A qname of the definition of the dependee that the depender depends onpublic void addDependency(ICompilationUnit depender, ICompilationUnit dependee, DependencyType dt, String targetQName)
depender
- ICompilationUnit
with a reference to a definition
defined by the other ICompilationUnit
.dependee
- ICompilationUnit
with a definition referred to by
the other ICompilationUnit
.dt
- The type of dependency to add from the "depender" to the "dependee".targetQName
- A qname of the definition of the dependee that the depender depends onpublic void addDependency(ICompilationUnit depender, ICompilationUnit dependee, DependencyType dt)
depender
- ICompilationUnit
with a reference to a definition
defined by the other ICompilationUnit
.dependee
- ICompilationUnit
with a definition referred to by
the other ICompilationUnit
.dt
- The type of dependency to add from the "depender" to the "dependee".public void removeDependencies(ICompilationUnit cu)
cu
- The compilation to remove dependencies from.public List<ICompilationUnit> topologicalSort(Collection<ICompilationUnit> roots)
ICompilationUnit
's that the specified
collection of ICompilationUnit
's depends directly or indirectly.
ICompilationUnit
's that contain definitions that extend or
implement definitions from other ICompilationUnit
's will occur in
the list after the ICompilationUnit
's that contains the
definitions that are extended or implemented.
In cases where ICompilationUnit
s have no real dependencies between
them this function employs a lexical sort on the ICompilationUnit
's
name.roots
- Collection of ICompilationUnit
's that will be in the
returned List along with any ICompilationUnit
's they depend on
directly or indirectly.ICompilationUnit
's that the specified
collection of ICompilationUnit
's depends directly or indirectly.public List<ICompilationUnit> topologicalSort(Collection<ICompilationUnit> roots, Comparator<ICompilationUnit> comparator)
ICompilationUnit
's that the specified
collection of ICompilationUnit
's depends directly or indirectly.
ICompilationUnit
's that contain definitions that extend or
implement definitions from other ICompilationUnit
's will occur in
the list after the ICompilationUnit
's that contains the
definitions that are extended or implemented.roots
- Collection of ICompilationUnit
's that will be in the
returned List along with any ICompilationUnit
's they depend on
directly or indirectly.comparator
- The comparator of last resort used to order
ICompilationUnit
s when there are no real dependencies between them.ICompilationUnit
's that the specified
collection of ICompilationUnit
's depends directly or indirectly.public static Set<ICompilationUnit> computeInvalidationSet(Iterable<ICompilationUnit> roots)
ICompilationUnit
's that should be cleaned
given a collection of ICompilationUnit
's that are known to need
cleaning.
This method is not thread safe and must not be called while any compilation is occurring in any project in the workspace associated with the specified compilation units.
roots
- ICompilationUnit
's that are known to need cleaningICompilationUnit
's that should be cleaned.public void addCompilationUnit(ICompilationUnit cu)
ICompilationUnit
to the dependency graph.cu
- ICompilationUnit
to add to the dependency graphpublic void addCompilationUnits(Collection<ICompilationUnit> c)
ICompilationUnit
's to the dependency graph.c
- Collection of ICompilationUnit
's to add to the dependency graphpublic void removeCompilationUnit(ICompilationUnit cu)
ICompilationUnit
from the dependency graph.public Set<ICompilationUnit> getDirectDependencies(ICompilationUnit cu)
ICompilationUnit
's depended on directly by the specified ICompilationUnit
.cu
- ICompilationUnit
whose set of direct dependencies will be returned.ICompilationUnit
's that the specified ICompilationUnit
directly depends on.public Set<ICompilationUnit> getDirectReverseDependencies(ICompilationUnit cu, DependencyTypeSet types)
ICompilationUnit
's that directly depended on the specified ICompilationUnit
.cu
- A compilation unit.types
- Set of dependency types used to filter the returned set of ICompilationUnit
's.ICompilationUnit
's that directly depend on the
specified ICompilationUnit
.public void addEmbedCompilationUnit(EmbedCompilationUnit unit)
EmbedCompilationUnit
to the dependency graph.
This is just like adding any other compilation unit, except
for the fact that we may be in the middle of compiling a project.
Thus, when we add an embed compilation unit we grab the dependency graph
write lock.unit
- The embed compilation unit to be added.public boolean contains(ICompilationUnit unit)
unit
- An ICompilationUnit
to be checkedICompilationUnit
unit exists in this DependencyGraph
public Map<String,DependencyTypeSet> getDependencySet(ICompilationUnit from, ICompilationUnit to)
from
- The depender ICompilationUnit
to
- The dependee ICompilationUnit
Map
from definition qname String
to a DependencyTypeSet
,
representing the dependencies between two ICompilationUnit
public DependencyTypeSet getDependencyTypes(ICompilationUnit from, ICompilationUnit to)
ICompilationUnit
sfrom
- The depender ICompilationUnit
to
- The dependee ICompilationUnit
DependencyTypeSet
that is active between the two compilation unitspublic Collection<ICompilationUnit> getCompilationUnits()
Copyright © 2016 The Apache Software Foundation. All rights reserved.