mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-CR-62399 - drop VirtualFile#toPathOrNull, rename toPath() to toNioPath()
GitOrigin-RevId: 0927de3ff1eda025bdcb76854c511b9f07c2299b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d8af0c4e3a
commit
0a98a2baa4
@@ -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?
|
||||
|
||||
@@ -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.
|
||||
* <br />
|
||||
* 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()}
|
||||
* <br />
|
||||
* @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.
|
||||
* <br />
|
||||
* 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()}
|
||||
* <br />
|
||||
* @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<File> virtualToIoFiles(@NotNull Collection<? extends VirtualFile> files) {
|
||||
return ContainerUtil.map2List(files, file -> virtualToIoFile(file));
|
||||
|
||||
@@ -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.
|
||||
* <br/>
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>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 <protocol>://<path>}.</p>
|
||||
|
||||
@@ -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?
|
||||
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user