"Go to Type Declaration" is broken for stdlib types (KT-13001)

#KT-13001Fixed
This commit is contained in:
Nikolay Krasko
2016-12-19 22:00:38 +03:00
parent 6ca5ba3615
commit 2500dc9bb1
4 changed files with 48 additions and 10 deletions
@@ -36,8 +36,6 @@ class KotlinTypeDeclarationProvider : TypeDeclarationProvider {
val type = callableDescriptor.returnType ?: return emptyArray()
val classifierDescriptor = type.constructor.declarationDescriptor ?: return emptyArray()
val typeElement = DescriptorToSourceUtils.descriptorToDeclaration(classifierDescriptor) ?: return emptyArray()
return arrayOf(typeElement)
return DescriptorToSourceUtilsIde.getAllDeclarations(symbol.project, classifierDescriptor).toTypedArray()
}
}
@@ -0,0 +1,8 @@
// FILE: before.kt
fun foo(a: Any) {
val b = 1
foo(<caret>b)
}
// FILE: after.kt
public class <caret>Int private constructor() : Number(), Comparable<Int> {
@@ -18,12 +18,15 @@ package org.jetbrains.kotlin.idea.navigation
import com.intellij.codeInsight.CodeInsightActionHandler
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert
abstract class AbstractGotoActionTest : LightCodeInsightFixtureTestCase() {
abstract class AbstractGotoActionTest : KotlinLightCodeInsightFixtureTestCase() {
protected abstract val actionName: String
protected fun doTest(testPath: String) {
@@ -31,12 +34,35 @@ abstract class AbstractGotoActionTest : LightCodeInsightFixtureTestCase() {
myFixture.configureByText(KotlinFileType.INSTANCE, parts[0])
val gotoSuperAction = ActionManager.getInstance().getAction(actionName) as CodeInsightActionHandler
gotoSuperAction.invoke(project, myFixture.editor, myFixture.file)
val gotoAction = ActionManager.getInstance().getAction(actionName) as CodeInsightActionHandler
gotoAction.invoke(project, myFixture.editor, myFixture.file)
val text = myFixture.getDocument(myFixture.file).text
val afterText = StringBuilder(text).insert(editor.caretModel.offset, "<caret>").toString()
val fileEditorManager = FileEditorManager.getInstance(myFixture.project) as FileEditorManagerEx
val currentEditor = fileEditorManager.selectedTextEditor ?: editor
Assert.assertEquals(parts[1], afterText)
if (currentEditor == editor) {
val text = myFixture.getDocument(myFixture.file).text
val afterText = StringBuilder(text).insert(editor.caretModel.offset, "<caret>").toString()
Assert.assertEquals(parts[1], afterText)
}
else {
val fileOffset = currentEditor.caretModel.offset
val lineNumber = currentEditor.document.getLineNumber(fileOffset)
val lineStart = currentEditor.document.getLineStartOffset(lineNumber)
val lineEnd = currentEditor.document.getLineEndOffset(lineNumber)
val inLineOffset = fileOffset - lineStart
val line = currentEditor.document.getText(TextRange(lineStart, lineEnd))
val withCaret = with(StringBuilder()) {
append(line)
insert(inLineOffset, "<caret>")
toString()
}
Assert.assertEquals(parts[1], withCaret)
}
}
override fun getProjectDescriptor() = getProjectDescriptorFromTestName()
}
@@ -36,6 +36,12 @@ public class GotoTypeDeclarationTestGenerated extends AbstractGotoTypeDeclaratio
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/navigation/gotoTypeDeclaration"), Pattern.compile("^(.+)\\.test$"), TargetBackend.ANY, true);
}
@TestMetadata("builtinTypeStdlib.test")
public void testBuiltinTypeStdlib() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoTypeDeclaration/builtinTypeStdlib.test");
doTest(fileName);
}
@TestMetadata("explicitParameterInLambda.test")
public void testExplicitParameterInLambda() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoTypeDeclaration/explicitParameterInLambda.test");