TreeVisitor (TreeNode node) { return new TreeVisitor.ByComponent<>(node, o -> o) { @Override protected boolean contains(@NotNull Object pathComponent, @NotNull TreeNode thisComponent) { while (pathComponent != thisComponent && thisComponent != null) thisComponent = thisComponent.getParent(); return thisComponent != null; } }; }