mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
KTIJ-22971 [kotlin] Adjust the applicability range for LabeledReturnAsLastExpressionInLambdaInspection
Now the quick fix would only be applied on the `return@foo` range, and would not be available on the returned expression GitOrigin-RevId: a0e6756cdc12543602da11b0d7418c7659fd1f16
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fbf7da2525
commit
bbee37c964
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.idea.base.psi.getParentLambdaLabelName
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.inspections.AbstractKotlinApplicableInspection
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicabilityRange
|
||||
import org.jetbrains.kotlin.idea.codeinsights.impl.base.applicators.ApplicabilityRanges
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.applicabilityRange
|
||||
import org.jetbrains.kotlin.psi.KtBlockExpression
|
||||
import org.jetbrains.kotlin.psi.KtReturnExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
@@ -51,7 +51,12 @@ internal class LabeledReturnAsLastExpressionInLambdaInspection : AbstractKotlinA
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getApplicabilityRange(): KotlinApplicabilityRange<KtReturnExpression> = ApplicabilityRanges.SELF
|
||||
override fun getApplicabilityRange(): KotlinApplicabilityRange<KtReturnExpression> = applicabilityRange { returnExpression ->
|
||||
val keywordRange = returnExpression.returnKeyword.textRangeInParent
|
||||
val labelRange = returnExpression.labeledExpression?.textRangeInParent
|
||||
|
||||
if (labelRange != null) keywordRange.union(labelRange) else null
|
||||
}
|
||||
|
||||
override fun apply(
|
||||
element: KtReturnExpression,
|
||||
|
||||
@@ -523,6 +523,16 @@ public abstract class SharedK1LocalInspectionTestGenerated extends AbstractShare
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("inLabelRange.kt")
|
||||
public void testInLabelRange() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/inLabelRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inReturnedExpressionRange.kt")
|
||||
public void testInReturnedExpressionRange() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/inReturnedExpressionRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("labeledLambda.kt")
|
||||
public void testLabeledLambda() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/labeledLambda.kt");
|
||||
|
||||
@@ -523,6 +523,16 @@ public abstract class SharedK2LocalInspectionTestGenerated extends AbstractShare
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("inLabelRange.kt")
|
||||
public void testInLabelRange() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/inLabelRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inReturnedExpressionRange.kt")
|
||||
public void testInReturnedExpressionRange() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/inReturnedExpressionRange.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("labeledLambda.kt")
|
||||
public void testLabeledLambda() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/labeledReturnAsLastExpressionInLambda/labeledLambda.kt");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_STDLIB
|
||||
// INTENTION_TEXT: "Remove return@find"
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).find {
|
||||
return@<caret>find true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_STDLIB
|
||||
// INTENTION_TEXT: "Remove return@find"
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).find {
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_STDLIB
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).find {
|
||||
return@find <caret>true
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).find label@{
|
||||
return@label <caret>true
|
||||
<caret>return@label true
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
fun foo() {
|
||||
listOf(1,2,3).find {
|
||||
if (it > 0) {
|
||||
return@find <caret>true
|
||||
<caret>return@find true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
fun foo() {
|
||||
listOf(1,2,3).find {
|
||||
return@find <caret>true
|
||||
<caret>return@find true
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,5 @@
|
||||
// PROBLEM: none
|
||||
|
||||
fun foo(): Boolean {
|
||||
return@foo <caret>true
|
||||
<caret>return@foo true
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
fun foo(): Boolean {
|
||||
listOf(1,2,3).find {
|
||||
return <caret>true
|
||||
<caret>return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
fun foo() {
|
||||
listOf(1,2,3).forEach {
|
||||
listOf(1,2,3).find {
|
||||
return@forEach<caret>
|
||||
<caret>return@forEach
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user