Reformat: KotlinInlineValHandler

This commit is contained in:
Mikhail Glukhikh
2018-05-08 15:39:05 +03:00
parent 5246c54dad
commit de85235bd7
@@ -47,7 +47,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHandler() { class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHandler() {
constructor(): this(withPrompt = true) constructor() : this(withPrompt = true)
override fun isEnabledForLanguage(l: Language) = l == KotlinLanguage.INSTANCE override fun isEnabledForLanguage(l: Language) = l == KotlinLanguage.INSTANCE
@@ -92,8 +92,7 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand
readReplacement = buildCodeToInline(declaration, descriptor.type, isTypeExplicit, initialization.value, false, editor) ?: return readReplacement = buildCodeToInline(declaration, descriptor.type, isTypeExplicit, initialization.value, false, editor) ?: return
writeReplacement = null writeReplacement = null
assignmentToDelete = initialization.assignment assignmentToDelete = initialization.assignment
} } else {
else {
readReplacement = getter?.let { readReplacement = getter?.let {
buildCodeToInline(getter, descriptor.type, isTypeExplicit, getter.bodyExpression!!, getter.hasBlockBody(), editor) ?: return buildCodeToInline(getter, descriptor.type, isTypeExplicit, getter.bodyExpression!!, getter.hasBlockBody(), editor) ?: return
} }
@@ -111,8 +110,7 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand
project.checkConflictsInteractively(conflictsCopy) { project.checkConflictsInteractively(conflictsCopy) {
performRefactoring(declaration, readReplacement, writeReplacement, assignmentToDelete, editor, hasHighlightings) performRefactoring(declaration, readReplacement, writeReplacement, assignmentToDelete, editor, hasHighlightings)
} }
} } else {
else {
performRefactoring(declaration, readReplacement, writeReplacement, assignmentToDelete, editor, hasHighlightings) performRefactoring(declaration, readReplacement, writeReplacement, assignmentToDelete, editor, hasHighlightings)
} }
} }
@@ -159,8 +157,7 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand
return null return null
} }
return Initialization(initializerInDeclaration, assignment = null) return Initialization(initializerInDeclaration, assignment = null)
} } else {
else {
val assignment = writeUsages.singleOrNull() val assignment = writeUsages.singleOrNull()
?.getAssignmentByLHS() ?.getAssignmentByLHS()
?.takeIf { it.operationToken == KtTokens.EQ } ?.takeIf { it.operationToken == KtTokens.EQ }
@@ -192,8 +189,7 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand
val statusBar = WindowManager.getInstance().getStatusBar(declaration.project) val statusBar = WindowManager.getInstance().getStatusBar(declaration.project)
statusBar?.info = RefactoringBundle.message("press.escape.to.remove.the.highlighting") statusBar?.info = RefactoringBundle.message("press.escape.to.remove.the.highlighting")
} }
} } else {
else {
dialog.doAction() dialog.doAction()
} }
} }
@@ -205,7 +201,13 @@ class KotlinInlineValHandler(private val withPrompt: Boolean) : InlineActionHand
} }
private fun showErrorHint(project: Project, editor: Editor?, message: String) { private fun showErrorHint(project: Project, editor: Editor?, message: String) {
CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.message("inline.variable.title"), HelpID.INLINE_VARIABLE) CommonRefactoringUtil.showErrorHint(
project,
editor,
message,
RefactoringBundle.message("inline.variable.title"),
HelpID.INLINE_VARIABLE
)
} }
} }