ArrangementEntryDependencyInfo (@NotNull final PsiMethod method, @NotNull Map<PsiMethod, ArrangementEntryDependencyInfo> cache) { JavaElementArrangementEntry entry = myMethodEntriesMap.get(method); if (entry == null) { return null; } ArrangementEntryDependencyInfo result = new ArrangementEntryDependencyInfo(entry); Stack<Pair<PsiMethod, ArrangementEntryDependencyInfo>> toProcess = new Stack<>(); toProcess.push(Pair.create(method, result)); Set<PsiMethod> usedMethods = new HashSet<>(); while (!toProcess.isEmpty()) { Pair<PsiMethod, ArrangementEntryDependencyInfo> pair = toProcess.pop(); Set<PsiMethod> dependentMethods = myMethodDependencies.get(pair.first); if (dependentMethods == null) { continue; } usedMethods.add(pair.first); for (PsiMethod dependentMethod : dependentMethods) { if (usedMethods.contains(dependentMethod)) { // Prevent cyclic dependencies. return null; } JavaElementArrangementEntry dependentEntry = myMethodEntriesMap.get(dependentMethod); if (dependentEntry == null) { continue; } ArrangementEntryDependencyInfo dependentMethodInfo = cache.get(dependentMethod); if (dependentMethodInfo == null) { cache.put(dependentMethod, dependentMethodInfo = new ArrangementEntryDependencyInfo(dependentEntry)); } Pair<PsiMethod, ArrangementEntryDependencyInfo> dependentPair = Pair.create(dependentMethod, dependentMethodInfo); pair.second.addDependentEntryInfo(dependentPair.second); toProcess.push(dependentPair); } } return result; }