@Nonnull
	@SuppressWarnings("deprecation")
	public static WorkspaceTreeNode getOrInsertIntoTree(@Nonnull WorkspaceTreeNode node, @Nonnull PathNode<?> path, boolean sorted) {
		// Edge case handling for directory nodes.
		if (path instanceof DirectoryPathNode directoryPath) {
			// If we have parent links in our path, insert those first.
			// We should generate up to whatever context our parent is.
			BundlePathNode parent = directoryPath.getParent();
			if (parent != null)
				node = getOrInsertIntoTree(node, parent, sorted);

			// Work off of the first node that does NOT contain a directory value.
			// This should result in the node pointing to a bundle.
			while (node.getValue() instanceof DirectoryPathNode) {
				node = (WorkspaceTreeNode) node.getSourceParent();
				if (node == null)
					throw new IllegalStateException("Directory path node had no parent in workspace tree");
			}

			// Insert the directory path, separated by '/'.
			// Update 'node' as we build/fetch the directory path items.
			// We use '-1' as a limit in split to allow empty directories to be split properly:
			//  '//' --> ['', '', '']
			String fullDirectory = directoryPath.getValue();
			String[] directoryParts = fullDirectory.split("/", -1);

			StringBuilder directoryBuilder = new StringBuilder();
			for (String directoryPart : directoryParts) {
				// Build up directory path.
				directoryBuilder.append(directoryPart).append('/');
				String directoryName = directoryBuilder.substring(0, directoryBuilder.length() - 1);
				DirectoryPathNode localPathNode = directoryPath.withDirectory(directoryName);

				// Get existing tree node, or create child if non-existent
				WorkspaceTreeNode childNode = null;
				ObservableList<TreeItem<PathNode<?>>> children;
				if (node instanceof FilterableTreeItem<?> filterableNode)
					children = Unchecked.cast(filterableNode.getSourceChildren());
				else
					children = node.getChildren();
				for (TreeItem<PathNode<?>> child : children)
					if (child.getValue().equals(localPathNode)) {
						childNode = (WorkspaceTreeNode) child;
						break;
					}
				if (childNode == null) {
					childNode = new WorkspaceTreeNode(localPathNode);
					if (sorted) {
						node.addPreSortedChild(childNode);
					} else {
						node.addAndSortChild(childNode);
					}
				}

				// Prepare for next directory path entry.
				node = childNode;
			}
			return node;
		}

		// If we have parent links in our path, insert those first.
		// We should generate up to whatever context our parent is.
		PathNode<?> parent = path.getParent();
		if (parent != null)
			node = getOrInsertIntoTree(node, parent, sorted);
		else if (path.typeIdMatch(node.getValue())) {
			// We are the root link in the path. This check ensures that as the root type we do not
			// insert a new tree-node of the same value, to the children list of the root tree node.
			return node;
		}

		// Check if already inserted.
		ObservableList<TreeItem<PathNode<?>>> children;
		if (node instanceof FilterableTreeItem<?> filterableNode)
			children = Unchecked.cast(filterableNode.getSourceChildren());
		else
			children = node.getChildren();
		for (TreeItem<PathNode<?>> child : children)
			if (path.equals(child.getValue()))
				return (WorkspaceTreeNode) child;

		// Not already inserted, create a new node and insert it.
		WorkspaceTreeNode inserted = new WorkspaceTreeNode(path);
		if (sorted) {
			node.addPreSortedChild(inserted);
		} else {
			node.addAndSortChild(inserted);
		}
		return inserted;
	}
Get/insert a {@link WorkspaceTreeNode} holding the given {@link PathNode} from/to the tree model.

@param node
		Tree node to insert into.
@param path
		Path to insert, relative to the given node.
@param sorted
       {@code true} if the path insertion is being done in a pre-sorted manner, typically in the case of building an initial tree.
       {@code false} if the path being inserted is not guaranteed to be in order relative to the last path inserted into the tree.

@return Inserted node.
recaf-ui/src/main/java/software/coley/recaf/ui/control/tree/WorkspaceTreeNode.java