KT-12284 "Add braces to else" has too wide range
#KT-12284 Fixed
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
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
|
||||
@@ -31,6 +32,10 @@ class AddBracesIntention : SelfTargetingIntention<KtExpression>(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)!!
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun foo(p: Int) {
|
||||
if (p == 1) {
|
||||
|
||||
}
|
||||
else if (p == 2) {
|
||||
bar()<caret>
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(){}
|
||||
@@ -90,6 +90,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
public void testAllFilesPresentInAddBraces() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/addBraces"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("notInsideElseIfBlock.kt")
|
||||
public void testNotInsideElseIfBlock() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addBraces/notInsideElseIfBlock.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/addConstModifier")
|
||||
|
||||
Reference in New Issue
Block a user