From 0a98a2baa4bee1f700cedceba05239cab33896d6 Mon Sep 17 00:00:00 2001 From: Eugene Petrenko Date: Tue, 12 May 2020 23:09:44 +0200 Subject: [PATCH] IDEA-CR-62399 - drop VirtualFile#toPathOrNull, rename toPath() to toNioPath() GitOrigin-RevId: 0927de3ff1eda025bdcb76854c511b9f07c2299b --- .../src/ChooseComponentsToExportDialog.kt | 2 +- .../com/intellij/openapi/vfs/VfsUtilCore.java | 11 +++++----- .../com/intellij/openapi/vfs/VirtualFile.java | 22 +++++-------------- .../intellij/openapi/vfs/VirtualFileLookup.kt | 2 +- .../vfs/local/LocalFileSystemTest.java | 4 ++-- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt index 0f33211156ca..69751974bdbb 100644 --- a/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt +++ b/platform/configuration-store-impl/src/ChooseComponentsToExportDialog.kt @@ -75,7 +75,7 @@ fun chooseSettingsFile(oldPath: String?, parent: Component?, title: String, desc chooserDescriptor.title = title chooserDescriptor.withFileFilter { ConfigImportHelper.isSettingsFile(it) || - it.toPathOrNull()?.let { p -> ConfigImportHelper.isConfigDirectory(p) } == true + it.fileSystem.getNioPath(it)?.let { p -> ConfigImportHelper.isConfigDirectory(p) } == true } var initialDir: VirtualFile? diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java index 254b6ab80039..c4fc3f27015d 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VfsUtilCore.java @@ -411,12 +411,11 @@ public class VfsUtilCore { * @return a {@link File} for a given {@link VirtualFile}, * the created file may not exist or may not make sense. *
- * It could be better and more reliably to use the {@link VirtualFile#toPath()} + * It could be better and more reliably to use the {@link VirtualFile#toNioPath()} *
* @implNote it takes the part after ://, trims !/ at the end and turns it into a File path * - * @see VirtualFile#toPathOrNull() - * @see VirtualFile#toPath() + * @see VirtualFile#toNioPath() */ @NotNull public static File virtualToIoFile(@NotNull VirtualFile file) { @@ -437,12 +436,12 @@ public class VfsUtilCore { * @return a {@link File} for a given {@link VirtualFile}, * the created file may not exist or may not make sense. *
- * It could be better and more reliably to use the {@link VirtualFile#toPath()} + * It could be better and more reliably to use the {@link VirtualFile#toNioPath()} *
* @implNote for every item, it takes the part after ://, trims !/ at the end and turns it into a File path + * * @see #virtualToIoFile(VirtualFile) - * @see VirtualFile#toPathOrNull() - * @see VirtualFile#toPath() + * @see VirtualFile#toNioPath() */ public static List virtualToIoFiles(@NotNull Collection files) { return ContainerUtil.map2List(files, file -> virtualToIoFile(file)); diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java index 5976ddbfe006..02064b36d9a2 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFile.java @@ -128,7 +128,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica * ({@link File#separatorChar}) replaced to the forward slash ({@code '/'}). * * @return the path - * @see #toPath() + * @see #toNioPath() */ @NotNull public abstract String getPath(); @@ -137,29 +137,19 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica * @return a related {@link Path} for a given virtual file where possible otherwise an * exception is thrown. * The returned {@link Path} may not have a default filesystem behind. + *
+ * Use {@link #getFileSystem()} and {@link VirtualFileSystem#getNioPath(VirtualFile)} + * to avoid the exception * * @throws UnsupportedOperationException if this VirtualFile does not have an associated {@link Path} - * - * @see #toPathOrNull() */ @NotNull - public Path toPath() { - Path path = toPathOrNull(); + public Path toNioPath() { + Path path = getFileSystem().getNioPath(this); if (path != null) return path; throw new UnsupportedOperationException("Failed to map " + this + " (filesystem " + getFileSystem() + ") into nio Path"); } - /** - * @return a related {@link Path} for a given virtual file where possible otherwise {@code null}. - * The returned {@link Path} may not have a default filesystem behind. - * - * @see #toPath() - */ - @Nullable - public Path toPathOrNull() { - return getFileSystem().getNioPath(this); - } - /** *

Returns the URL of this file. The URL is a string that uniquely identifies a file in all file systems. * It has the following format: {@code ://}.

diff --git a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileLookup.kt b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileLookup.kt index 63e1d2c433f1..77ad86e0ae5a 100644 --- a/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileLookup.kt +++ b/platform/core-api/src/com/intellij/openapi/vfs/VirtualFileLookup.kt @@ -34,7 +34,7 @@ interface VirtualFileLookup { /** * Searches for a [VirtualFile] corresponding to the given nio [Path]. - * The [VirtualFile.toPath] method should return the same Path back. + * The [VirtualFile.toNioPath] method should return the same Path back. */ fun fromNioPath(path: Path) : VirtualFile? diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java index 168b30485e7b..552e6dff798e 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/LocalFileSystemTest.java @@ -851,7 +851,7 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { File newDir = tempDir.newDirectory("someDir-32"); VirtualFile newDirFile = myFS.refreshAndFindFileByPath(newDir.getPath()); assertNotNull(newDirFile); - assertThat(newDirFile.toPath()).isNotNull().isEqualTo(newDir.toPath()); + assertThat(newDirFile.toNioPath()).isNotNull().isEqualTo(newDir.toPath()); } @Test @@ -859,6 +859,6 @@ public class LocalFileSystemTest extends BareTestFixtureTestCase { File newDir = tempDir.newFile("someFile-32"); VirtualFile newDirFile = myFS.refreshAndFindFileByPath(newDir.getPath()); assertNotNull(newDirFile); - assertThat(newDirFile.toPath()).isNotNull().isEqualTo(newDir.toPath()); + assertThat(newDirFile.toNioPath()).isNotNull().isEqualTo(newDir.toPath()); } } \ No newline at end of file