mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Apply RedundantReturnLabelInspection for anonymous functions
^KTIJ-24241 Fixed closes https://github.com/JetBrains/intellij-community/pull/2445 GitOrigin-RevId: 56b0c2b01af8f24c1f04c259585573f000e1a162
This commit is contained in:
committed by
intellij-monorepo-bot
parent
eef148bad0
commit
3b147864f1
+6
-1
@@ -4,6 +4,7 @@ package org.jetbrains.kotlin.idea.codeInsight.inspections.shared
|
||||
import com.intellij.codeInspection.IntentionWrapper
|
||||
import com.intellij.codeInspection.ProblemsHolder
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.inspections.AbstractKotlinInspection
|
||||
import org.jetbrains.kotlin.idea.codeinsights.impl.base.quickFix.RemoveReturnLabelFix
|
||||
@@ -15,7 +16,11 @@ class RedundantReturnLabelInspection : AbstractKotlinInspection() {
|
||||
fun(returnExpression) {
|
||||
val label = returnExpression.getTargetLabel() ?: return
|
||||
val function = returnExpression.getParentOfType<KtNamedFunction>(true, KtLambdaExpression::class.java) ?: return
|
||||
if (function.name == null) return
|
||||
|
||||
if (function.name == null &&
|
||||
analyze(returnExpression) { returnExpression.getReturnTargetSymbol() != function.getSymbol() }
|
||||
) return
|
||||
|
||||
val labelName = label.getReferencedName()
|
||||
holder.registerProblem(
|
||||
label,
|
||||
|
||||
+5
@@ -256,6 +256,11 @@ public abstract class SharedK1LocalInspectionTestGenerated extends AbstractShare
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inAnonymousFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inAnonymousFunction2.kt")
|
||||
public void testInAnonymousFunction2() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inAnonymousFunction2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inFunction.kt")
|
||||
public void testInFunction() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inFunction.kt");
|
||||
|
||||
+5
@@ -256,6 +256,11 @@ public abstract class SharedK2LocalInspectionTestGenerated extends AbstractShare
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inAnonymousFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inAnonymousFunction2.kt")
|
||||
public void testInAnonymousFunction2() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inAnonymousFunction2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inFunction.kt")
|
||||
public void testInFunction() throws Exception {
|
||||
runTest("../testData/inspectionsLocal/redundantReturnLabel/inFunction.kt");
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// PROBLEM: none
|
||||
fun foo(f: (String?) -> Int) {}
|
||||
|
||||
fun test() {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo(f: (String?) -> Int) {}
|
||||
|
||||
fun test() {
|
||||
foo(fun(it: String?): Int {
|
||||
if (it != null) return 1
|
||||
return 0
|
||||
})
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// PROBLEM: none
|
||||
inline fun foo(f: (String?) -> Int): Int = f("")
|
||||
|
||||
fun test(): Int {
|
||||
return foo(fun(it: String?): Int {
|
||||
if (it != null) return@test<caret> 1
|
||||
return 0
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user