Eel API: rename methods in EelPath: foobarE -> foobar

IJ-CR-147046

(cherry picked from commit 38d4ed91bb138a96c999f140c9671b96dac081a0)

GitOrigin-RevId: 26a58200d6f669137019495176576661bf1c01d2
This commit is contained in:
Vladimir Lagunov
2024-10-17 17:22:09 +02:00
committed by intellij-monorepo-bot
parent 650e3a7632
commit 994d8c338c
13 changed files with 66 additions and 66 deletions

View File

@@ -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}")

View File

@@ -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..<other.nameCount).all { getName(it) == other.getName(it) }
override fun normalizeE(): EelPath.Absolute {
override fun normalize(): EelPath.Absolute {
val result = mutableListOf<String>()
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..<other.nameCount) {
val name = other.getName(index).fileName
@@ -69,7 +70,7 @@ internal class ArrayListEelAbsolutePath private constructor(
return ArrayListEelAbsolutePath(_root, result)
}
override fun getChildE(name: String): EelPath.Absolute {
override fun getChild(name: String): EelPath.Absolute {
val error = checkFileName(name)
return if (error == null)
ArrayListEelAbsolutePath(_root, parts + name)
@@ -108,7 +109,7 @@ internal class ArrayListEelAbsolutePath private constructor(
if (parts.isEmpty()) return EelPath.Relative.EMPTY
require(index in parts.indices) { "$index !in ${parts.indices}" }
return EelPath.Relative.buildE(parts[index])
return EelPath.Relative.build(parts[index])
}
override fun endsWith(other: EelPath.Relative): Boolean {
@@ -134,7 +135,7 @@ internal class ArrayListEelAbsolutePath private constructor(
return nameCount - other.nameCount
}
override fun relativizeE(other: EelPath.Absolute): EelPath.Relative {
override fun relativize(other: EelPath.Absolute): EelPath.Relative {
if (root != other.root) {
throw EelPathException(other.root.toString(), "The other path has a different root")
}
@@ -155,7 +156,7 @@ internal class ArrayListEelAbsolutePath private constructor(
result += other.getName(index).fileName
}
return EelPath.Relative.buildE(result)
return EelPath.Relative.build(result)
}
override fun equals(other: Any?): Boolean =

View File

@@ -1,6 +1,9 @@
// 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 kotlin.Throws
internal class ArrayListEelRelativePath private constructor(
private val parts: List<String>,
) : 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<String>()
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
}

View File

@@ -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<String>): Relative =
fun build(parts: List<String>): 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<Absolute> {
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<String>, os: OS?): Absolute =
fun build(parts: List<String>, 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<Absolute>
@@ -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 <P : EelPath, E : EelPathError> EelResult<P, E>.getOrThrow(): P = getOrThrow { throw InvalidPathException(it.raw, it.reason) }

View File

@@ -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
})
}

View File

@@ -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)
}
}

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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()
}

View File

@@ -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)
}
}

View File

@@ -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 <T> fsBlocking(body: suspend () -> T): T = invokeSuspending(body)

View File

@@ -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

View File

@@ -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 {