Change FUNCTION_EXPRESSION_WITH_NAME severity to ERROR
Also drop deprecation related parts and get rid of usages of this `feature` within testData
This commit is contained in:
@@ -83,7 +83,6 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
|
||||
|
||||
private val cleanupDiagnosticsFactories = setOf(
|
||||
Errors.MISSING_CONSTRUCTOR_KEYWORD,
|
||||
Errors.FUNCTION_EXPRESSION_WITH_NAME,
|
||||
Errors.UNNECESSARY_NOT_NULL_ASSERTION,
|
||||
Errors.UNNECESSARY_SAFE_CALL,
|
||||
Errors.USELESS_CAST,
|
||||
|
||||
@@ -303,8 +303,7 @@ public class QuickFixRegistrar : QuickFixContributor {
|
||||
MISSING_CONSTRUCTOR_KEYWORD.registerFactory(MissingConstructorKeywordFix,
|
||||
MissingConstructorKeywordFix.createWholeProjectFixFactory())
|
||||
|
||||
FUNCTION_EXPRESSION_WITH_NAME.registerFactory(RemoveNameFromFunctionExpressionFix,
|
||||
RemoveNameFromFunctionExpressionFix.createWholeProjectFixFactory())
|
||||
FUNCTION_EXPRESSION_WITH_NAME.registerFactory(RemoveNameFromFunctionExpressionFix)
|
||||
|
||||
UNRESOLVED_REFERENCE.registerFactory(ReplaceObsoleteLabelSyntaxFix,
|
||||
ReplaceObsoleteLabelSyntaxFix.createWholeProjectFixFactory())
|
||||
|
||||
@@ -16,18 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.kotlin.JetNodeTypes
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getNextSiblingIgnoringWhitespaceAndComments
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
public class RemoveNameFromFunctionExpressionFix(element: JetNamedFunction) : JetIntentionAction<JetNamedFunction>(element), CleanupFix {
|
||||
@@ -41,24 +36,6 @@ public class RemoveNameFromFunctionExpressionFix(element: JetNamedFunction) : Je
|
||||
override fun createAction(diagnostic: Diagnostic) =
|
||||
diagnostic.createIntentionForFirstParentOfType(::RemoveNameFromFunctionExpressionFix)
|
||||
|
||||
public fun createWholeProjectFixFactory(): JetSingleIntentionActionFactory = createIntentionFactory {
|
||||
JetWholeProjectForEachElementOfTypeFix.createByPredicate<JetNamedFunction>(
|
||||
predicate = { isFunctionExpression(it) },
|
||||
taskProcessor = { removeNameFromFunction(it) },
|
||||
name = "Remove identifier from function expressions in the whole project"
|
||||
)
|
||||
}
|
||||
|
||||
private fun isFunctionExpression(function: JetNamedFunction): Boolean {
|
||||
var parent = function.getParent()
|
||||
|
||||
while (parent is JetAnnotatedExpression || parent is JetLabeledExpression) {
|
||||
parent = parent.getParent()
|
||||
}
|
||||
|
||||
return function.isLocal() && parent !is JetBlockExpression
|
||||
}
|
||||
|
||||
private fun removeNameFromFunction(function: JetNamedFunction) {
|
||||
var wereAutoLabelUsages = false
|
||||
val name = function.getNameAsName() ?: return
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ fun main(args: Array<String>) {
|
||||
// RESULT: 1: I
|
||||
// STEP_INTO: 2
|
||||
//Breakpoint!
|
||||
a.foo (fun b(it): A { return a })
|
||||
a.foo (fun(it): A { return a })
|
||||
}
|
||||
|
||||
class A {
|
||||
|
||||
@@ -4,8 +4,6 @@ import pack.oldFun3
|
||||
|
||||
class A private()
|
||||
|
||||
val x = fun foo(x: String) { }
|
||||
|
||||
fun foo() {
|
||||
@loop
|
||||
for (i in 1..100) {
|
||||
|
||||
@@ -3,8 +3,6 @@ import pack.oldFun2 // should not be removed for non-deprecated overload used
|
||||
|
||||
class A private constructor()
|
||||
|
||||
val x = fun(x: String) { }
|
||||
|
||||
fun foo() {
|
||||
loop@
|
||||
for (i in 1..100) {
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
fun main() {
|
||||
(fun() {})
|
||||
}
|
||||
Vendored
-46
@@ -1,46 +0,0 @@
|
||||
// "Remove identifier from function expressions in the whole project" "true"
|
||||
|
||||
inline fun run(block: () -> Unit) = block()
|
||||
annotation class ann
|
||||
|
||||
fun foo() {
|
||||
l2@ @ann l2@ fun local() {
|
||||
run(l1@ fun() { return@l1 })
|
||||
|
||||
run(label@ expr@ fun() {
|
||||
return@label
|
||||
return@expr
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
fun bar() {
|
||||
run(toRun@ fun() {
|
||||
if (1 == 1) return@toRun
|
||||
return@bar
|
||||
})
|
||||
|
||||
run(
|
||||
/* abc */ fun /* cde */ () {
|
||||
return@bar
|
||||
}
|
||||
)
|
||||
|
||||
run(
|
||||
/* abc */
|
||||
foo@ fun /* cde */ () {
|
||||
return@foo
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init {
|
||||
(foo@ fun A.() {
|
||||
(fun() {
|
||||
val x = 1
|
||||
})
|
||||
return@foo
|
||||
})
|
||||
}
|
||||
}
|
||||
Vendored
-46
@@ -1,46 +0,0 @@
|
||||
// "Remove identifier from function expressions in the whole project" "true"
|
||||
|
||||
inline fun run(block: () -> Unit) = block()
|
||||
annotation class ann
|
||||
|
||||
fun foo() {
|
||||
l2@ @ann l2@ fun local() {
|
||||
run(l1@ fun() { return@l1 })
|
||||
|
||||
run(label@ fun expr<caret>() {
|
||||
return@label
|
||||
return@expr
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
fun bar() {
|
||||
run(fun toRun() {
|
||||
if (1 == 1) return@toRun
|
||||
return@bar
|
||||
})
|
||||
|
||||
run(
|
||||
/* abc */ fun /* cde */ toRun() {
|
||||
return@bar
|
||||
}
|
||||
)
|
||||
|
||||
run(
|
||||
/* abc */
|
||||
fun /* cde */ foo() {
|
||||
return@foo
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
init {
|
||||
(fun A.foo() {
|
||||
(fun bar() {
|
||||
val x = 1
|
||||
})
|
||||
return@foo
|
||||
})
|
||||
}
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
fun main() {
|
||||
(fun foo() {})
|
||||
}
|
||||
@@ -1129,20 +1129,6 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/migration/removeNameFromFunctionExpression")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class RemoveNameFromFunctionExpression extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInRemoveNameFromFunctionExpression() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/removeNameFromFunctionExpression"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("manyFilesMuitliple.before.Main.kt")
|
||||
public void testManyFilesMuitliple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/removeNameFromFunctionExpression/manyFilesMuitliple.before.Main.kt");
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers")
|
||||
|
||||
Reference in New Issue
Block a user