From 0b76dbb49297be7142852d1727fe7bf1735a587f Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 18 Mar 2015 16:35:25 +0300 Subject: [PATCH] Create DeprecatedLambdaSyntaxFix --- .../kotlin/idea/JetBundle.properties | 2 + .../quickfix/DeprecatedLambdaSyntaxFix.kt | 175 ++++++++++++++++++ .../idea/quickfix/QuickFixRegistrar.java | 1 + .../afterLabelInLiteralArgument.kt | 10 + ...elInLiteralArgumentImplicitReceiverType.kt | 10 + ...abelInLiteralArgumentImplicitReturnType.kt | 10 + ...afterLabelInLiteralArgumentOneStatement.kt | 7 + .../afterLambdaInFunctionArgument.kt | 10 + .../lambdaSyntax/afterLambdaInsideLambda.kt | 11 ++ .../afterParanthesizedParameters.kt | 4 + .../afterReceiverAndReturnInExpression.kt | 5 + .../beforeLabelInLiteralArgument.kt | 10 + ...elInLiteralArgumentImplicitReceiverType.kt | 10 + ...abelInLiteralArgumentImplicitReturnType.kt | 10 + ...eforeLabelInLiteralArgumentOneStatement.kt | 9 + .../beforeLambdaInFunctionArgument.kt | 12 ++ .../lambdaSyntax/beforeLambdaInsideLambda.kt | 10 + .../beforeParanthesizedParameters.kt | 4 + .../beforeReceiverAndReturnInExpression.kt | 4 + .../QuickFixMultiFileTestGenerated.java | 3 + .../idea/quickfix/QuickFixTestGenerated.java | 60 ++++++ 21 files changed, 377 insertions(+) create mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgument.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReceiverType.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReturnType.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentOneStatement.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInFunctionArgument.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterParanthesizedParameters.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgument.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReceiverType.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReturnType.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentOneStatement.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInFunctionArgument.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInsideLambda.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeParanthesizedParameters.kt create mode 100644 idea/testData/quickfix/migration/lambdaSyntax/beforeReceiverAndReturnInExpression.kt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties index c61565b4fc1..1da5dda86b8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/JetBundle.properties @@ -184,6 +184,8 @@ migrate.class.object.to.companion=Replace 'class' keyword with 'companion' modif migrate.class.object.to.companion.family=Replace 'class' Keyword with 'companion' Modifier migrate.class.object.to.companion.in.whole.project=Replace 'class' keyword with 'companion' modifier in whole project migrate.class.object.to.companion.in.whole.project.family=Replace 'class' Keyword with 'companion' Modifier in Whole Project +migrate.lambda.syntax=Migrate lambda syntax +migrate.lambda.syntax.family=Migrate lambda syntax remove.val.var.from.parameter=Remove ''{0}'' from parameter add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project add.when.else.branch.action.family.name=Add Else Branch diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt new file mode 100644 index 00000000000..7ae3129e200 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedLambdaSyntaxFix.kt @@ -0,0 +1,175 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.quickfix + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.progress.ProgressManager +import com.intellij.openapi.progress.Task +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.DiagnosticUtils +import org.jetbrains.kotlin.diagnostics.Errors +import org.jetbrains.kotlin.idea.JetBundle +import org.jetbrains.kotlin.idea.caches.resolve.analyze +import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully +import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider +import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers +import org.jetbrains.kotlin.idea.util.ShortenReferences +import org.jetbrains.kotlin.idea.util.application.runReadAction +import org.jetbrains.kotlin.idea.util.application.runWriteAction +import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParenthesesAndReplaceWith +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.getParentOfType +import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch +import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.BindingTrace +import org.jetbrains.kotlin.types.JetType +import org.jetbrains.kotlin.types.expressions.FunctionsTypingVisitor +import org.jetbrains.kotlin.utils.addIfNotNull +import java.util.ArrayList + +public class DeprecatedLambdaSyntaxFix(element: JetFunctionLiteralExpression) : JetIntentionAction(element) { + override fun getText() = JetBundle.message("migrate.lambda.syntax") + override fun getFamilyName() = JetBundle.message("migrate.lambda.syntax.family") + + override fun invoke(project: Project, editor: Editor, file: JetFile) { + LambdaWithDeprecatedSyntax(element, JetPsiFactory(project)).runFix() + } + + companion object Factory : JetSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic) + = (diagnostic.getPsiElement() as? JetFunctionLiteralExpression)?.let { DeprecatedLambdaSyntaxFix(it) } + } +} + +private class LambdaWithDeprecatedSyntax(val functionLiteralExpression: JetFunctionLiteralExpression, val psiFactory: JetPsiFactory, val level: Int = 0) { + val functionLiteral = functionLiteralExpression.getFunctionLiteral() + val hasNoReturnAndReceiverType = !functionLiteral.hasDeclaredReturnType() && functionLiteral.getReceiverTypeReference() == null + + val bindingContext = if (hasNoReturnAndReceiverType) null else functionLiteralExpression.analyze() + val functionLiteralType: JetType? = if (hasNoReturnAndReceiverType) null else { + val type = bindingContext!!.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression) + assert(type != null && KotlinBuiltIns.isFunctionOrExtensionFunctionType(type)) { + "Broken function type for expression: ${functionLiteralExpression.getText()}, at: ${DiagnosticUtils.atLocation(functionLiteralExpression)}" + } + type + } + + // you must run it under write action + fun runFix() { + if (!JetPsiUtil.isDeprecatedLambdaSyntax(functionLiteralExpression)) return + + if (hasNoReturnAndReceiverType) { + removeExternalParenthesesOnParameterList(functionLiteral, psiFactory) + } + else { + val functionExpression = convertToFunctionExpression(functionLiteralType!!) + + val literalArgument = getFunctionLiteralArgument() + val newFunctionExpression = if (literalArgument == null) { + functionLiteralExpression.replace(functionExpression) as JetNamedFunction + } + else { + literalArgument.moveInsideParenthesesAndReplaceWith(functionExpression, bindingContext!!). + getValueArguments().last().getArgumentExpression() as JetNamedFunction + } + + // todo move outside + ShortenReferences.DEFAULT.process( + listOf(newFunctionExpression.getReceiverTypeReference(), newFunctionExpression.getTypeReference()).filterNotNull() + ) + } + } + + private fun getFunctionLiteralArgument(): JetFunctionLiteralArgument? { + val argument = functionLiteralExpression.getParentOfType(strict = false) + + if (argument != null && argument.getFunctionLiteral() == functionLiteralExpression) { + return argument + } + return null + } + + private fun removeExternalParenthesesOnParameterList(functionLiteral: JetFunctionLiteral, psiFactory: JetPsiFactory) { + val parameterList = functionLiteral.getValueParameterList() + if (parameterList != null && parameterList.isParenthesized()) { + val oldParameterList = parameterList.getText() + val newParameterList = oldParameterList.substring(1..oldParameterList.length() - 2) + parameterList.replace(psiFactory.createFunctionLiteralParameterList(newParameterList)) + } + } + + private fun JetElement.replaceWithReturn(psiFactory: JetPsiFactory) { + if (this is JetReturnExpression) { + return + } + else { + replace(psiFactory.createReturn(getText())) + } + } + + private fun getLambdaLabelName(): String? { + val labeledExpression = functionLiteralExpression.getParentOfType(strict = false) + if (labeledExpression != null && JetPsiUtil.deparenthesize(labeledExpression.getBaseExpression()) == functionLiteralExpression) { + return labeledExpression.getLabelName() + } + return null + } + + private fun convertToFunctionExpression( + functionLiteralType: JetType + ): JetNamedFunction { + val functionName = getLambdaLabelName() + val parameterList = functionLiteral.getValueParameterList()?.getText() + val receiverType = KotlinBuiltIns.getReceiverType(functionLiteralType)?.let { IdeDescriptorRenderers.SOURCE_CODE.renderType(it) } + val returnType = KotlinBuiltIns.getReturnTypeFromFunctionType(functionLiteralType).let { + if (KotlinBuiltIns.isUnit(it)) + null + else + IdeDescriptorRenderers.SOURCE_CODE.renderType(it) + } + + val functionDeclaration = "fun " + + (receiverType?.let { "$it." } ?: "") + + (functionName ?: "") + + (parameterList ?: "()") + + (returnType?.let { ": $it" } ?: "") + + val functionWithEmptyBody = psiFactory.createFunction(functionDeclaration + " {}") + + val blockExpression = functionLiteral.getBodyExpression() + if (blockExpression == null) return functionWithEmptyBody + + val statements = blockExpression.getStatements() + if (statements.isEmpty()) return functionWithEmptyBody + + if (statements.size() == 1) { + return psiFactory.createFunction(functionDeclaration + " = " + statements.first().getText()) + } + + // many statements + if (returnType != null) statements.last().replaceWithReturn(psiFactory) + + return psiFactory.createFunction(functionDeclaration + "{ " + blockExpression.getText() + "}") + } + +} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java index 50f338bef60..5fd725ce3ee 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.java @@ -231,6 +231,7 @@ public class QuickFixRegistrar { QuickFixes.factories.put(NO_VALUE_FOR_PARAMETER, ChangeFunctionSignatureFix.createFactory()); QuickFixes.factories.put(UNUSED_PARAMETER, ChangeFunctionSignatureFix.createFactoryForUnusedParameter()); QuickFixes.factories.put(EXPECTED_PARAMETERS_NUMBER_MISMATCH, ChangeFunctionSignatureFix.createFactoryForParametersNumberMismatch()); + QuickFixes.factories.put(DEPRECATED_LAMBDA_SYNTAX, DeprecatedLambdaSyntaxFix.Factory); QuickFixes.factories.put(EXPECTED_PARAMETER_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedParameterTypeMismatch()); QuickFixes.factories.put(EXPECTED_RETURN_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedReturnTypeMismatch()); diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgument.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgument.kt new file mode 100644 index 00000000000..2d52c8962f7 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgument.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo(fun Int.a(a: String): A { + A() + return A() +}) \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReceiverType.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReceiverType.kt new file mode 100644 index 00000000000..2d52c8962f7 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReceiverType.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo(fun Int.a(a: String): A { + A() + return A() +}) \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReturnType.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReturnType.kt new file mode 100644 index 00000000000..2d52c8962f7 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentImplicitReturnType.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo(fun Int.a(a: String): A { + A() + return A() +}) \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentOneStatement.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentOneStatement.kt new file mode 100644 index 00000000000..008ae180c06 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLabelInLiteralArgumentOneStatement.kt @@ -0,0 +1,7 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Any) {} + +val a = foo(fun Int.a(a: String): A = A()) \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInFunctionArgument.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInFunctionArgument.kt new file mode 100644 index 00000000000..f4758d2b2a3 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInFunctionArgument.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: (Int).(String) -> Int) { + +} + + +val a = foo (fun Int.(a: String): Int = 4) diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt new file mode 100644 index 00000000000..a4203c9c1f7 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterLambdaInsideLambda.kt @@ -0,0 +1,11 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Any) {} + +val a = foo @a { + + val a = + fun (): Int = 1 +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterParanthesizedParameters.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterParanthesizedParameters.kt new file mode 100644 index 00000000000..5ff47f7e626 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterParanthesizedParameters.kt @@ -0,0 +1,4 @@ +// "Migrate lambda syntax" "true" + + +val a = { a: Int -> } \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt b/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt new file mode 100644 index 00000000000..3fb482ed2d4 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/afterReceiverAndReturnInExpression.kt @@ -0,0 +1,5 @@ +// "Migrate lambda syntax" "true" + + +val a = + fun Int.(a: Int): String = "" \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgument.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgument.kt new file mode 100644 index 00000000000..38b21157826 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgument.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo @a { Int.(a: String): A -> + A() + A() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReceiverType.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReceiverType.kt new file mode 100644 index 00000000000..f78304f6f41 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReceiverType.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo @a { (a: String): A -> + A() + A() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReturnType.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReturnType.kt new file mode 100644 index 00000000000..ac955b98860 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReturnType.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Int.(String) -> A) {} + +val a = foo @a { Int.(a: String) -> + A() + A() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentOneStatement.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentOneStatement.kt new file mode 100644 index 00000000000..8ca1828256b --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentOneStatement.kt @@ -0,0 +1,9 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Any) {} + +val a = foo @a { Int.(a: String): A -> + A() +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInFunctionArgument.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInFunctionArgument.kt new file mode 100644 index 00000000000..70ae3ee734d --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInFunctionArgument.kt @@ -0,0 +1,12 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: (Int).(String) -> Int) { + +} + + +val a = foo ({ + (Int).(a: String) -> 4 +}) diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInsideLambda.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInsideLambda.kt new file mode 100644 index 00000000000..3d1e81b2a41 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInsideLambda.kt @@ -0,0 +1,10 @@ +// "Migrate lambda syntax" "true" + +class A + +fun foo(a: Any) {} + +val a = foo @a { + + val a = { (): Int -> 1 } +} \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeParanthesizedParameters.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeParanthesizedParameters.kt new file mode 100644 index 00000000000..f1f900f136c --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeParanthesizedParameters.kt @@ -0,0 +1,4 @@ +// "Migrate lambda syntax" "true" + + +val a = { (a: Int) -> } \ No newline at end of file diff --git a/idea/testData/quickfix/migration/lambdaSyntax/beforeReceiverAndReturnInExpression.kt b/idea/testData/quickfix/migration/lambdaSyntax/beforeReceiverAndReturnInExpression.kt new file mode 100644 index 00000000000..e03f20b2be8 --- /dev/null +++ b/idea/testData/quickfix/migration/lambdaSyntax/beforeReceiverAndReturnInExpression.kt @@ -0,0 +1,4 @@ +// "Migrate lambda syntax" "true" + + +val a = { Int.(a: Int): String -> "" } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java index e78eaa15e95..3ea6d7c3487 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiFileTestGenerated.java @@ -856,6 +856,8 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes @TestMetadata("idea/testData/quickfix/migration") @TestDataPath("$PROJECT_ROOT") + @InnerTestClasses({ + }) @RunWith(JUnit3RunnerWithInners.class) public static class Migration extends AbstractQuickFixMultiFileTest { public void testAllFilesPresentInMigration() throws Exception { @@ -867,6 +869,7 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/classObjectToDefaultMultiple.before.Main.kt"); doTestWithExtraFile(fileName); } + } @TestMetadata("idea/testData/quickfix/modifiers") diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index d69d962232a..76b3986d043 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -2887,6 +2887,9 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { @TestMetadata("idea/testData/quickfix/migration") @TestDataPath("$PROJECT_ROOT") + @InnerTestClasses({ + Migration.LambdaSyntax.class, + }) @RunWith(JUnit3RunnerWithInners.class) public static class Migration extends AbstractQuickFixTest { @TestMetadata("beforeAddOverrideToEqualsHashCodeToString.kt") @@ -2904,6 +2907,63 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/beforeClassObjectToDefaultSingle.kt"); doTest(fileName); } + + @TestMetadata("idea/testData/quickfix/migration/lambdaSyntax") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class LambdaSyntax extends AbstractQuickFixTest { + public void testAllFilesPresentInLambdaSyntax() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/lambdaSyntax"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeLabelInLiteralArgument.kt") + public void testLabelInLiteralArgument() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgument.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLabelInLiteralArgumentImplicitReceiverType.kt") + public void testLabelInLiteralArgumentImplicitReceiverType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReceiverType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLabelInLiteralArgumentImplicitReturnType.kt") + public void testLabelInLiteralArgumentImplicitReturnType() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentImplicitReturnType.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLabelInLiteralArgumentOneStatement.kt") + public void testLabelInLiteralArgumentOneStatement() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLabelInLiteralArgumentOneStatement.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLambdaInFunctionArgument.kt") + public void testLambdaInFunctionArgument() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInFunctionArgument.kt"); + doTest(fileName); + } + + @TestMetadata("beforeLambdaInsideLambda.kt") + public void testLambdaInsideLambda() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeLambdaInsideLambda.kt"); + doTest(fileName); + } + + @TestMetadata("beforeParanthesizedParameters.kt") + public void testParanthesizedParameters() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeParanthesizedParameters.kt"); + doTest(fileName); + } + + @TestMetadata("beforeReceiverAndReturnInExpression.kt") + public void testReceiverAndReturnInExpression() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/lambdaSyntax/beforeReceiverAndReturnInExpression.kt"); + doTest(fileName); + } + } } @TestMetadata("idea/testData/quickfix/modifiers")