Disable "Add labeled return" for suspend lambdas #KT-23126 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-03-06 05:18:25 +03:00
committed by Mikhail Glukhikh
parent 5d1f5d9bca
commit e3a69d118f
3 changed files with 16 additions and 0 deletions
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
@@ -19,6 +20,7 @@ class AddLabeledReturnInLambdaIntention : SelfTargetingRangeIntention<KtBlockExp
override fun applicabilityRange(element: KtBlockExpression): TextRange? {
if (!isApplicableTo(element)) return null
val labelName = element.getParentLambdaLabelName() ?: return null
if (labelName == KtTokens.SUSPEND_KEYWORD.value) return null
text = "Add return@$labelName"
return element.statements.lastOrNull()?.textRange
}
@@ -0,0 +1,8 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun foo() {
suspend {
<caret>true
}
}
@@ -468,6 +468,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("suspend.kt")
public void testSuspend() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addLabeledReturnInLambda/suspend.kt");
doTest(fileName);
}
@TestMetadata("unit.kt")
public void testUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addLabeledReturnInLambda/unit.kt");