Document org.jetbrains.kotlin.idea.intentions.SelfTargetingIntention#allowCaretInsideElement

Also update its usage so that the contract of this method is easier to
understand.
This commit is contained in:
Tianyu Geng
2021-06-17 10:06:47 -07:00
committed by TeamCityServer
parent 5a1223e812
commit abcc716ffc
@@ -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 (!allowCaretInsideElement(element) && element.textRange.containsInside(offset)) break if (element.textRange.containsInside(offset) && !allowCaretInsideElement(element)) break
} }
return null return null
} }
@@ -89,6 +89,7 @@ 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. */
protected open fun allowCaretInsideElement(element: PsiElement): Boolean = element !is KtBlockExpression protected open fun allowCaretInsideElement(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 {