Skip to content

Commit

Permalink
Remove FilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
3flex committed Apr 27, 2024
1 parent cf59aa1 commit 8e7ed97
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 62 deletions.
10 changes: 0 additions & 10 deletions detekt-psi-utils/api/detekt-psi-utils.api
Expand Up @@ -3,15 +3,6 @@ public final class io/github/detekt/psi/AnnotationExcluder {
public final fun shouldExclude (Ljava/util/List;)Z
}

public final class io/github/detekt/psi/FilePath {
public fun <init> (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/nio/file/Path;)V
public synthetic fun <init> (Ljava/nio/file/Path;Ljava/nio/file/Path;Ljava/nio/file/Path;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getAbsolutePath ()Ljava/nio/file/Path;
public final fun getBasePath ()Ljava/nio/file/Path;
public final fun getRelativePath ()Ljava/nio/file/Path;
public fun toString ()Ljava/lang/String;
}

public abstract class io/github/detekt/psi/FunctionMatcher {
public static final field Companion Lio/github/detekt/psi/FunctionMatcher$Companion;
public abstract fun match (Lorg/jetbrains/kotlin/descriptors/CallableDescriptor;)Z
Expand Down Expand Up @@ -40,7 +31,6 @@ public final class io/github/detekt/psi/KtFilesKt {
public static final fun getAbsolutePath (Lorg/jetbrains/kotlin/com/intellij/psi/PsiFile;)Ljava/nio/file/Path;
public static final fun getLineAndColumnInPsiFile (Lorg/jetbrains/kotlin/com/intellij/psi/PsiFile;Lorg/jetbrains/kotlin/com/intellij/openapi/util/TextRange;)Lorg/jetbrains/kotlin/diagnostics/PsiDiagnosticUtils$LineAndColumn;
public static final fun setAbsolutePath (Lorg/jetbrains/kotlin/com/intellij/psi/PsiFile;Ljava/nio/file/Path;)V
public static final fun toFilePath (Lorg/jetbrains/kotlin/com/intellij/psi/PsiFile;)Lio/github/detekt/psi/FilePath;
}

public final class io/gitlab/arturbosch/detekt/rules/AllowedExceptionNamePatternKt {
Expand Down
39 changes: 0 additions & 39 deletions detekt-psi-utils/src/main/kotlin/io/github/detekt/psi/KtFiles.kt
Expand Up @@ -36,45 +36,6 @@ instead.
*/
fun PsiFile.absolutePath(): Path = absolutePath ?: Path(virtualFile.path)

/**
* Represents both absolute path and relative path if available.
*/
class FilePath(
val absolutePath: Path,
val basePath: Path? = null,
val relativePath: Path? = null
) {

init {
require(
basePath == null ||
relativePath == null ||
absolutePath == basePath.resolve(relativePath).normalize()
) {
"Absolute path = $absolutePath much match base path = $basePath and relative path = $relativePath"
}
require(absolutePath.isAbsolute) { "absolutePath should be absolute" }
require(basePath?.isAbsolute != false) { "basePath should be absolute" }
require(relativePath?.isAbsolute != true) { "relativePath should not be absolute" }
}

override fun toString(): String =
"FilePath(absolutePath=$absolutePath, basePath=$basePath, relativePath=$relativePath)"
}

fun PsiFile.toFilePath(): FilePath {
return when {
basePath != null && relativePath != null -> FilePath(
absolutePath = absolutePath(),
basePath = basePath,
relativePath = relativePath
)

basePath == null && relativePath == null -> FilePath(absolutePath = absolutePath())
else -> error("Cannot build a FilePath from base path = $basePath and relative path = $relativePath")
}
}

// #3317 If any rule mutates the PsiElement, searching the original PsiElement may throw an exception.
fun getLineAndColumnInPsiFile(file: PsiFile, range: TextRange): PsiDiagnosticUtils.LineAndColumn? {
return if (file.textLength == 0) {
Expand Down
Expand Up @@ -5,8 +5,6 @@ import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.com.intellij.psi.PsiFile
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import kotlin.io.path.Path
import kotlin.io.path.absolute

class KtFilesSpec {

Expand Down Expand Up @@ -45,15 +43,4 @@ class KtFilesSpec {
}

private fun makeFile(filename: String): PsiFile = FakePsiFile(name = filename)

@Test
fun `FilePath toString`() {
val basePath = Path("/").absolute().resolve("a/b")
val relativePath = Path("c/d")
val absolutePath = Path("/").absolute().resolve("a/b/c/d")
val filePath = FilePath(absolutePath, basePath, relativePath)

assertThat(filePath.toString())
.isEqualTo("FilePath(absolutePath=$absolutePath, basePath=$basePath, relativePath=$relativePath)")
}
}

0 comments on commit 8e7ed97

Please sign in to comment.