EditorConfig documentation test
[idea/community.git] / java / java-impl / src / com / intellij / cyclicDependencies / CyclicDependenciesBuilder.java
index 8baaaa7b33374fd043f62ce39eeae9d00bdd8a01..8f546070ad139aadf32d5ac69a475d3cb063ea8d 100644 (file)
@@ -26,18 +26,13 @@ import com.intellij.openapi.roots.ProjectRootManager;
 import com.intellij.packageDependencies.DependenciesBuilder;
 import com.intellij.packageDependencies.ForwardDependenciesBuilder;
 import com.intellij.psi.*;
-import com.intellij.util.graph.CachingSemiGraph;
-import com.intellij.util.graph.Graph;
-import com.intellij.util.graph.GraphAlgorithms;
-import com.intellij.util.graph.GraphGenerator;
+import com.intellij.util.graph.*;
+import org.jetbrains.annotations.NotNull;
 
 import java.util.*;
 
-/**
- * User: anna
- * Date: Jan 30, 2005
- */
 public class CyclicDependenciesBuilder{
+  @NotNull
   private final Project myProject;
   private final AnalysisScope myScope;
   private final Map<String, PsiPackage> myPackages = new HashMap<>();
@@ -51,14 +46,16 @@ public class CyclicDependenciesBuilder{
 
   private String myRootNodeNameInUsageView;
 
-  public CyclicDependenciesBuilder(final Project project, final AnalysisScope scope) {
+  public CyclicDependenciesBuilder(@NotNull Project project, final AnalysisScope scope) {
     myProject = project;
     myScope = scope;
     myForwardBuilder = new ForwardDependenciesBuilder(myProject, myScope){
+      @Override
       public String getRootNodeNameInUsageView() {
         return CyclicDependenciesBuilder.this.getRootNodeNameInUsageView();
       }
 
+      @Override
       public String getInitialUsagesPosition() {
         return AnalysisScopeBundle.message("cyclic.dependencies.usage.view.initial.text");
       }
@@ -73,6 +70,7 @@ public class CyclicDependenciesBuilder{
     myRootNodeNameInUsageView = rootNodeNameInUsageView;
   }
 
+  @NotNull
   public Project getProject() {
     return myProject;
   }
@@ -206,19 +204,18 @@ public class CyclicDependenciesBuilder{
     return myCyclicDependencies;
   }
 
-  public HashMap<PsiPackage, Set<List<PsiPackage>>> getCycles(Collection<PsiPackage> packages) {
+  public HashMap<PsiPackage, Set<List<PsiPackage>>> getCycles(Collection<? extends PsiPackage> packages) {
     if (myGraph == null){
       myGraph = buildGraph();
     }
     final HashMap<PsiPackage, Set<List<PsiPackage>>> result = new HashMap<>();
-    for (Iterator<PsiPackage> iterator = packages.iterator(); iterator.hasNext();) {
-      PsiPackage psiPackage = iterator.next();
-        Set<List<PsiPackage>> paths2Pack = result.get(psiPackage);
-        if (paths2Pack == null) {
-          paths2Pack = new HashSet<>();
-          result.put(psiPackage, paths2Pack);
-        }
-        paths2Pack.addAll(GraphAlgorithms.getInstance().findCycles(myGraph, psiPackage));
+    for (PsiPackage psiPackage : packages) {
+      Set<List<PsiPackage>> paths2Pack = result.get(psiPackage);
+      if (paths2Pack == null) {
+        paths2Pack = new HashSet<>();
+        result.put(psiPackage, paths2Pack);
+      }
+      paths2Pack.addAll(GraphAlgorithms.getInstance().findCycles(myGraph, psiPackage));
     }
     return result;
   }
@@ -241,22 +238,24 @@ public class CyclicDependenciesBuilder{
     return myPackages;
   }
 
-
   private Graph<PsiPackage> buildGraph() {
-    final Graph<PsiPackage> graph = GraphGenerator.create(CachingSemiGraph.create(new GraphGenerator.SemiGraph<PsiPackage>() {
+    return GraphGenerator.generate(CachingSemiGraph.cache(new InboundSemiGraph<PsiPackage>() {
+      @Override
+      @NotNull
       public Collection<PsiPackage> getNodes() {
         return getAllScopePackages().values();
       }
 
+      @NotNull
+      @Override
       public Iterator<PsiPackage> getIn(PsiPackage psiPack) {
         final Set<PsiPackage> psiPackages = myPackageDependencies.get(psiPack);
         if (psiPackages == null) {     //for packs without java classes
-          return new HashSet<PsiPackage>().iterator();
+          return Collections.emptyIterator();
         }
         return psiPackages.iterator();
       }
     }));
-    return graph;
   }
 
   public Set<PsiPackage> getPackageHierarhy(String packageName) {
@@ -283,5 +282,4 @@ public class CyclicDependenciesBuilder{
     final PsiPackage psiPackage = getAllScopePackages().get(packName);
     return psiPackage;
   }
-
-}
+}
\ No newline at end of file