ChangeVariableTypeFix to not hold KotlinType

This commit is contained in:
Valentin Kipyatkov
2016-03-28 21:46:20 +03:00
parent d5a8d8c393
commit 54a69bf21d
2 changed files with 7 additions and 5 deletions
@@ -26,7 +26,6 @@ change.function.return.type=Change ''{0}'' function return type to ''{1}''
change.no.name.function.return.type=Change function return type to ''{0}''
remove.function.return.type=Remove explicitly specified return type in ''{0}'' function
remove.no.name.function.return.type=Remove explicitly specified function return type
change.element.type=Change ''{0}'' type to ''{1}''
change.function.parameter.type=Change parameter ''{0}'' type of function ''{1}'' to ''{2}''
change.primary.constructor.parameter.type=Change parameter ''{0}'' type of primary constructor of class ''{1}'' to ''{2}''
change.type=Change type from ''{0}'' to ''{1}''
@@ -36,25 +36,28 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import java.util.*
class ChangeVariableTypeFix(element: KtVariableDeclaration, private val type: KotlinType) : KotlinQuickFixAction<KtVariableDeclaration>(element) {
class ChangeVariableTypeFix(element: KtVariableDeclaration, type: KotlinType) : KotlinQuickFixAction<KtVariableDeclaration>(element) {
private val typeContainsError = ErrorUtils.containsErrorType(type)
private val typePresentation = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type)
private val typeSourceCode = IdeDescriptorRenderers.SOURCE_CODE.renderType(type)
override fun getText(): String {
var propertyName = element.fqName?.asString() ?: element.name
return KotlinBundle.message("change.element.type", propertyName, IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type))
return "Change '$propertyName' type to '$typePresentation'"
}
override fun getFamilyName()
= KotlinBundle.message("change.type.family")
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile)
= super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type)
= !typeContainsError && super.isAvailable(project, editor, file)
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val psiFactory = KtPsiFactory(file)
assert(element.nameIdentifier != null) { "ChangeVariableTypeFix applied to variable without name" }
val replacingTypeReference = psiFactory.createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type))
val replacingTypeReference = psiFactory.createType(typeSourceCode)
val toShorten = ArrayList<KtTypeReference>()
toShorten.add(element.setTypeReference(replacingTypeReference)!!)