TreePath (@NotNull TreeNode node) { if (node instanceof DefaultMutableTreeNode) { return new TreePath(((DefaultMutableTreeNode)node).getPath()); } else { List<TreeNode> nodes = new ArrayList<>(); TreeNode eachParent = node; while (eachParent != null) { nodes.add(eachParent); eachParent = eachParent.getParent(); } return new TreePath(ArrayUtil.toObjectArray(nodes)); } }