boolean (@NotNull PsiMethod method, @NotNull HierarchyNodeDescriptor parentDescriptor) { // detect recursion // the current call-site calls *method* // Thus, we already have a node that represents *method* // Check whether we have any other node along the parent-chain that represents that same method NodeDescriptor<?> ancestorDescriptor = parentDescriptor; // Start check on grandparent while ((ancestorDescriptor = ancestorDescriptor.getParentDescriptor()) != null) { if (ancestorDescriptor instanceof HierarchyNodeDescriptor) { PsiMember ancestorCallSite = getEnclosingElement(((HierarchyNodeDescriptor)ancestorDescriptor).getPsiElement()); if (ancestorCallSite == method) { // We have at least two occurrences in the parent chain of method already // Don't search any deeper return true; } } } return false; }