[kotlin] Enforce source file name in test data

#KTIJ-33060

GitOrigin-RevId: 4250b28f13c3c77ed7f3c78139f6b94349c2d041
This commit is contained in:
Vladimir Dolzhenko
2025-02-19 14:50:02 +00:00
committed by intellij-monorepo-bot
parent d8c9fe3d1f
commit 99e6f2e4b7
23 changed files with 67 additions and 67 deletions
@@ -60,12 +60,14 @@ abstract class AbstractReferenceResolveTest : KotlinLightCodeInsightFixtureTestC
}
}
protected open val replacePlaceholders: Boolean = true
private fun doSingleResolveTest() {
forEachCaret { index, offset ->
val fileText = myFixture.file.text
val expectedResolveData = readResolveData(fileText, getExpectedReferences(fileText, index))
val psiReference = wrapReference(myFixture.file.findReferenceAt(offset))
checkReferenceResolve(expectedResolveData, offset, psiReference, render = { this.render(it) }) { resolveTo ->
checkReferenceResolve(expectedResolveData, offset, psiReference, render = { this.render(it) }, replacePlaceholders = replacePlaceholders) { resolveTo ->
checkResolvedTo(resolveTo)
performAdditionalResolveChecks(listOf(resolveTo))
}
@@ -1,6 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.navigation
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
@@ -18,7 +20,9 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
import org.jetbrains.kotlin.test.util.renderAsGotoImplementation
abstract class AbstractKotlinNavigationToLibrarySourceTest : AbstractReferenceResolveTest() {
@@ -36,12 +40,9 @@ abstract class AbstractKotlinNavigationToLibrarySourceTest : AbstractReferenceRe
}
}
override fun render(element: PsiElement): String {
return when (val navigationElement = element.navigationElement) {
is KtNamedDeclaration -> "(" + (navigationElement.fqName?.asString() ?: "<local>") + ") " + navigationElement.signatureText()
else -> super.render(element)
}
}
override val replacePlaceholders: Boolean = false
override fun render(element: PsiElement): String = renderNavigationElement(element)
override fun tearDown() {
runAll(
@@ -64,5 +65,40 @@ abstract class AbstractKotlinNavigationToLibrarySourceTest : AbstractReferenceRe
return containingFile.text.subSequence(firstElement.startOffset, endOffset?.endOffset ?: lastChild!!.endOffset).toString()
.replace("\n", " ")
}
fun renderNavigationElement(element: PsiElement): String {
fun StringBuilder.renderPackageName(declaration: KtNamedDeclaration) {
if (declaration is KtClassOrObject) {
append(declaration.fqName?.asString() ?: "<local>")
} else {
val classOrObject = declaration.containingClassOrObject
if (classOrObject != null) {
renderPackageName(classOrObject)
} else {
append(declaration.fqName?.asString() ?: "<??>")
}
}
}
return when (val navigationElement = element.navigationElement) {
is KtNamedDeclaration -> buildString {
append("(")
renderPackageName(navigationElement)
append(" @ ")
val virtualFile = navigationElement.containingFile.virtualFile
val jarFileSystem = virtualFile.fileSystem as? JarFileSystem
append(jarFileSystem?.let {
val root = VfsUtilCore.getRootFile(virtualFile)
"${it.protocol}://${root.name}${JarFileSystem.JAR_SEPARATOR}${VfsUtilCore.getRelativeLocation(virtualFile, root)}"
} ?: virtualFile.name)
append(") ")
append(navigationElement.signatureText())
}
else -> {
element.renderAsGotoImplementation()
}
}
}
}
}
@@ -1,23 +1,17 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.k2.navigation
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiReference
import org.jetbrains.kotlin.idea.base.test.IgnoreTests
import org.jetbrains.kotlin.idea.base.test.KotlinTestHelpers
import org.jetbrains.kotlin.idea.k2.navigation.AbstractKotlinNavigationToLibrarySourceTest.Companion.signatureText
import org.jetbrains.kotlin.idea.k2.navigation.AbstractKotlinNavigationToLibrarySourceTest.Companion.renderNavigationElement
import org.jetbrains.kotlin.idea.multiplatform.setupMppProjectFromDirStructure
import org.jetbrains.kotlin.idea.resolve.AbstractReferenceResolveTest
import org.jetbrains.kotlin.idea.resolve.AbstractReferenceResolveTest.Companion.checkReferenceResolve
import org.jetbrains.kotlin.idea.resolve.AbstractReferenceResolveTest.Companion.readResolveData
import org.jetbrains.kotlin.idea.test.*
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.test.util.renderAsGotoImplementation
import java.io.File
abstract class AbstractMultiModuleNavigationTest: AbstractMultiModuleTest() {
@@ -89,38 +83,6 @@ abstract class AbstractMultiModuleNavigationTest: AbstractMultiModuleTest() {
}
}
private fun render(element: PsiElement): String {
fun StringBuilder.renderPackageName(declaration: KtNamedDeclaration) {
if (declaration is KtClassOrObject) {
append(declaration.fqName?.asString() ?: "<local>")
} else {
val classOrObject = declaration.containingClassOrObject
if (classOrObject != null) {
renderPackageName(classOrObject)
} else {
append("<??>")
}
}
}
return when (val navigationElement = element.navigationElement) {
is KtNamedDeclaration -> buildString {
append("(")
renderPackageName(navigationElement)
append(" @ ")
val virtualFile = navigationElement.containingFile.virtualFile
val jarFileSystem = virtualFile.fileSystem as? JarFileSystem
append(jarFileSystem?.let {
val root = VfsUtilCore.getRootFile(virtualFile)
"${it.protocol}://${root.name}${JarFileSystem.JAR_SEPARATOR}${VfsUtilCore.getRelativeLocation(virtualFile, root)}"
} ?: virtualFile.name)
append(")")
append(navigationElement.signatureText())
}
else -> {
element.renderAsGotoImplementation()
}
}
}
private fun render(element: PsiElement): String = renderNavigationElement(element)
}
@@ -1,3 +1,3 @@
val version = Kotlin<caret>Version(2, 0, 0)
// REF: (kotlin.KotlinVersion @ jar://kotlin-stdlib-common-sources.jar!/commonMain/kotlin/util/KotlinVersion.kt)(public val major: Int, public val minor: Int, public val patch: Int)
// REF: (kotlin.KotlinVersion @ jar://kotlin-stdlib-common-sources.jar!/commonMain/kotlin/util/KotlinVersion.kt) (public val major: Int, public val minor: Int, public val patch: Int)
@@ -2,4 +2,4 @@ fun a() {
val e: IllegalA<caret>rgumentException = TODO()
}
// REF: (kotlin.IllegalArgumentException) @SinceKotlin("1.1") public actual typealias IllegalArgumentException = java.lang.IllegalArgumentException
// REF: (kotlin.IllegalArgumentException @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/TypeAliases.kt) @SinceKotlin("1.1") public actual typealias IllegalArgumentException = java.lang.IllegalArgumentException
@@ -3,4 +3,4 @@ class FooWithField {
val i: Int = 4
}
// REF: (kotlin.jvm.JvmField) @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.BINARY) @MustBeDocumented public actual annotation class JvmField
// REF: (kotlin.jvm.JvmField @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/jvm/annotations/JvmPlatformAnnotations.kt) @Target(AnnotationTarget.FIELD) @Retention(AnnotationRetention.BINARY) @MustBeDocumented public actual annotation class JvmField
@@ -2,4 +2,4 @@ fun a() {
val value: In<caret>t = 1
}
// REF: (kotlin.Int) public class Int private constructor()
// REF: (kotlin.Int @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/Primitives.kt) public class Int private constructor()
@@ -2,4 +2,4 @@ fun a() {
val list: Abstrac<caret>tList<Int> = TODO()
}
// REF: (kotlin.collections.AbstractList) @SinceKotlin("1.1") public abstract class AbstractList<out E> protected constructor()
// REF: (kotlin.collections.AbstractList @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/collections/AbstractList.kt) @SinceKotlin("1.1") public abstract class AbstractList<out E> protected constructor()
@@ -3,4 +3,4 @@
level = DeprecationLevel.ERR<caret>OR
)
val p = 0
// REF: (kotlin.DeprecationLevel.ERROR) ERROR
// REF: (kotlin.DeprecationLevel.ERROR @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/Annotations.kt) ERROR
@@ -2,4 +2,4 @@ fun a() {
Char<caret>Progression.fromClosedRange('a', 'b', 1)
}
// REF: (kotlin.ranges.CharProgression.Companion) public companion object
// REF: (kotlin.ranges.CharProgression.Companion @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/ranges/Progressions.kt) public companion object
@@ -1,3 +1,3 @@
abstract class MyAbstractList<out E> : Abstract<caret>List<E>() {}
// REF: (<local>) protected constructor()
// REF: (kotlin.collections.AbstractList @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/collections/AbstractList.kt) protected constructor()
@@ -2,4 +2,4 @@ fun a() {
val array = Byte<caret>Array(10)
}
// REF: (<local>) public constructor(size: Int)
// REF: (kotlin.ByteArray @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/Arrays.kt) public constructor(size: Int)
@@ -2,4 +2,4 @@ fun a() {
val array = Byte<caret>Array(10) { 1.toByte() }
}
// REF: (<local>) @Suppress("WRONG_MODIFIER_TARGET") public inline constructor(size: Int, init: (Int) -> Byte)
// REF: (kotlin.ByteArray @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/Arrays.kt) @Suppress("WRONG_MODIFIER_TARGET") public inline constructor(size: Int, init: (Int) -> Byte)
@@ -2,4 +2,4 @@ fun a() {
listOf(1).listIt<caret>erator(1)
}
// REF: (kotlin.collections.List.listIterator) public actual fun listIterator(index: Int): ListIterator<E>
// REF: (kotlin.collections.List @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/Collections.kt) public actual fun listIterator(index: Int): ListIterator<E>
@@ -2,4 +2,4 @@ fun a() {
li<caret>stOf()
}
// REF: (kotlin.collections.listOf) @kotlin.internal.InlineOnly public inline fun <T> listOf(): List<T>
// REF: (kotlin.collections.listOf @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/collections/Collections.kt) @kotlin.internal.InlineOnly public inline fun <T> listOf(): List<T>
@@ -2,4 +2,4 @@ fun a() {
li<caret>stOf(1)
}
// REF: (kotlin.collections.listOf) public actual fun <T> listOf(element: T): List<T>
// REF: (kotlin.collections.listOf @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/collections/CollectionsJVM.kt) public actual fun <T> listOf(element: T): List<T>
@@ -2,4 +2,4 @@ fun a() {
li<caret>stOf(1, 2)
}
// REF: (kotlin.collections.listOf) public fun <T> listOf(vararg elements: T): List<T>
// REF: (kotlin.collections.listOf @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/collections/Collections.kt) public fun <T> listOf(vararg elements: T): List<T>
@@ -2,4 +2,4 @@ fun a() {
charArrayOf('1', '2').m<caret>ap { it }
}
// REF: (kotlin.collections.map) public inline fun <R> CharArray.map(transform: (Char) -> R): List<R>
// REF: (kotlin.collections.map @ jar://kotlin-stdlib-sources.jar!/commonMain/generated/_Arrays.kt) public inline fun <R> CharArray.map(transform: (Char) -> R): List<R>
@@ -2,4 +2,4 @@ fun a() {
intArrayOf(1, 1).m<caret>ap { it }
}
// REF: (kotlin.collections.map) public inline fun <R> IntArray.map(transform: (Int) -> R): List<R>
// REF: (kotlin.collections.map @ jar://kotlin-stdlib-sources.jar!/commonMain/generated/_Arrays.kt) public inline fun <R> IntArray.map(transform: (Int) -> R): List<R>
@@ -2,4 +2,4 @@ fun a() {
CharProgression.fromClosed<caret>Range('a', 'b', 1)
}
// REF: (kotlin.ranges.CharProgression.Companion.fromClosedRange) public fun fromClosedRange(rangeStart: Char, rangeEnd: Char, step: Int): CharProgression
// REF: (kotlin.ranges.CharProgression.Companion @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/ranges/Progressions.kt) public fun fromClosedRange(rangeStart: Char, rangeEnd: Char, step: Int): CharProgression
@@ -3,4 +3,4 @@ fun bbb(mg: MatchGroup) {
val s = mg.<caret>value
}
// REF: (kotlin.text.MatchGroup.value) public actual val value: String
// REF: (kotlin.text.MatchGroup @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/text/regex/Regex.kt) public actual val value: String
@@ -3,4 +3,4 @@ fun a() {
list.si<caret>ze
}
// REF: (kotlin.collections.List.size) actual override val size: Int
// REF: (kotlin.collections.List @ jar://kotlin-stdlib-sources.jar!/jvmMain/kotlin/Collections.kt) actual override val size: Int
@@ -4,4 +4,4 @@ fun a() {
val a = P<caret>I
}
// REF: (kotlin.math.PI) @SinceKotlin("1.2") public const val PI: Double
// REF: (kotlin.math.PI @ jar://kotlin-stdlib-sources.jar!/commonMain/kotlin/MathH.kt) @SinceKotlin("1.2") public const val PI: Double