mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[kotlin] Fix rendering of anonymous types
#KTIJ-31102 Fixed GitOrigin-RevId: 0139da9b175c66c65649818dd1f700862a3b76f0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f591065c2e
commit
25beb950c8
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.components.DefaultTypeClassIds
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaClassKind
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaClassSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.*
|
||||
import org.jetbrains.kotlin.idea.codeInsight.hints.KotlinFqnDeclarativeInlayActionHandler
|
||||
@@ -112,7 +113,10 @@ internal fun PresentationTreeBuilder.printKtType(type: KaType) {
|
||||
|
||||
context(KaSession)
|
||||
private fun PresentationTreeBuilder.printNonErrorClassType(type: KaClassType, anotherType: KaClassType? = null) {
|
||||
type.classId.let { printClassId(it, truncatedName(type)) }
|
||||
val truncatedName = truncatedName(type)
|
||||
if (truncatedName.isNotEmpty()) {
|
||||
printClassId(type.classId, truncatedName)
|
||||
}
|
||||
|
||||
val ownTypeArguments = type.typeArguments
|
||||
if (ownTypeArguments.isNotEmpty()) {
|
||||
@@ -155,13 +159,17 @@ private fun PresentationTreeBuilder.printProjection(projection: KaTypeProjection
|
||||
|
||||
|
||||
private fun PresentationTreeBuilder.printClassId(classId: ClassId, name: String) {
|
||||
text(
|
||||
name,
|
||||
InlayActionData(
|
||||
StringInlayActionPayload(classId.asFqNameString()),
|
||||
KotlinFqnDeclarativeInlayActionHandler.HANDLER_NAME
|
||||
if (classId.shortClassName.isSpecial) {
|
||||
text(name)
|
||||
} else {
|
||||
text(
|
||||
name,
|
||||
InlayActionData(
|
||||
StringInlayActionPayload(classId.asFqNameString()),
|
||||
KotlinFqnDeclarativeInlayActionHandler.HANDLER_NAME
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isMutabilityFlexibleType(lower: KaType, upper: KaType): Boolean {
|
||||
@@ -210,10 +218,13 @@ private fun isSimilarTypes(
|
||||
private fun truncatedName(classType: KaClassType): String {
|
||||
val names = classType.qualifiers
|
||||
.mapNotNull {
|
||||
it.symbol.takeUnless {
|
||||
val symbol = it.symbol
|
||||
symbol.takeUnless {
|
||||
(it as? KaNamedClassSymbol)?.classKind == KaClassKind.COMPANION_OBJECT &&
|
||||
it.name == SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT
|
||||
}?.name
|
||||
}?.name ?: symbol.takeIf { (symbol as? KaClassSymbol)?.classKind == KaClassKind.ANONYMOUS_OBJECT }?.let {
|
||||
SpecialNames.ANONYMOUS
|
||||
}
|
||||
}
|
||||
|
||||
names.joinToString(".", transform = Name::asString)
|
||||
|
||||
@@ -185,6 +185,11 @@ public class KtReferenceTypeHintsProviderTestGenerated extends AbstractKtReferen
|
||||
runTest("../../idea/tests/testData/codeInsight/hints/types/ParameterType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateAnonymousObject.kt")
|
||||
public void testPrivateAnonymousObject() throws Exception {
|
||||
runTest("../../idea/tests/testData/codeInsight/hints/types/PrivateAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyType.kt")
|
||||
public void testPropertyType() throws Exception {
|
||||
runTest("../../idea/tests/testData/codeInsight/hints/types/PropertyType.kt");
|
||||
|
||||
@@ -185,6 +185,11 @@ public class KotlinReferenceTypeHintsProviderTestGenerated extends AbstractKotli
|
||||
runTest("testData/codeInsight/hints/types/ParameterType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateAnonymousObject.kt")
|
||||
public void testPrivateAnonymousObject() throws Exception {
|
||||
runTest("testData/codeInsight/hints/types/PrivateAnonymousObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("PropertyType.kt")
|
||||
public void testPropertyType() throws Exception {
|
||||
runTest("testData/codeInsight/hints/types/PropertyType.kt");
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// MODE: all
|
||||
private val list/*<# : |[kotlin.collections.List:kotlin.fqn.class]List|<|<anonymous>|> #>*/ = listOf(object : Iterable<Int> {
|
||||
override fun iterator()/*<# : |[kotlin.collections.Iterator:kotlin.fqn.class]Iterator|<|[kotlin.Int:kotlin.fqn.class]Int|> #>*/ = object : Iterator<Int> {
|
||||
override fun next()/*<# : |[kotlin.Int:kotlin.fqn.class]Int #>*/ = 1
|
||||
override fun hasNext()/*<# : |[kotlin.Boolean:kotlin.fqn.class]Boolean #>*/ = true
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// MODE: all
|
||||
private val list/*<# : |[kotlin.collections.List:kotlin.fqn.class]List|<|[list.<no name provided>:kotlin.fqn.class]`<no name provided>`|> #>*/ = listOf(object : Iterable<Int> {
|
||||
override fun iterator()/*<# : |[kotlin.collections.Iterator:kotlin.fqn.class]Iterator|<|[kotlin.Int:kotlin.fqn.class]Int|> #>*/ = object : Iterator<Int> {
|
||||
override fun next()/*<# : |[kotlin.Int:kotlin.fqn.class]Int #>*/ = 1
|
||||
override fun hasNext()/*<# : |[kotlin.Boolean:kotlin.fqn.class]Boolean #>*/ = true
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user