HashSet<ICompilationUnit> result = new HashSet<ICompilationUnit>();
LinkedList<Edge> workList = new LinkedList<Edge>();
for (ICompilationUnit unit : roots)
{
assert unit instanceof CompilationUnitBase;
CompilationUnitBase compilationUnit = (CompilationUnitBase)unit;
boolean alreadyVisited = !result.add(compilationUnit);
if (!alreadyVisited)
workList.addAll(compilationUnit.getProject().getDependencyGraph().getIncomingEdges(compilationUnit));
}
DependencyTypeSet recursiveInvalidationSet = DependencyTypeSet.of(DependencyType.INHERITANCE, DependencyType.SIGNATURE, DependencyType.NAMESPACE);
HashSet<Edge> visitedEdges = new HashSet<Edge>();
while (!workList.isEmpty())
{
Edge currentEdge = workList.pop();
if (visitedEdges.add(currentEdge))
{
assert currentEdge.getFrom() instanceof CompilationUnitBase;
CompilationUnitBase dependentUnit = (CompilationUnitBase)currentEdge.getFrom();
result.add(dependentUnit);
if (currentEdge.typeInSet(recursiveInvalidationSet))
workList.addAll(dependentUnit.getProject().getDependencyGraph().getIncomingEdges(dependentUnit));
}
}
return result;
}