Fix: Unstable IDE navigation to expect/actual symbols in stdlib

Issue #KT-30790 Fixed
This commit is contained in:
Dmitriy Dolovov
2019-04-05 12:40:35 +07:00
parent 9b5c8bbac9
commit f2d513a39c
2 changed files with 45 additions and 6 deletions
@@ -35,7 +35,6 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.debugText.getDebugText
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
object SourceNavigationHelper {
@@ -191,8 +190,8 @@ object SourceNavigationHelper {
index: StringStubIndexExtension<T>
): T? {
val classFqName = entity.fqName ?: return null
return targetScopes(entity, navigationKind).firstNotNullResult {
index.get(classFqName.asString(), entity.project, it).firstOrNull()
return targetScopes(entity, navigationKind).firstNotNullResult { scope ->
index.get(classFqName.asString(), entity.project, scope).sortedBy { it.isExpectDeclaration() }.firstOrNull()
}
}
@@ -5,9 +5,14 @@
package org.jetbrains.kotlin.idea.decompiler.navigation
import com.intellij.psi.PsiElement
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.test.*
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtModifierListOwner
import org.jetbrains.kotlin.psi.KtTypeAlias
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase() {
@ProjectDescriptorKind(JDK_AND_MULTIPLATFORM_STDLIB_WITH_SOURCES)
@@ -26,6 +31,35 @@ class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase()
)
}
@ProjectDescriptorKind(KOTLIN_JVM_WITH_STDLIB_SOURCES)
fun testNavigateToJVMActualClassDeclarations() {
val checkedTypes = listOf(
// abstract actual classes in JVM:
"AbstractMutableCollection<String>",
"AbstractMutableList<String>",
"AbstractMutableSet<String>",
"AbstractMutableMap<String, String>",
// actual typealiases in JVM:
"ArrayList<String>",
"HashSet<String>"
)
for (type in checkedTypes) {
doTest("fun some() { val collection: <caret>$type? = null }") { navigationElement ->
TestCase.assertTrue(
"$navigationElement is not instance of ${KtClassOrObject::class} or ${KtTypeAlias::class}",
navigationElement is KtClassOrObject || navigationElement is KtTypeAlias
)
TestCase.assertTrue(
"$navigationElement is not actual declaration",
(navigationElement as KtModifierListOwner).hasActualModifier()
)
}
}
}
@ProjectDescriptorKind(KOTLIN_JVM_WITH_STDLIB_SOURCES)
fun testRefToPrintlnWithJVM() {
doTest(
@@ -57,13 +91,19 @@ class LightNavigateToStdlibSourceTest : KotlinLightCodeInsightFixtureTestCase()
override fun getProjectDescriptor() = getProjectDescriptorFromAnnotation()
private fun doTest(text: String, sourceFileName: String) {
private fun doTest(text: String, sourceFileName: String) = doTest(text) { navigationElement ->
// by default check by source file name
TestCase.assertEquals(sourceFileName, navigationElement.containingFile.name)
}
private fun doTest(text: String, checker: (PsiElement) -> Unit) {
myFixture.configureByText(KotlinFileType.INSTANCE, text)
val ref = file.findReferenceAt(editor.caretModel.offset)
val resolve = ref!!.resolve()
val navigationElement = resolve!!.navigationElement
TestCase.assertEquals(sourceFileName, navigationElement.containingFile.name)
checker(navigationElement)
}
}
}