private static boolean isInTopSubTree(@NotNull TreeNode node) {
    Set<TreeNode> visited = new HashSet<>();
    while (node.getParent() != null) {
      if (!visited.add(node) || visited.size() > 10) { // stop expanding if recursion detected or we're too deep
        return false;
      }
      if (node != node.getParent().getChildAt(0)) {
        return false;
      }
      node = node.getParent();
    }

    return true;
  }
private static boolean isInTopSubTree(@NotNull TreeNode node)