FileTreeUtil { @NotNull public static List<FilePath> getTree(@NotNull FilePath path) { List<FilePath> ret = new ArrayList<>(); FilePath prev; FilePath next = path; do { ret.add(next); prev = next; next = next.getParentPath(); } while (next != null && !next.equals(prev)); return ret; }  @NotNull static List<FilePath> getTree(@NotNull FilePath path); @Nullable static List<FilePath> getTreeTo(@NotNull FilePath path, @Nullable FilePath parent); @Nullable static List<VirtualFile> getTreeTo(@NotNull VirtualFile path, @Nullable VirtualFile parent); static int getPathDepth(@NotNull FilePath path, @Nullable FilePath parent); static int getPathDepth(@NotNull VirtualFile path, @Nullable VirtualFile parent); static int getPathDepth(@NotNull FilePath path, @Nullable VirtualFile parent); static boolean isSameOrUnder(@Nullable FilePath parent, @NotNull FilePath child); static boolean isSameOrUnder(@Nullable VirtualFile parent, @NotNull FilePath child); @Nullable static FilePath getCommonRoot(@NotNull Collection<FilePath> files);  }
@Test void getTree_FilePath() { Map<String, MockVirtualFile> vfs = MockVirtualFileSystem.createTree( "one/two/three/four/five.txt", "contents", "root.txt", "contents", "one/root.txt", "contents", "two/root.txt", "contents" ); FilePath five = vfs.get("one/two/three/four/five.txt").asFilePath(); List<FilePath> tree = FileTreeUtil.getTree(five); assertSize(6, tree); assertEquals(five, tree.get(0)); assertEquals(five.getParentPath(), tree.get(1)); assertEquals(five.getParentPath().getParentPath(), tree.get(2)); assertEquals(five.getParentPath().getParentPath().getParentPath(), tree.get(3)); assertEquals(five.getParentPath().getParentPath().getParentPath().getParentPath(), tree.get(4)); assertEquals(five.getParentPath().getParentPath().getParentPath().getParentPath().getParentPath(), tree.get(5)); assertNotNull(tree.get(5)); }