From 65f5dd1dd546ef23fe320e226e8f3f420ad9fdbe Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 14 Jan 2016 17:24:57 +0300 Subject: [PATCH] Got rid of special methods "applyTo" without editor parameter in intentions --- .../AddOperatorModifierIntention.kt | 4 --- .../AnonymousFunctionToLambdaIntention.kt | 6 +--- .../ConvertAssertToIfWithThrowIntention.kt | 6 ++-- .../ConvertToStringTemplateIntention.kt | 6 +--- .../idea/intentions/IfNullToElvisIntention.kt | 7 +--- .../MoveLambdaOutsideParenthesesIntention.kt | 4 --- .../ObjectLiteralToLambdaIntention.kt | 4 --- .../RemoveUnnecessaryParenthesesIntention.kt | 4 --- .../idea/intentions/SimplifyForIntention.kt | 4 --- ...implifyNegatedBinaryExpressionIntention.kt | 4 --- .../intentions/IfThenToElvisIntention.kt | 11 +++--- .../intentions/IfThenToSafeAccessIntention.kt | 11 +++--- .../ReplaceGetOrSetIntention.kt | 4 --- .../kotlin/idea/j2k/J2kPostProcessings.kt | 36 +++++++++---------- 14 files changed, 33 insertions(+), 78 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt index dc9f9f0ca42..29d1eabc2bf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddOperatorModifierIntention.kt @@ -33,10 +33,6 @@ class AddOperatorModifierIntention : SelfTargetingRangeIntention 1 && !KotlinBuiltIns.isAny(valParameters[1].type) } - private fun simplifyConditionIfPossible(ifExpression: KtIfExpression) { + private fun simplifyConditionIfPossible(ifExpression: KtIfExpression, editor: Editor?) { val condition = ifExpression.condition as KtPrefixExpression val simplifier = SimplifyNegatedBinaryExpressionIntention() if (simplifier.isApplicableTo(condition)) { - simplifier.applyTo(condition) + simplifier.applyTo(condition, editor) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt index 592afcc6de8..5d09bcc0d17 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt @@ -43,11 +43,7 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention } override fun applyTo(element: KtBinaryExpression, editor: Editor?) { - applyTo(element) - } - - fun applyTo(element: KtBinaryExpression): KtStringTemplateExpression { - return element.replaced(buildReplacement(element)) + element.replaced(buildReplacement(element)) } fun shouldSuggestToConvert(expression: KtBinaryExpression): Boolean { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt index 364f95dc3e6..b9ea92d4660 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/IfNullToElvisIntention.kt @@ -48,11 +48,6 @@ class IfNullToElvisIntention : SelfTargetingRangeIntention(KtIfE } override fun applyTo(element: KtIfExpression, editor: Editor?) { - val newElvis = applyTo(element) - editor?.caretModel?.moveToOffset(newElvis.right!!.textOffset) - } - - fun applyTo(element: KtIfExpression): KtBinaryExpression { val (initializer, declaration, ifNullExpr) = calcData(element)!! val factory = KtPsiFactory(element) @@ -77,7 +72,7 @@ class IfNullToElvisIntention : SelfTargetingRangeIntention(KtIfE declaration.setType(explicitTypeToAdd) } - return newElvis + editor?.caretModel?.moveToOffset(newElvis.right!!.textOffset) } private data class Data( diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt index 0840b3bbac6..9b384aed3d8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/MoveLambdaOutsideParenthesesIntention.kt @@ -60,8 +60,4 @@ class MoveLambdaOutsideParenthesesIntention : SelfTargetingIntention( "Simplify 'for'" ) { override fun applyTo(element: KtForExpression, editor: Editor?) { - applyTo(element) - } - - fun applyTo(element: KtForExpression) { val (propertiesToRemove, removeSelectorInLoopRange) = collectPropertiesToRemove(element) ?: return val loopRange = element.loopRange ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt index 0cf31cd3dc7..de9e8782594 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/SimplifyNegatedBinaryExpressionIntention.kt @@ -69,10 +69,6 @@ class SimplifyNegatedBinaryExpressionIntention : SelfTargetingRangeIntention(Errors.USELESS_CAST) { element, diagnostic -> val expression = RemoveUselessCastFix.invoke(element) @@ -106,17 +106,15 @@ object J2KPostProcessingRegistrar { } private inline fun > registerIntentionBasedProcessing( - intention: TIntention, - crossinline apply: TIntention.(TElement) -> Unit + intention: TIntention ) { //TODO: replace with optional argument when supported for inline functions - return registerIntentionBasedProcessing(intention, { true }, apply) + return registerIntentionBasedProcessing(intention, { true }) } private inline fun > registerIntentionBasedProcessing( intention: TIntention, - noinline additionalChecker: (TElement) -> Boolean, - crossinline apply: TIntention.(TElement) -> Unit + noinline additionalChecker: (TElement) -> Boolean ) { _processings.add(object : J2kPostProcessing { override fun createAction(element: KtElement, diagnostics: Diagnostics): (() -> Unit)? { @@ -124,7 +122,7 @@ object J2KPostProcessingRegistrar { val tElement = element as TElement if (intention.applicabilityRange(tElement) == null) return null if (!additionalChecker(tElement)) return null - return { intention.apply(element) } + return { intention.applyTo(element, null) } } }) } @@ -172,7 +170,7 @@ object J2KPostProcessingRegistrar { if (element !is KtCallExpression) return null val literalArgument = element.valueArguments.lastOrNull()?.getArgumentExpression()?.unpackFunctionLiteral() ?: return null if (!intention.isApplicableTo(element, literalArgument.textOffset)) return null - return { intention.applyTo(element) } + return { intention.applyTo(element, null) } } } @@ -181,7 +179,7 @@ object J2KPostProcessingRegistrar { override fun createAction(element: KtElement, diagnostics: Diagnostics): (() -> Unit)? { if (element is KtBinaryExpression && intention.isApplicableTo(element) && intention.shouldSuggestToConvert(element)) { - return { intention.applyTo(element) } + return { intention.applyTo(element, null) } } else { return null