diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ChooseValueExpression.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ChooseValueExpression.kt index dfe3b405f48..8c2c416d7d9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ChooseValueExpression.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ChooseValueExpression.kt @@ -25,16 +25,18 @@ import com.intellij.codeInsight.template.impl.TemplateManagerImpl import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil //TODO: move it somewhere else and reuse -abstract class ChooseValueExpression( +abstract class ChooseValueExpression( lookupItems: Collection, - protected val defaultItem: T, + defaultItem: T, private val advertisementText: String? = null ) : Expression() { - protected abstract fun getLookupString(element: T): String protected abstract fun getResult(element: T): String - protected val lookupItems: Array = lookupItems.map { suggestion -> + @Suppress("LeakingThis") + private val defaultItemString = getLookupString(defaultItem) + + private val lookupItems: Array = lookupItems.map { suggestion -> LookupElementBuilder.create(suggestion, getLookupString(suggestion)).withInsertHandler { context, item -> val topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(context.editor) val templateState = TemplateManagerImpl.getTemplateState(topLevelEditor) @@ -52,7 +54,7 @@ abstract class ChooseValueExpression( override fun calculateQuickResult(context: ExpressionContext) = calculateResult(context) - override fun calculateResult(context: ExpressionContext) = TextResult(getLookupString(defaultItem)) + override fun calculateResult(context: ExpressionContext) = TextResult(defaultItemString) override fun getAdvertisingText() = advertisementText } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt index f4cbcb99d15..92b3f413a0f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SpecifyTypeExplicitlyIntention.kt @@ -132,10 +132,14 @@ class SpecifyTypeExplicitlyIntention : } }.ifEmpty { return null } - return object : ChooseValueExpression(types, types.first()) { - override fun getLookupString(element: KotlinType) = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(element) - override fun getResult(element: KotlinType) = IdeDescriptorRenderers.SOURCE_CODE.renderType(element) - } + return TypeChooseValueExpression(types, types.first()) + } + + // Explicit class is used because of KT-20460 + private class TypeChooseValueExpression(items: List, defaultItem: KotlinType) : + ChooseValueExpression(items, defaultItem) { + override fun getLookupString(element: KotlinType) = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(element) + override fun getResult(element: KotlinType) = IdeDescriptorRenderers.SOURCE_CODE.renderType(element) } fun addTypeAnnotation(editor: Editor?, declaration: KtCallableDeclaration, exprType: KotlinType) {