Change Signature: Fix TypeInfo comparison

#KT-13437 Fixed
This commit is contained in:
Alexey Sedunov
2017-04-21 20:46:32 +03:00
parent 8bbf8e185a
commit f70bac019a
5 changed files with 39 additions and 5 deletions
@@ -18,18 +18,22 @@ package org.jetbrains.kotlin.idea.refactoring.changeSignature
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
data class KotlinTypeInfo(val isCovariant: Boolean, val type: KotlinType? = null, val text: String? = null)
fun KotlinTypeInfo.render(): String {
return when {
text != null -> text
type != null -> (if (isCovariant) IdeDescriptorRenderers.SOURCE_CODE else IdeDescriptorRenderers.SOURCE_CODE_NOT_NULL_TYPE_APPROXIMATION).renderType(type)
type != null -> renderType()
else -> ""
}
}
private fun KotlinTypeInfo.renderType(): String {
val renderer = if (isCovariant) IdeDescriptorRenderers.SOURCE_CODE else IdeDescriptorRenderers.SOURCE_CODE_NOT_NULL_TYPE_APPROXIMATION
return renderer.renderType(type!!)
}
fun KotlinTypeInfo.isEquivalentTo(other: KotlinTypeInfo): Boolean {
return if (type != null && other.type != null) TypeUtils.equalTypes(type, other.type) else render() == other.render()
return if (type != null && other.type != null) renderType() == other.renderType() else text == other.text
}
@@ -407,7 +407,7 @@ class KotlinChangeSignatureDialog(
}
}
private fun getTypeCodeFragmentContext(startFrom: PsiElement): KtElement {
fun getTypeCodeFragmentContext(startFrom: PsiElement): KtElement {
return startFrom.parentsWithSelf.mapNotNull {
when {
it is KtNamedFunction -> it.bodyExpression ?: it.valueParameterList
@@ -440,7 +440,7 @@ class KotlinChangeSignatureDialog(
return KotlinChangeSignatureProcessor(project, changeInfo, commandName)
}
private fun PsiCodeFragment?.getTypeInfo(isCovariant: Boolean, forPreview: Boolean): KotlinTypeInfo {
fun PsiCodeFragment?.getTypeInfo(isCovariant: Boolean, forPreview: Boolean): KotlinTypeInfo {
if (this !is KtTypeCodeFragment) return KotlinTypeInfo(isCovariant)
val typeRef = getContentElement()