TreePath (@NotNull TreePath path, int minCount, int keepSelectionLevel) { if (keepSelectionLevel < 0) return path; if (keepSelectionLevel > minCount) minCount = keepSelectionLevel; int pathCount = path.getPathCount(); while (minCount < pathCount--) path = path.getParentPath(); assert path != null : "unexpected minCount: " + minCount; return path; }