Clean up KotlinMissingIfBranchFixer
This commit is contained in:
@@ -17,11 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.idea.editor.fixers
|
package org.jetbrains.kotlin.idea.editor.fixers
|
||||||
|
|
||||||
import com.intellij.lang.SmartEnterProcessorWithFixers
|
import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||||
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.psi.KtIfExpression
|
import org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler
|
||||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtIfExpression
|
||||||
|
|
||||||
class KotlinMissingIfBranchFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
class KotlinMissingIfBranchFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
||||||
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
override fun apply(editor: Editor, processor: KotlinSmartEnterHandler, element: PsiElement) {
|
||||||
@@ -32,7 +32,7 @@ class KotlinMissingIfBranchFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSma
|
|||||||
val elseKeyword = element.elseKeyword
|
val elseKeyword = element.elseKeyword
|
||||||
|
|
||||||
if (elseKeyword != null) {
|
if (elseKeyword != null) {
|
||||||
if (elseBranch == null || elseBranch !is KtBlockExpression && elseBranch.startLine(editor.document) > elseKeyword.startLine(editor.document)) {
|
if (elseBranch == null || elseBranch !is KtBlockExpression && elseBranch.startLine(document) > elseKeyword.startLine(document)) {
|
||||||
document.insertString(elseKeyword.range.end, "{}")
|
document.insertString(elseKeyword.range.end, "{}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -41,11 +41,10 @@ class KotlinMissingIfBranchFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSma
|
|||||||
val thenBranch = element.then
|
val thenBranch = element.then
|
||||||
if (thenBranch is KtBlockExpression) return
|
if (thenBranch is KtBlockExpression) return
|
||||||
|
|
||||||
val rParen = element.rightParenthesis
|
val rParen = element.rightParenthesis ?: return
|
||||||
if (rParen == null) return
|
|
||||||
|
|
||||||
var transformingOneLiner = false
|
var transformingOneLiner = false
|
||||||
if (thenBranch != null && thenBranch.startLine(editor.document) == element.startLine(editor.document)) {
|
if (thenBranch != null && thenBranch.startLine(document) == element.startLine(document)) {
|
||||||
if (element.condition != null) return
|
if (element.condition != null) return
|
||||||
transformingOneLiner = true
|
transformingOneLiner = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user