diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt index 997f4d82548..177e0ab28be 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/intentions/SelfTargetingIntention.kt @@ -29,6 +29,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection +import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.psiUtil.containsInside import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf @@ -81,7 +82,8 @@ abstract class SelfTargetingIntention( return null } - protected open fun allowCaretInsideElement(element: PsiElement): Boolean = true + protected open fun allowCaretInsideElement(element: PsiElement): Boolean = + element !is KtBlockExpression final override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean { val target = getTarget(editor, file) ?: return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt index 0fc7f1cb862..059656a322c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddBracesIntention.kt @@ -17,10 +17,10 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor -import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.startOffset +import java.lang.IllegalArgumentException class AddBracesIntention : SelfTargetingIntention(KtExpression::class.java, "Add braces") { override fun isApplicableTo(element: KtExpression, caretOffset: Int): Boolean { @@ -32,10 +32,6 @@ class AddBracesIntention : SelfTargetingIntention(KtExpression::cl return true } - override fun allowCaretInsideElement(element: PsiElement): Boolean { - return element !is KtBlockExpression // do not work inside another block to avoid confusion - } - override fun applyTo(element: KtExpression, editor: Editor?) { if (editor == null) throw IllegalArgumentException("This intention requires an editor") val expression = element.getTargetExpression(editor.caretModel.offset)!! diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt index 15a59d59356..6a415775f1e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/AddNameToArgumentIntention.kt @@ -48,7 +48,7 @@ class AddNameToArgumentIntention } override fun allowCaretInsideElement(element: PsiElement) - = element !is KtValueArgumentList && element !is KtContainerNode + = element !is KtValueArgumentList && element !is KtContainerNode && super.allowCaretInsideElement(element) override fun applyTo(element: KtValueArgument, editor: Editor?) { val name = detectNameToAdd(element)!! diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt index d03311e6af8..fc9d4df2418 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertPropertyInitializerToGetterIntention.kt @@ -34,7 +34,10 @@ class ConvertPropertyInitializerToGetterIntention : SelfTargetingRangeIntention< return null } - override fun allowCaretInsideElement(element: PsiElement) = element !is KtDeclaration // do not work inside lambda's in initializer - they can be too big + override fun allowCaretInsideElement(element: PsiElement): Boolean { + // do not work inside lambda's in initializer - they can be too big + return element !is KtDeclaration && super.allowCaretInsideElement(element) + } override fun applyTo(element: KtProperty, editor: Editor?) { convertPropertyInitializerToGetter(element, editor) diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt index 5578c90789c..2e5eba2e6e0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToBlockBodyIntention.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.isNothing import org.jetbrains.kotlin.types.typeUtil.isUnit +import java.lang.RuntimeException class ConvertToBlockBodyIntention : SelfTargetingIntention( KtDeclarationWithBody::class.java, "Convert to block body" @@ -47,7 +48,7 @@ class ConvertToBlockBodyIntention : SelfTargetingIntention(K val block = element.expression as KtBlockExpression block.replace(block.statements.single()) } + + override fun allowCaretInsideElement(element: PsiElement): Boolean { + return element !is KtBlockExpression || element.parent is KtWhenEntry + } }