int (@NotNull Object element) { int distance = 0; Object eachParent = element; while (eachParent != null) { if (myAutoExpandRoots.contains(eachParent)) break; eachParent = getTreeStructure().getParentElement(eachParent); distance++; } return eachParent != null ? distance : -1; }