From 994d8c338c9d1967f3f095936049567b521448ed Mon Sep 17 00:00:00 2001 From: Vladimir Lagunov Date: Thu, 17 Oct 2024 17:22:09 +0200 Subject: [PATCH] Eel API: rename methods in EelPath: foobarE -> foobar IJ-CR-147046 (cherry picked from commit 38d4ed91bb138a96c999f140c9671b96dac081a0) GitOrigin-RevId: 26a58200d6f669137019495176576661bf1c01d2 --- .../platform/eel/fs/EelFileSystemApi.kt | 5 +-- .../eel/path/ArrayListEelAbsolutePath.kt | 15 +++---- .../eel/path/ArrayListEelRelativePath.kt | 9 +++-- .../com/intellij/platform/eel/path/EelPath.kt | 39 ++++++++++--------- .../platform/eel/path/EelAbsolutePathTest.kt | 2 +- .../platform/eel/path/EelRelativePathTest.kt | 26 ++++++------- .../eel/impl/local/LocalEelApiImpl.kt | 4 +- .../eel/provider/utils/eelProcessUtils.kt | 4 +- .../community/impl/nio/IjentNioFileSystem.kt | 4 +- .../impl/nio/IjentNioFileSystemProvider.kt | 4 +- .../impl/nio/IjentNioFileSystemUtil.kt | 3 +- .../ijent/community/impl/nio/IjentNioPath.kt | 10 ++--- .../execution/eel/EelApiWithPathsMapping.kt | 7 +--- 13 files changed, 66 insertions(+), 66 deletions(-) diff --git a/platform/eel/src/com/intellij/platform/eel/fs/EelFileSystemApi.kt b/platform/eel/src/com/intellij/platform/eel/fs/EelFileSystemApi.kt index 6f707dc85144..e8715d7ed786 100644 --- a/platform/eel/src/com/intellij/platform/eel/fs/EelFileSystemApi.kt +++ b/platform/eel/src/com/intellij/platform/eel/fs/EelFileSystemApi.kt @@ -7,12 +7,11 @@ import com.intellij.platform.eel.EelUserPosixInfo import com.intellij.platform.eel.EelUserWindowsInfo import com.intellij.platform.eel.fs.EelFileSystemApi.StatError import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.EelPathError import java.nio.ByteBuffer import kotlin.Throws -fun EelFileSystemApi.getPathE(string: String, vararg other: String): EelPath.Absolute { - return EelPath.Absolute.buildE(listOf(string, *other), when (this) { +fun EelFileSystemApi.getPath(string: String, vararg other: String): EelPath.Absolute { + return EelPath.Absolute.build(listOf(string, *other), when (this) { is EelFileSystemPosixApi -> EelPath.Absolute.OS.UNIX is EelFileSystemWindowsApi -> EelPath.Absolute.OS.WINDOWS else -> throw UnsupportedOperationException("Unsupported OS: ${this::class.java}") diff --git a/platform/eel/src/com/intellij/platform/eel/path/ArrayListEelAbsolutePath.kt b/platform/eel/src/com/intellij/platform/eel/path/ArrayListEelAbsolutePath.kt index f863f796be12..02d006e9e00b 100644 --- a/platform/eel/src/com/intellij/platform/eel/path/ArrayListEelAbsolutePath.kt +++ b/platform/eel/src/com/intellij/platform/eel/path/ArrayListEelAbsolutePath.kt @@ -1,7 +1,8 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.platform.eel.path -import com.intellij.platform.eel.EelResult +import kotlin.Throws + internal class ArrayListEelAbsolutePath private constructor( private val _root: Root, @@ -33,7 +34,7 @@ internal class ArrayListEelAbsolutePath private constructor( root.fileName == other.root.fileName && (0..() for (part in parts) { when (part) { @@ -56,7 +57,7 @@ internal class ArrayListEelAbsolutePath private constructor( return ArrayListEelAbsolutePath(_root, result) } - override fun resolveE(other: EelPath.Relative): EelPath.Absolute { + override fun resolve(other: EelPath.Relative): EelPath.Absolute { val result = parts.toMutableList() for (index in 0.., ) : EelPath.Relative { @@ -24,7 +27,7 @@ internal class ArrayListEelRelativePath private constructor( return true } - override fun resolveE(other: EelPath.Relative): ArrayListEelRelativePath { + override fun resolve(other: EelPath.Relative): ArrayListEelRelativePath { val result = mutableListOf() result += parts if (other != EMPTY) { @@ -36,7 +39,7 @@ internal class ArrayListEelRelativePath private constructor( return ArrayListEelRelativePath(result) } - override fun getChildE(name: String): ArrayListEelRelativePath = + override fun getChild(name: String): ArrayListEelRelativePath = when { name.isEmpty() -> throw EelPathException(name, "Empty child name is not allowed") "/" in name -> throw EelPathException(name, "Invalid symbol in child name: /") @@ -121,7 +124,7 @@ internal class ArrayListEelRelativePath private constructor( // Not optimal, but DRY. var result = ArrayListEelRelativePath(listOf()) for (part in parts) { - result = result.getChildE(part) + result = result.getChild(part) } return result } diff --git a/platform/eel/src/com/intellij/platform/eel/path/EelPath.kt b/platform/eel/src/com/intellij/platform/eel/path/EelPath.kt index 053d6d61b8c8..a4c0416ed5e8 100644 --- a/platform/eel/src/com/intellij/platform/eel/path/EelPath.kt +++ b/platform/eel/src/com/intellij/platform/eel/path/EelPath.kt @@ -6,6 +6,7 @@ import com.intellij.platform.eel.EelResult import com.intellij.platform.eel.getOrThrow import com.intellij.platform.eel.path.EelPath.Absolute.OS import java.nio.file.InvalidPathException +import kotlin.Throws interface EelPathError { val raw: String @@ -26,9 +27,9 @@ sealed interface EelPath { companion object { @Throws(EelPathException::class) @JvmStatic - fun parseE(raw: String, os: OS?): EelPath = + fun parse(raw: String, os: OS?): EelPath = ArrayListEelAbsolutePath.parseOrNull(raw, os) - ?: Relative.parseE(raw) + ?: Relative.parse(raw) } val fileName: String @@ -101,7 +102,7 @@ sealed interface EelPath { * It should fail in cases like Absolute("/").resolve(Relative("..")). */ @Throws(EelPathException::class) - fun resolveE(other: Relative): EelPath + fun resolve(other: Relative): EelPath /** * ```kotlin @@ -114,7 +115,7 @@ sealed interface EelPath { * ``` */ @Throws(EelPathException::class) - fun getChildE(name: String): EelPath + fun getChild(name: String): EelPath override fun toString(): String @@ -122,7 +123,7 @@ sealed interface EelPath { companion object { @JvmStatic @Throws(EelPathException::class) - fun parseE(raw: String): Relative = + fun parse(raw: String): Relative = ArrayListEelRelativePath.parse(raw) /** @@ -130,15 +131,15 @@ sealed interface EelPath { */ @JvmStatic @Throws(EelPathException::class) - fun buildE(vararg parts: String): Relative = - buildE(listOf(*parts)) + fun build(vararg parts: String): Relative = + build(listOf(*parts)) /** * The parts of the path must not contain / or \. */ @JvmStatic @Throws(EelPathException::class) - fun buildE(parts: List): Relative = + fun build(parts: List): Relative = ArrayListEelRelativePath.build(parts) @JvmField @@ -151,10 +152,10 @@ sealed interface EelPath { fun startsWith(other: Relative): Boolean @Throws(EelPathException::class) - override fun resolveE(other: Relative): Relative + override fun resolve(other: Relative): Relative @Throws(EelPathException::class) - override fun getChildE(name: String): Relative + override fun getChild(name: String): Relative override fun compareTo(other: Relative): Int @@ -182,18 +183,18 @@ sealed interface EelPath { interface Absolute : EelPath, Comparable { companion object { @JvmStatic - fun parseE(raw: String, os: OS?): Absolute = + fun parse(raw: String, os: OS?): Absolute = ArrayListEelAbsolutePath.parseOrNull(raw, os) ?: throw EelPathException(raw, "Not an absolute path") @JvmStatic @Throws(EelPathException::class) - fun buildE(vararg parts: String): Absolute = - buildE(listOf(*parts), null) + fun build(vararg parts: String): Absolute = + build(listOf(*parts), null) @JvmStatic @Throws(EelPathException::class) - fun buildE(parts: List, os: OS?): Absolute = + fun build(parts: List, os: OS?): Absolute = ArrayListEelAbsolutePath.build(parts, os) } @@ -213,11 +214,11 @@ sealed interface EelPath { /** See [java.nio.file.Path.normalize] */ @Throws(EelPathException::class) - fun normalizeE(): Absolute + fun normalize(): Absolute /** See [java.nio.file.Path.resolve] */ @Throws(EelPathException::class) - override fun resolveE(other: Relative): Absolute + override fun resolve(other: Relative): Absolute /** * See [java.nio.file.Path.relativize]. @@ -228,10 +229,10 @@ sealed interface EelPath { * ``` */ @Throws(EelPathException::class) - fun relativizeE(other: Absolute): Relative + fun relativize(other: Absolute): Relative @Throws(EelPathException::class) - override fun getChildE(name: String): Absolute + override fun getChild(name: String): Absolute fun scan(): Sequence @@ -243,7 +244,7 @@ sealed interface EelPath { } } -operator fun EelPath.div(part: String): EelPath = resolveE(EelPath.Relative.parseE(part)) +operator fun EelPath.div(part: String): EelPath = resolve(EelPath.Relative.parse(part)) @Throws(InvalidPathException::class) fun

EelResult.getOrThrow(): P = getOrThrow { throw InvalidPathException(it.raw, it.reason) } diff --git a/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt b/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt index 73fb3111634c..fbd3cd9dd396 100644 --- a/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt +++ b/platform/eel/tests/com/intellij/platform/eel/path/EelAbsolutePathTest.kt @@ -33,7 +33,7 @@ class EelAbsolutePathTest { for (rawPath in (unixPaths + windowsPaths)) { add(dynamicTest(rawPath) { - val eelPath = EelPath.Absolute.parseE(rawPath, null) + val eelPath = EelPath.Absolute.parse(rawPath, null) eelPath.toString() shouldBe rawPath }) } diff --git a/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt b/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt index b1c87a782cc2..1bc847c7f63b 100644 --- a/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt +++ b/platform/eel/tests/com/intellij/platform/eel/path/EelRelativePathTest.kt @@ -30,8 +30,8 @@ class EelRelativePathTest { abc/./def/../ghi, abc/ghi ./abc/def/../ghi, abc/ghi """) fun normalize(source: String?, expected: String?) { - val sourcePath = EelPath.Relative.parseE(source ?: "") - val expectedPath = EelPath.Relative.parseE(expected ?: "") + val sourcePath = EelPath.Relative.parse(source ?: "") + val expectedPath = EelPath.Relative.parse(expected ?: "") sourcePath.normalize() should be(expectedPath) } @@ -39,9 +39,9 @@ class EelRelativePathTest { inner class getChild { @Test fun positive() { - val empty = EelPath.Relative.buildE() - empty.getChildE("a") should be(EelPath.Relative.buildE("a")) - empty.getChildE("a").getChildE("bc") should be(EelPath.Relative.buildE("a", "bc")) + val empty = EelPath.Relative.build() + empty.getChild("a") should be(EelPath.Relative.build("a")) + empty.getChild("a").getChild("bc") should be(EelPath.Relative.build("a", "bc")) } } @@ -49,11 +49,11 @@ class EelRelativePathTest { inner class resolve { @Test fun `parent directory should persist`() { - val path = EelPath.Relative.parseE("abc/..") - val targetPath = EelPath.Relative.parseE("def") + val path = EelPath.Relative.parse("abc/..") + val targetPath = EelPath.Relative.parse("def") withClue("IjentPath.Relative.resolve must not normalize paths") { - EelPath.Relative.parseE("abc/../def") should be(path.resolveE(targetPath)) + EelPath.Relative.parse("abc/../def") should be(path.resolve(targetPath)) } } } @@ -63,15 +63,15 @@ class EelRelativePathTest { @Test fun positive() { val raw = "a/b/c" - val path = EelPath.Relative.parseE(raw) - val expected = EelPath.Relative.parseE("b") + val path = EelPath.Relative.parse(raw) + val expected = EelPath.Relative.parse("b") expected should be(path.getName(1)) } @Test fun `out of bound`() { val raw = "a/b/c" - val path = EelPath.Relative.parseE(raw) + val path = EelPath.Relative.parse(raw) shouldThrowAny { path.getName(10) @@ -84,14 +84,14 @@ class EelRelativePathTest { @ParameterizedTest @ValueSource(strings = ["a/b", "a/b/c"]) fun `is not null`(raw: String) { - val path = EelPath.Relative.parseE(raw) + val path = EelPath.Relative.parse(raw) path.parent shouldNot be(null) } @ParameterizedTest @ValueSource(strings = ["", "a"]) fun `is null`(raw: String) { - val path = EelPath.Relative.parseE(raw) + val path = EelPath.Relative.parse(raw) path.parent should be(null) } } diff --git a/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt b/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt index b45ca48e2f0a..dcc62746efdc 100644 --- a/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt +++ b/platform/eelProvider/src/com/intellij/platform/eel/impl/local/LocalEelApiImpl.kt @@ -5,7 +5,7 @@ import com.intellij.openapi.util.SystemInfo import com.intellij.platform.eel.* import com.intellij.platform.eel.fs.EelFileSystemPosixApi import com.intellij.platform.eel.fs.EelFileSystemWindowsApi -import com.intellij.platform.eel.fs.getPathE +import com.intellij.platform.eel.fs.getPath import com.intellij.platform.eel.path.EelPath import com.intellij.platform.eel.provider.EelUserPosixInfoImpl import com.intellij.platform.eel.provider.EelUserWindowsInfoImpl @@ -13,7 +13,7 @@ import java.nio.file.Path internal class LocalEelPathMapper(private val eelApi: EelApi) : EelPathMapper { override fun getOriginalPath(path: Path): EelPath.Absolute { - return eelApi.fs.getPathE(path.toString()) + return eelApi.fs.getPath(path.toString()) } override fun toNioPath(path: EelPath.Absolute): Path { diff --git a/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt b/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt index 22c0441edcbe..2aca519983e8 100644 --- a/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt +++ b/platform/eelProvider/src/com/intellij/platform/eel/provider/utils/eelProcessUtils.kt @@ -3,7 +3,7 @@ package com.intellij.platform.eel.provider.utils import com.intellij.execution.process.ProcessOutput import com.intellij.platform.eel.* -import com.intellij.platform.eel.fs.getPathE +import com.intellij.platform.eel.fs.getPath import com.intellij.platform.eel.path.EelPath import com.intellij.util.io.computeDetached import kotlinx.coroutines.DelicateCoroutinesApi @@ -84,6 +84,6 @@ suspend fun EelApi.where(exe: String): EelPath.Absolute? { return null } else { - return fs.getPathE(result.stdout) + return fs.getPath(result.stdout) } } \ No newline at end of file diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt index 7239cf981b32..5a77b8b7125f 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystem.kt @@ -70,8 +70,8 @@ class IjentNioFileSystem internal constructor( is IjentFileSystemPosixApi -> EelPath.Absolute.OS.UNIX is IjentFileSystemWindowsApi -> EelPath.Absolute.OS.WINDOWS } - return EelPath.parseE(first, os) - .resolveE(EelPath.Relative.buildE(*more)) + return EelPath.parse(first, os) + .resolve(EelPath.Relative.build(*more)) .toNioPath() } diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt index 5f423b269219..ca4361a2b3e4 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemProvider.kt @@ -205,7 +205,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() { .getOrThrowFileSystemException() .asSequence() .map { (childName, childStat) -> - val childIjentPath = dir.eelPath.getChildE(childName) + val childIjentPath = dir.eelPath.getChild(childName) val childAttrs = when (childStat) { is EelPosixFileInfo -> IjentNioPosixFileAttributes(childStat) is EelWindowsFileInfo -> TODO() @@ -219,7 +219,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() { .getOrThrowFileSystemException() .asSequence() .map { childName -> - val childIjentPath = dir.eelPath.getChildE(childName) + val childIjentPath = dir.eelPath.getChild(childName) IjentNioPath(childIjentPath, nioFs, null) } } diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt index a65d946d6357..dcc9f9b0ceed 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioFileSystemUtil.kt @@ -12,6 +12,7 @@ import com.intellij.util.text.nullize import kotlinx.coroutines.Dispatchers import java.io.IOException import java.nio.file.* +import kotlin.Throws import kotlin.coroutines.Continuation import kotlin.coroutines.CoroutineContext import kotlin.coroutines.startCoroutine @@ -54,7 +55,7 @@ internal fun Path.toEelPath(): EelPath = isAbsolute -> throw InvalidPathException(toString(), "This path can't be converted to IjentPath") - else -> EelPath.Relative.parseE(toString()) + else -> EelPath.Relative.parse(toString()) } internal fun fsBlocking(body: suspend () -> T): T = invokeSuspending(body) diff --git a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt index 0d1bffdcfb3f..041d15a432c7 100644 --- a/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt +++ b/platform/ijent/impl/src/com/intellij/platform/ijent/community/impl/nio/IjentNioPath.kt @@ -39,7 +39,7 @@ class IjentNioPath internal constructor( override fun getFileName(): IjentNioPath? = EelPath.Relative - .parseE(eelPath.fileName) + .parse(eelPath.fileName) .toNioPath() .takeIf { it.nameCount > 0 } @@ -83,20 +83,20 @@ class IjentNioPath internal constructor( override fun normalize(): IjentNioPath = when (eelPath) { - is EelPath.Absolute -> eelPath.normalizeE().toNioPath() + is EelPath.Absolute -> eelPath.normalize().toNioPath() is EelPath.Relative -> eelPath.normalize().toNioPath() } override fun resolve(other: Path): IjentNioPath = when (val otherIjentPath = other.toEelPath()) { is EelPath.Absolute -> otherIjentPath.toNioPath() // TODO is it the desired behaviour? - is EelPath.Relative -> eelPath.resolveE(otherIjentPath).toNioPath() + is EelPath.Relative -> eelPath.resolve(otherIjentPath).toNioPath() } override fun relativize(other: Path): IjentNioPath = when (val otherIjentPath = other.toEelPath()) { is EelPath.Absolute -> when (eelPath) { - is EelPath.Absolute -> eelPath.relativizeE(otherIjentPath).toNioPath() + is EelPath.Absolute -> eelPath.relativize(otherIjentPath).toNioPath() is EelPath.Relative -> throw InvalidPathException("$this.relativize($other)", "Can't relativize these paths") } @@ -125,7 +125,7 @@ class IjentNioPath internal constructor( override fun toRealPath(vararg options: LinkOption): IjentNioPath = when (eelPath) { is EelPath.Absolute -> - eelPath.normalizeE() + eelPath.normalize() .let { normalizedPath -> if (LinkOption.NOFOLLOW_LINKS in options) normalizedPath diff --git a/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt b/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt index 82f69635fac9..6a9b7cc9fc13 100644 --- a/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt +++ b/platform/platform-impl/src/com/intellij/execution/eel/EelApiWithPathsMapping.kt @@ -7,12 +7,7 @@ import com.intellij.platform.core.nio.fs.MultiRoutingFsPath import com.intellij.platform.eel.* import com.intellij.platform.eel.EelExecApi.ExecuteProcessError import com.intellij.platform.eel.fs.getPath -import com.intellij.platform.eel.fs.EelFileSystemApi -import com.intellij.platform.eel.fs.getPathE import com.intellij.platform.eel.path.EelPath -import com.intellij.platform.eel.path.getOrThrow -import com.intellij.util.awaitCancellationAndInvoke -import kotlinx.coroutines.CoroutineScope import org.jetbrains.annotations.ApiStatus.Internal import java.nio.file.Path import kotlin.io.path.pathString @@ -55,7 +50,7 @@ private class EelEphemeralRootAwareMapper( private val eelApi: EelApiBase, ) : EelPathMapper { override fun getOriginalPath(path: Path): EelPath.Absolute? { - return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPathE(it.toString()) } + return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPath(it.toString()) } } override fun toNioPath(path: EelPath.Absolute): Path {