提交 2500dc9b 编写于 作者: N Nikolay Krasko

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

 #KT-13001Fixed
上级 6ca5ba36
......@@ -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()
}
}
// 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> {
\ No newline at end of file
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册