diff --git a/platform/core-impl/src/com/intellij/util/graph/impl/HierarchyTreeImpl.kt b/platform/core-impl/src/com/intellij/util/graph/impl/HierarchyTreeImpl.kt index aef7469f53a2..08aba2a64abe 100644 --- a/platform/core-impl/src/com/intellij/util/graph/impl/HierarchyTreeImpl.kt +++ b/platform/core-impl/src/com/intellij/util/graph/impl/HierarchyTreeImpl.kt @@ -23,7 +23,8 @@ class HierarchyTreeImpl : HierarchyTree { private val nodes2ParentGroupsMap = mutableMapOf() private val groupNodes2Children = mutableMapOf>() - override fun getAllHierarchyNodes(): Set = hierarchyNodes + override val allHierarchyNodes: Set + get() = hierarchyNodes override fun getParent(node: N): GN? { return nodes2ParentGroupsMap[node] @@ -43,6 +44,16 @@ class HierarchyTreeImpl : HierarchyTree { return children } + override fun getDepth(node: N): Int { + var depth = 0 + var parent = getParent(node) + while (parent != null) { + depth++ + parent = getParent(parent) + } + return depth + } + override fun connect(child: N, parent: GN) { hierarchyNodes.add(child) hierarchyNodes.add(parent) diff --git a/platform/util/src/com/intellij/util/graph/HierarchyTree.kt b/platform/util/src/com/intellij/util/graph/HierarchyTree.kt index 8e84e5aca61b..aa44735750ba 100644 --- a/platform/util/src/com/intellij/util/graph/HierarchyTree.kt +++ b/platform/util/src/com/intellij/util/graph/HierarchyTree.kt @@ -29,7 +29,7 @@ interface HierarchyTree { * * @return The set containing all the hierarchy nodes in the hierarchy tree. */ - fun getAllHierarchyNodes(): Set + val allHierarchyNodes: Set /** * Retrieves the parent node of the given node. @@ -49,6 +49,14 @@ interface HierarchyTree { */ fun getChildren(group: GN, isRecursively: Boolean = false): Set + /** + * Retrieves the depth of the given node in the hierarchy tree. + * + * @param node The node for which to retrieve the depth. + * @return The depth of the given node in the hierarchy tree. + */ + fun getDepth(node: N): Int + /** * Connects a child node to a parent group node in the hierarchy tree. *