Object (@NotNull String s) { List<SpeedSearchObjectWithWeight> elements = SpeedSearchObjectWithWeight.findElement(s, this); SpeedSearchObjectWithWeight best = ContainerUtil.getFirstItem(elements); if (best == null) return null; if (myInitialElement instanceof PsiElement initial) { // find children of the initial element SpeedSearchObjectWithWeight bestForParent = find(initial, elements, FileStructurePopup::isParent); if (bestForParent != null) return bestForParent.node; // find siblings of the initial element PsiElement parent = initial.getParent(); if (parent != null) { SpeedSearchObjectWithWeight bestSibling = find(parent, elements, FileStructurePopup::isParent); if (bestSibling != null) return bestSibling.node; } // find grand children of the initial element SpeedSearchObjectWithWeight bestForAncestor = find(initial, elements, FileStructurePopup::isAncestor); if (bestForAncestor != null) return bestForAncestor.node; } return best.node; }