diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/intentions/HLConvertToBlockBodyIntention.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/intentions/HLConvertToBlockBodyIntention.kt index a5e654a54cc..30c665b0cb9 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/intentions/HLConvertToBlockBodyIntention.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/intentions/HLConvertToBlockBodyIntention.kt @@ -36,7 +36,8 @@ class HLConvertToBlockBodyIntention : val reformat: Boolean, ) : HLApplicatorInput - override fun allowCaretInsideElement(element: PsiElement) = element !is KtDeclaration && super.allowCaretInsideElement(element) + override fun skipProcessingFurtherElementsAfter(element: PsiElement) = + element is KtDeclaration || super.skipProcessingFurtherElementsAfter(element) override val applicabilityRange: HLApplicabilityRange get() = ApplicabilityRanges.SELF diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt index f92ac860257..b06140bb3ab 100644 --- a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt @@ -79,7 +79,7 @@ abstract class SelfTargetingIntention( if (elementType.isInstance(element) && isApplicableTo(element as TElement, offset)) { return element } - if (element.textRange.containsInside(offset) && !allowCaretInsideElement(element)) break + if (element.textRange.containsInside(offset) && skipProcessingFurtherElementsAfter(element)) break } return null } @@ -89,8 +89,16 @@ abstract class SelfTargetingIntention( return getTarget(offset, file) } - /** Whether to keep looking for targets after having processed the given element, which contains the cursor. */ - protected open fun allowCaretInsideElement(element: PsiElement): Boolean = element !is KtBlockExpression + /** Whether to keep looking for targets after having processed the given element, which contains the cursor. + * */ + @Deprecated( + "The name of this method is a bit confusing and hence deprecated.", + replaceWith = ReplaceWith("!skipProcessingFurtherElementsAfter(element)") + ) + protected open fun allowCaretInsideElement(element: PsiElement): Boolean = !skipProcessingFurtherElementsAfter(element) + + /** Whether to skip looking for targets after having processed the given element, which contains the cursor. */ + protected open fun skipProcessingFurtherElementsAfter(element: PsiElement): Boolean = element is KtBlockExpression final override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean { if (ApplicationManager.getApplication().isUnitTestMode) { diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt index 6b79856c89f..4dc4a8b9861 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/FunctionWithLambdaExpressionBodyInspection.kt @@ -68,7 +68,7 @@ class FunctionWithLambdaExpressionBodyInspection : AbstractKotlinInspection() { } private class AddArrowIntention : SpecifyExplicitLambdaSignatureIntention() { - override fun allowCaretInsideElement(element: PsiElement) = true + override fun skipProcessingFurtherElementsAfter(element: PsiElement): Boolean = false } private class RemoveBracesFix : LocalQuickFix { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt index aac71865519..f68bd369bf4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt @@ -46,9 +46,9 @@ class AddNameToArgumentIntention : SelfTargetingIntention( return true } - override fun allowCaretInsideElement(element: PsiElement) = element !is KtValueArgumentList && - element !is KtContainerNode && - super.allowCaretInsideElement(element) + override fun skipProcessingFurtherElementsAfter(element: PsiElement) = element is KtValueArgumentList || + element is KtContainerNode || + super.skipProcessingFurtherElementsAfter(element) override fun applyTo(element: KtValueArgument, editor: Editor?) { apply(element) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index 8ece60bcd21..514c4e1d88b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -33,9 +33,9 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention< null } - override fun allowCaretInsideElement(element: PsiElement): Boolean { + override fun skipProcessingFurtherElementsAfter(element: PsiElement): Boolean { // do not work inside lambda's in initializer - they can be too big - return element !is KtDeclaration && super.allowCaretInsideElement(element) + return element is KtDeclaration || super.skipProcessingFurtherElementsAfter(element) } override fun applyTo(element: KtProperty, editor: Editor?) { diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt index b12aa0e4948..c6195002b17 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt @@ -44,7 +44,8 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention(KtElement::class } } - override fun allowCaretInsideElement(element: PsiElement) = element !is KtBlockExpression || element.parent is KtWhenEntry + override fun skipProcessingFurtherElementsAfter(element: PsiElement) = element is KtBlockExpression && element.parent !is KtWhenEntry }