Cleanup: make single KtExpression.isElseIf
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<KtExpressionWithLabel> {
|
||||
it is KtBreakExpression || it is KtContinueExpression
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+1
-7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user