From 4313f249a4a598202ef8667cb3bdcafc5b3ff744 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 15 Sep 2016 14:25:48 +0300 Subject: [PATCH] Presentation: Add file name to the presentation of private top-level declaration #KT-13838 Fixed --- ChangeLog.md | 1 + .../presentation/DeclarationPresenters.kt | 23 +++++++++++++------ .../gotoSymbol/privateTopLevelDeclarations.kt | 19 +++++++++++++++ .../navigation/KotlinGotoTestGenerated.java | 6 +++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt diff --git a/ChangeLog.md b/ChangeLog.md index 452ee641198..cfeae566193 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -106,6 +106,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - Re-highlight only single function after local modifications - [`KT-13474`](https://youtrack.jetbrains.com/issue/KT-13474) Fix performance of typing super call lambda - Show "Variables and values captured in a closure" highlighting only for usages +- [`KT-13838`](https://youtrack.jetbrains.com/issue/KT-13838) Add file name to the presentation of private top-level declaration (Go to symbol, etc.) #### Intention actions, inspections and quickfixes diff --git a/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt b/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt index 3e0f5c48823..7a81f0ced3e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt +++ b/idea/src/org/jetbrains/kotlin/idea/presentation/DeclarationPresenters.kt @@ -23,6 +23,7 @@ import com.intellij.openapi.editor.colors.CodeInsightColors import com.intellij.openapi.editor.colors.TextAttributesKey import com.intellij.openapi.util.Iconable import org.jetbrains.kotlin.idea.KotlinIconProvider +import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* open class KotlinDefaultNamedDeclarationPresentation(private val declaration: KtNamedDeclaration) : ColoredItemPresentation { @@ -38,15 +39,23 @@ open class KotlinDefaultNamedDeclarationPresentation(private val declaration: Kt override fun getLocationString(): String? { val name = declaration.fqName ?: return null - val receiverTypeRef = (declaration as? KtCallableDeclaration)?.receiverTypeReference - if (receiverTypeRef != null) { - return "(for " + receiverTypeRef.text + " in " + name.parent() + ")" - } - else if (declaration.parent is KtFile) { - return "(" + name.parent() + ")" + val qualifiedContainer = name.parent().toString() + val parent = declaration.parent + val containerText = if (parent is KtFile && declaration.hasModifier(KtTokens.PRIVATE_KEYWORD)) { + "${parent.name} in $qualifiedContainer" } else { - return "(in " + name.parent() + ")" + qualifiedContainer + } + val receiverTypeRef = (declaration as? KtCallableDeclaration)?.receiverTypeReference + if (receiverTypeRef != null) { + return "(for " + receiverTypeRef.text + " in " + containerText + ")" + } + else if (parent is KtFile) { + return "(" + containerText + ")" + } + else { + return "(in " + containerText + ")" } } diff --git a/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt b/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt new file mode 100644 index 00000000000..915d2b725e0 --- /dev/null +++ b/idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt @@ -0,0 +1,19 @@ +package foo.bar + +private class test + +private fun Int.test() = 1 + +private fun test() = 2 + +private val Int.test: Int + get() = 3 + +private val test = 4 + +// SEARCH_TEXT: test +// REF: (for Int in privateTopLevelDeclarations.kt in foo.bar).test +// REF: (for Int in privateTopLevelDeclarations.kt in foo.bar).test() +// REF: (privateTopLevelDeclarations.kt in foo.bar).test +// REF: (privateTopLevelDeclarations.kt in foo.bar).test +// REF: (privateTopLevelDeclarations.kt in foo.bar).test() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java index d102754e9a0..0e377f0fe9e 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/KotlinGotoTestGenerated.java @@ -136,6 +136,12 @@ public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest { doSymbolTest(fileName); } + @TestMetadata("privateTopLevelDeclarations.kt") + public void testPrivateTopLevelDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/privateTopLevelDeclarations.kt"); + doSymbolTest(fileName); + } + @TestMetadata("properties.kt") public void testProperties() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/gotoSymbol/properties.kt");