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:
Denis Zharkov
2015-09-24 15:23:22 +03:00
parent 1d90b2e1fe
commit 3f6cadf9b7
22 changed files with 8 additions and 227 deletions
@@ -354,7 +354,7 @@ public interface Errors {
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetFunction> FUNCTION_DECLARATION_WITH_NO_NAME = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<PsiElement> FUNCTION_EXPRESSION_WITH_NAME = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<PsiElement> FUNCTION_EXPRESSION_WITH_NAME = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR);
@@ -221,7 +221,7 @@ public class DefaultErrorMessages {
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name");
MAP.put(FUNCTION_EXPRESSION_WITH_NAME, "Function expressions with names are deprecated");
MAP.put(FUNCTION_EXPRESSION_WITH_NAME, "Function expressions with names are prohibited");
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class");
MAP.put(FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE, "A function expression is not allowed to specify default values for its parameters");
@@ -1,32 +0,0 @@
val foo1 = fun Any.name(): String {
return "239" + this
}
val foo2 = fun Int.name(i : Int) : Int = this + i
fun <T> fooT1() = fun name(t : T) = t.toString()
annotation class A
fun box() : String {
if(10.foo1() != "23910") return "foo1 fail"
if(10.foo2(1) != 11) return "foo2 fail"
if(1.(fun Int.name() = this + 1)() != 2) return "test 3 failed";
if( (fun name() = 1)() != 1) return "test 4 failed";
if( (fun name(i: Int) = i)(1) != 1) return "test 5 failed";
if( 1.(fun Int.name(i: Int) = i + this)(1) != 2) return "test 6 failed";
if( (fooT1<String>()("mama")) != "mama") return "test 7 failed";
val a = @A fun Int.name() = this + 1 // name
if (1.a() != 2) return "test 8 failed"
val b = ( fun Int.name() = this + 1)
if (1.b() != 2) return "test 9 failed"
val c = (c@ fun Int.name() = this + 1)
if (1.c() != 2) return "test 10 failed"
val d = fun name(): Int { return@name 4}
if (d() != 4) return "test 11 failed"
return "OK"
}
@@ -1,17 +1,10 @@
fun simple() = fun (): Boolean { return true }
fun simpleNamed() = fun name(): Boolean { return true }
fun simpleNamed2() = fun name(): Boolean { return@name true }
fun withLabel() = l@ fun (): Boolean { return@l true }
fun withLabelNamed() = l@ fun name(): Boolean { return@l true }
fun box(): String {
if (!simple()()) return "Test simple failed"
if (!simpleNamed()()) return "Test simpleNamed failed"
if (!simpleNamed2()()) return "Test simpleNamed2 failed"
if (!withLabel()()) return "Test withLabel failed"
if (!withLabelNamed()()) return "Test withLabelNamed failed"
return "OK"
}
@@ -1,6 +1,6 @@
fun test1(): Int {
val inlineX = Inline(9)
return inlineX.calcExt(fun smth(z: Int) = z, 25)
return inlineX.calcExt(fun(z: Int) = z, 25)
}
fun test2(): Int {
@@ -9,15 +9,10 @@ fun test2(): String = (l@ fun (): String {
return "fail"
}) ()
fun test3(): String = (l@ fun bar(): String {
foo { return@bar "OK" }
return "fail"
}) ()
fun box(): String {
if (test() != "OK") return "fail 1: ${test()}"
if (test2() != "OK") return "fail 2: ${test2()}"
return test3()
return "OK"
}
@@ -21,7 +21,7 @@ fun test1(local: Int, nonLocal: String, doNonLocal: Boolean): String {
fun test2(local: Int, nonLocal: String, doNonLocal: Boolean): String {
val localResult = doCall(
fun xxx(): Int {
xxx@ fun(): Int {
if (doNonLocal) {
return@test2 nonLocal
}
@@ -39,7 +39,7 @@ fun test2(local: Int, nonLocal: String, doNonLocal: Boolean): String {
fun test3(local: Int, nonLocal: String, doNonLocal: Boolean): String {
val localResult = doCall(
yy@ fun xxx(): Int {
yy@ fun(): Int {
if (doNonLocal) {
return@test3 nonLocal
}
@@ -1,16 +0,0 @@
val property = fun name() {}
fun box(): String {
val javaClass = property.javaClass
val enclosingMethod = javaClass.getEnclosingMethod()
if (enclosingMethod != null) return "method: $enclosingMethod"
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
if (enclosingClass != "NamedFunctionExpressionInPropertyKt") return "enclosing class: $enclosingClass"
val declaringClass = javaClass.getDeclaringClass()
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
return "OK"
}
@@ -4164,12 +4164,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("functionExpressionWithName.kt")
public void testFunctionExpressionWithName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithName.kt");
doTest(fileName);
}
@TestMetadata("functionExpressionWithThisReference.kt")
public void testFunctionExpressionWithThisReference() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt");
@@ -3384,12 +3384,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib(fileName);
}
@TestMetadata("namedFunctionExpressionInProperty.kt")
public void testNamedFunctionExpressionInProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/namedFunctionExpressionInProperty.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("objectInLambda.kt")
public void testObjectInLambda() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/reflection/enclosing/objectInLambda.kt");
@@ -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
@@ -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 {
-2
View File
@@ -4,8 +4,6 @@ import pack.oldFun3
class A private()
val x = fun foo(x: String) { }
fun foo() {
@loop
for (i in 1..100) {
-2
View File
@@ -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) {
@@ -1,3 +0,0 @@
fun main() {
(fun() {})
}
@@ -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
})
}
}
@@ -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
})
}
}
@@ -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")
@@ -41,12 +41,6 @@ public class FunctionExpressionTestGenerated extends AbstractFunctionExpressionT
doTest(fileName);
}
@TestMetadata("functionExpressionWithName.kt")
public void testFunctionExpressionWithName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithName.kt");
doTest(fileName);
}
@TestMetadata("functionExpressionWithThisReference.kt")
public void testFunctionExpressionWithThisReference() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt");