diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinTypeDeclarationProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinTypeDeclarationProvider.kt index 5a5a1d24633..051da0e6dd8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinTypeDeclarationProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinTypeDeclarationProvider.kt @@ -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() } } diff --git a/idea/testData/navigation/gotoTypeDeclaration/builtinTypeStdlib.test b/idea/testData/navigation/gotoTypeDeclaration/builtinTypeStdlib.test new file mode 100644 index 00000000000..fa52e6196d8 --- /dev/null +++ b/idea/testData/navigation/gotoTypeDeclaration/builtinTypeStdlib.test @@ -0,0 +1,8 @@ +// FILE: before.kt +fun foo(a: Any) { + val b = 1 + foo(b) +} + +// FILE: after.kt +public class Int private constructor() : Number(), Comparable { \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractGotoActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractGotoActionTest.kt index 70b93865d70..7dbe9f16935 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractGotoActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractGotoActionTest.kt @@ -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, "").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, "").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, "") + toString() + } + + Assert.assertEquals(parts[1], withCaret) + } } + + override fun getProjectDescriptor() = getProjectDescriptorFromTestName() } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoTypeDeclarationTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoTypeDeclarationTestGenerated.java index 92ca8447c09..bcfbb96da4c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoTypeDeclarationTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoTypeDeclarationTestGenerated.java @@ -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");