diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt index 5aed936b171..057b7152e3a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/KotlinBreadcrumbsInfoProvider.kt @@ -25,6 +25,7 @@ import com.intellij.usageView.UsageViewShortNameLocation import com.intellij.xml.breadcrumbs.BreadcrumbsInfoProvider import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isElseIf import org.jetbrains.kotlin.idea.intentions.loopToCallChain.unwrapIfLabeled import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getCallNameExpression @@ -469,8 +470,6 @@ class KotlinBreadcrumbsInfoProvider : BreadcrumbsInfoProvider() { val ellipsis = "${Typography.ellipsis}" - fun KtIfExpression.isElseIf() = parent.node.elementType == KtNodeTypes.ELSE - fun KtContainerNode.bodyOwner(): KtExpression? { return if (node.elementType == KtNodeTypes.BODY) parent as KtExpression else null } diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CascadeIfInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CascadeIfInspection.kt index 8f2d1902519..0a9c0ac3367 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CascadeIfInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CascadeIfInspection.kt @@ -22,7 +22,7 @@ import com.intellij.codeInspection.ProblemHighlightType import com.intellij.codeInspection.ProblemsHolder import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfToWhenIntention import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isOneLiner -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isIfBranch +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isElseIf import org.jetbrains.kotlin.idea.intentions.branches import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* @@ -44,7 +44,7 @@ class CascadeIfInspection : AbstractKotlinInspection() { it.lastBlockStatementOrThis() is KtIfExpression }) return - if (expression.isIfBranch()) return + if (expression.isElseIf()) return if (expression.anyDescendantOfType { it is KtBreakExpression || it is KtContinueExpression diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/LiftReturnOrAssignmentInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/LiftReturnOrAssignmentInspection.kt index 19f6ee6473c..fff89647eeb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/LiftReturnOrAssignmentInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/LiftReturnOrAssignmentInspection.kt @@ -20,7 +20,7 @@ import com.intellij.codeInspection.* import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedFoldingUtils -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isIfBranch +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isElseIf import org.jetbrains.kotlin.idea.intentions.branchedTransformations.lineCount import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.anyDescendantOfType @@ -32,7 +32,7 @@ class LiftReturnOrAssignmentInspection : AbstractKotlinInspection() { object : KtVisitorVoid() { private fun visitIfOrWhen(expression: KtExpression, keyword: PsiElement) { if (expression.lineCount() > LINES_LIMIT) return - if (expression.isIfBranch()) return + if (expression.isElseIf()) return val foldableReturns = BranchedFoldingUtils.getFoldableReturns(expression) if (foldableReturns?.isNotEmpty() == true) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt index e58f17f6b27..bf3df45f21a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt @@ -262,10 +262,4 @@ internal fun KtExpression.lineCount(): Int { internal fun KtExpression.isOneLiner(): Boolean = lineCount() == 1 -internal fun KtExpression.isIfBranch(): Boolean { - if (parent is KtContainerNodeForControlStructureBody) { - val grandParent = parent.parent - if (grandParent is KtIfExpression && grandParent.`else` == this) return true - } - return false -} +internal fun KtExpression.isElseIf() = parent.node.elementType == KtNodeTypes.ELSE