Rename SelfTargetingIntention#allowCaretInsideElement

The current method makes it a bit hard to understand its purpose.
This commit is contained in:
Tianyu Geng
2021-06-17 13:49:11 -07:00
committed by TeamCityServer
parent abcc716ffc
commit 476d1da1cf
7 changed files with 22 additions and 12 deletions
@@ -36,7 +36,8 @@ class HLConvertToBlockBodyIntention :
val reformat: Boolean, val reformat: Boolean,
) : HLApplicatorInput ) : 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<KtDeclarationWithBody> get() = ApplicabilityRanges.SELF override val applicabilityRange: HLApplicabilityRange<KtDeclarationWithBody> get() = ApplicabilityRanges.SELF
@@ -79,7 +79,7 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
if (elementType.isInstance(element) && isApplicableTo(element as TElement, offset)) { if (elementType.isInstance(element) && isApplicableTo(element as TElement, offset)) {
return element return element
} }
if (element.textRange.containsInside(offset) && !allowCaretInsideElement(element)) break if (element.textRange.containsInside(offset) && skipProcessingFurtherElementsAfter(element)) break
} }
return null return null
} }
@@ -89,8 +89,16 @@ abstract class SelfTargetingIntention<TElement : PsiElement>(
return getTarget(offset, file) return getTarget(offset, file)
} }
/** Whether to keep looking for targets after having processed the given element, which contains the cursor. */ /** 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 * */
@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 { final override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean {
if (ApplicationManager.getApplication().isUnitTestMode) { if (ApplicationManager.getApplication().isUnitTestMode) {
@@ -68,7 +68,7 @@ class FunctionWithLambdaExpressionBodyInspection : AbstractKotlinInspection() {
} }
private class AddArrowIntention : SpecifyExplicitLambdaSignatureIntention() { private class AddArrowIntention : SpecifyExplicitLambdaSignatureIntention() {
override fun allowCaretInsideElement(element: PsiElement) = true override fun skipProcessingFurtherElementsAfter(element: PsiElement): Boolean = false
} }
private class RemoveBracesFix : LocalQuickFix { private class RemoveBracesFix : LocalQuickFix {
@@ -46,9 +46,9 @@ class AddNameToArgumentIntention : SelfTargetingIntention<KtValueArgument>(
return true return true
} }
override fun allowCaretInsideElement(element: PsiElement) = element !is KtValueArgumentList && override fun skipProcessingFurtherElementsAfter(element: PsiElement) = element is KtValueArgumentList ||
element !is KtContainerNode && element is KtContainerNode ||
super.allowCaretInsideElement(element) super.skipProcessingFurtherElementsAfter(element)
override fun applyTo(element: KtValueArgument, editor: Editor?) { override fun applyTo(element: KtValueArgument, editor: Editor?) {
apply(element) apply(element)
@@ -33,9 +33,9 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention<
null 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 // 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?) { override fun applyTo(element: KtProperty, editor: Editor?) {
@@ -44,7 +44,8 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention<KtDeclarationWithBody
} }
} }
override fun allowCaretInsideElement(element: PsiElement) = element !is KtDeclaration && super.allowCaretInsideElement(element) override fun skipProcessingFurtherElementsAfter(element: PsiElement) =
element is KtDeclaration || super.skipProcessingFurtherElementsAfter(element)
override fun applyTo(element: KtDeclarationWithBody, editor: Editor?) { override fun applyTo(element: KtDeclarationWithBody, editor: Editor?) {
convert(element, true) convert(element, true)
@@ -93,5 +93,5 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(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
} }