Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor) { TreeModel model = tree.getModel(); if (model instanceof TreeVisitor.Acceptor acceptor) { return acceptor.accept(visitor); } if (model == null) return Promises.rejectedPromise("tree model is not set"); AsyncPromise<TreePath> promise = new AsyncPromise<>(); EdtInvocationManager.invokeLaterIfNeeded(() -> promise.setResult(visitModel(model, visitor))); return promise; }