mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
[kotlin] workaround for function presentation with functional types
^KTIJ-31321 fixed GitOrigin-RevId: fb9e09070ca7e8f89f498fe4a883f6c2f3d89561
This commit is contained in:
committed by
intellij-monorepo-bot
parent
93a62f9d5c
commit
d17f70059a
@@ -91,21 +91,33 @@ open class KotlinFunctionPresentation(
|
||||
) : KotlinDefaultNamedDeclarationPresentation(function) {
|
||||
override fun getPresentableText(): String {
|
||||
return buildString {
|
||||
function.receiverTypeReference?.getTypeText()?.let {
|
||||
append(StringUtil.getShortName(it))
|
||||
append(".")
|
||||
val receiverTypeText = getTrimmedTypeText(function.receiverTypeReference)
|
||||
if (receiverTypeText.isNotEmpty()) {
|
||||
append("$receiverTypeText.")
|
||||
}
|
||||
|
||||
name?.let { append(it) }
|
||||
|
||||
append("(")
|
||||
append(function.valueParameters.joinToString {
|
||||
(if (it.isVarArg) "vararg " else "") + StringUtil.getShortName(it.typeReference?.getTypeText() ?: "")
|
||||
val typeReference = it.typeReference
|
||||
(if (it.isVarArg) "vararg " else "") + getTrimmedTypeText(typeReference)
|
||||
})
|
||||
append(")")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getTrimmedTypeText(typeReference: KtTypeReference?): String {
|
||||
val typeText = when (typeReference?.typeElement) {
|
||||
null -> ""
|
||||
is KtFunctionType -> typeReference.getTypeText()
|
||||
else -> {
|
||||
StringUtil.getShortName(typeReference.getTypeText())
|
||||
}
|
||||
}
|
||||
return typeText
|
||||
}
|
||||
|
||||
override fun getLocationString(): String? {
|
||||
if (function is KtConstructor<*>) {
|
||||
val name = function.getContainingClassOrObject().fqName ?: return null
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.idea.base.plugin.KotlinPluginMode
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.junit.Assert
|
||||
|
||||
class KotlinPresentationTest: KotlinLightCodeInsightFixtureTestCase() {
|
||||
override val pluginMode: KotlinPluginMode = KotlinPluginMode.K2
|
||||
fun testFunctionPresentation() {
|
||||
val file = myFixture.configureByText("a.kt", "fun <T> (() -> kotlin.Boolean).foo(p: T.() -> kotlin.Boolean) {}") as KtFile
|
||||
val function = file.declarations[0] as KtFunction
|
||||
val presentableText = function.presentation!!.presentableText
|
||||
Assert.assertEquals("(() -> kotlin.Boolean).foo(T.() -> kotlin.Boolean)", presentableText)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user