From b6661710dd54baaf4977c80d10ef7d09da3f1290 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 17 Apr 2018 14:50:12 +0300 Subject: [PATCH] Use expression body: reformat --- .../UseExpressionBodyInspection.kt | 65 ++++++++++--------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt index 8028e0172a0..5ee85a5f4e7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UseExpressionBodyInspection.kt @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.BindingContext class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : AbstractKotlinInspection() { - constructor(): this(convertEmptyToUnit = true) + constructor() : this(convertEmptyToUnit = true) private data class Status(val toHighlight: PsiElement?, val subject: String, val highlightType: ProblemHighlightType) @@ -46,7 +46,8 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs val value = valueStatement.getValue() if (value.anyDescendantOfType( canGoInside = { it !is KtFunctionLiteral && it !is KtNamedFunction && it !is KtPropertyAccessor } - )) return null + ) + ) return null val toHighlight = valueStatement.toHighlight() return when { @@ -58,39 +59,39 @@ class UseExpressionBodyInspection(private val convertEmptyToUnit: Boolean) : Abs } override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean) = - declarationVisitor(fun(declaration) { - declaration as? KtDeclarationWithBody ?: return - val (toHighlightElement, suffix, highlightType) = statusFor(declaration) ?: return - // Change range to start with left brace - val hasHighlighting = highlightType != INFORMATION + declarationVisitor(fun(declaration) { + declaration as? KtDeclarationWithBody ?: return + val (toHighlightElement, suffix, highlightType) = statusFor(declaration) ?: return + // Change range to start with left brace + val hasHighlighting = highlightType != INFORMATION - fun defaultLevel(): HighlightDisplayLevel { - val project = declaration.project - val inspectionProfileManager = ProjectInspectionProfileManager.getInstance(project) - val inspectionProfile = inspectionProfileManager.currentProfile - val state = inspectionProfile.getToolDefaultState("UseExpressionBody", project) - return state.level + fun defaultLevel(): HighlightDisplayLevel { + val project = declaration.project + val inspectionProfileManager = ProjectInspectionProfileManager.getInstance(project) + val inspectionProfile = inspectionProfileManager.currentProfile + val state = inspectionProfile.getToolDefaultState("UseExpressionBody", project) + return state.level + } + + val toHighlightRange = toHighlightElement?.textRange?.let { + if (hasHighlighting && defaultLevel() != HighlightDisplayLevel.DO_NOT_SHOW) { + it + } else { + // Extend range to [left brace..end of highlight element] + val offset = (declaration.blockExpression()?.lBrace?.startOffset ?: it.startOffset) - it.startOffset + it.shiftRight(offset).grown(-offset) } + } - val toHighlightRange = toHighlightElement?.textRange?.let { - if (hasHighlighting && defaultLevel() != HighlightDisplayLevel.DO_NOT_SHOW) { - it - } else { - // Extend range to [left brace..end of highlight element] - val offset = (declaration.blockExpression()?.lBrace?.startOffset ?: it.startOffset) - it.startOffset - it.shiftRight(offset).grown(-offset) - } - } - - holder.registerProblemWithoutOfflineInformation( - declaration, - "Use expression body instead of $suffix", - isOnTheFly, - highlightType, - toHighlightRange?.shiftRight(-declaration.startOffset), - ConvertToExpressionBodyFix() - ) - }) + holder.registerProblemWithoutOfflineInformation( + declaration, + "Use expression body instead of $suffix", + isOnTheFly, + highlightType, + toHighlightRange?.shiftRight(-declaration.startOffset), + ConvertToExpressionBodyFix() + ) + }) private fun KtDeclarationWithBody.findValueStatement(): KtExpression? { val body = blockExpression() ?: return null