From dbb28c571b98e719235d949ae1c639b7aad5e1db Mon Sep 17 00:00:00 2001 From: Pradyoth Kukkapalli Date: Mon, 7 Apr 2014 11:47:58 -0400 Subject: [PATCH] New Intention Action: Replace a call to forEach function with for loop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces an expression of form x.forEach { … } with for (a in x) { … }. --- .../jet/generators/tests/GenerateTests.kt | 1 + .../after.kt.template | 5 + .../before.kt.template | 3 + .../description.html | 5 + idea/src/META-INF/plugin.xml | 8 +- .../jetbrains/jet/plugin/JetBundle.properties | 2 + .../ConvertToForEachLoopIntention.kt | 121 ++++++++++++++++++ .../convertToForEachLoop/complexReceiver.kt | 6 + .../complexReceiver.kt.after | 8 ++ .../explicitFunctionLiteral.kt | 6 + .../explicitFunctionLiteral.kt.after | 8 ++ .../convertToForEachLoop/extraArguments.kt | 11 ++ .../implicitFunctionLiteralParameter.kt | 6 + .../implicitFunctionLiteralParameter.kt.after | 8 ++ .../convertToForEachLoop/infixCall.kt | 6 + .../convertToForEachLoop/infixCall.kt.after | 8 ++ .../parenthesizedExpression.kt | 4 + .../parenthesizedExpression.kt.after | 6 + .../intentions/convertToForEachLoop/simple.kt | 6 + .../convertToForEachLoop/simple.kt.after | 8 ++ .../typeArgumentPresent.kt | 6 + .../typeArgumentPresent.kt.after | 8 ++ .../convertToForEachLoop/userDefined.kt | 11 ++ .../convertToForEachLoop/zeroArguments.kt | 11 ++ .../AbstractCodeTransformationTest.java | 4 + .../CodeTransformationTestGenerated.java | 56 +++++++- 26 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/description.html create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/ConvertToForEachLoopIntention.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/complexReceiver.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/complexReceiver.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/extraArguments.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/infixCall.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/infixCall.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/simple.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/simple.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt.after create mode 100644 idea/testData/intentions/convertToForEachLoop/userDefined.kt create mode 100644 idea/testData/intentions/convertToForEachLoop/zeroArguments.kt diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 72d7f2e30b8..d75d88b2473 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -412,6 +412,7 @@ fun main(args: Array) { model("intentions/convertIfToAssert", testMethod = "doTestConvertIfWithThrowToAssertIntention") model("intentions/makeTypeExplicitInLambda", testMethod = "doTestMakeTypeExplicitInLambda") model("intentions/makeTypeImplicitInLambda", testMethod = "doTestMakeTypeImplicitInLambda") + model("intentions/convertToForEachLoop", testMethod = "doTestConvertToForEachLoop") } testClass(javaClass()) { diff --git a/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/after.kt.template b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/after.kt.template new file mode 100644 index 00000000000..ae87a41b5d0 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/after.kt.template @@ -0,0 +1,5 @@ +fun foo() { + for (a in x) { + a.bar() + } +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/before.kt.template b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/before.kt.template new file mode 100644 index 00000000000..f02a9f5892f --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/before.kt.template @@ -0,0 +1,3 @@ +fun foo() { + x.forEach { a -> a.bar() } +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/description.html b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/description.html new file mode 100644 index 00000000000..2b8115b3973 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToForEachLoopIntention/description.html @@ -0,0 +1,5 @@ + + +This intention converts a call to the "forEach" function into a for each loop expression. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 633746d1417..e3577dcd6d9 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -696,7 +696,13 @@ Kotlin - + org.jetbrains.jet.plugin.intentions.ConvertToForEachLoopIntention + Kotlin + + + + ("convert.to.for.each.loop.intention", javaClass()) { + private fun getFunctionLiteralArgument(element: JetExpression): JetFunctionLiteralExpression? { + val argument = when (element) { + is JetDotQualifiedExpression -> { + val selector = element.getSelectorExpression() + + when (selector) { + is JetCallExpression -> { + when { + selector.getValueArguments().size() > 0 -> selector.getValueArguments()[0]!!.getArgumentExpression() + selector.getFunctionLiteralArguments().size() > 0 -> selector.getFunctionLiteralArguments()[0] + else -> null + } + } + } + } + is JetBinaryExpression -> element.getRight() + else -> null + } + + return when (argument) { + is JetFunctionLiteralExpression -> argument + else -> null + } + } + + override fun isApplicableTo(element: JetExpression): Boolean { + fun isWellFormedFunctionLiteral(element: JetFunctionLiteralExpression): Boolean { + return element.getValueParameters().size() <= 1 && element.getBodyExpression() != null + } + + fun checkTotalNumberOfArguments(element: JetExpression): Boolean { + return when (element) { + is JetDotQualifiedExpression -> { + val selector = element.getSelectorExpression() + + when (selector) { + is JetCallExpression -> (selector.getValueArguments().size() + selector.getFunctionLiteralArguments().size()) == 1 + else -> false + } + } + is JetBinaryExpression -> true + else -> false + } + } + + val callee = JetPsiUtil.getCalleeExpressionIfAny(element) + val functionLiteral = getFunctionLiteralArgument(element) + + if (callee != null && + functionLiteral != null && + isWellFormedFunctionLiteral(functionLiteral) && + checkTotalNumberOfArguments(element)) { + + val context = element.getContainingJetFile().getLazyResolveSession().resolveToElement(callee) + val resolvedCall = context[BindingContext.RESOLVED_CALL, callee] + val functionFqName = if (resolvedCall != null) DescriptorUtils.getFqName(resolvedCall.getResultingDescriptor()).toString() else null + + return "kotlin.forEach".equals(functionFqName); + } + + return false; + } + + override fun applyTo(element: JetExpression, editor: Editor) { + fun buildLoopRangeText(receiver: JetExpression): String? { + return when (receiver) { + is JetParenthesizedExpression -> receiver.getExpression()?.getText() + else -> receiver.getText() + } + } + + fun generateLoopText(receiver: JetExpression, functionLiteral: JetFunctionLiteralExpression): String { + return when { + functionLiteral.getValueParameters().size() == 0 -> "for (it in ${buildLoopRangeText(receiver)}) { ${functionLiteral.getBodyExpression()!!.getText()} }" + else -> "for (${functionLiteral.getValueParameters()[0].getText()} in ${buildLoopRangeText(receiver)}) { ${functionLiteral.getBodyExpression()!!.getText()} }" + } + } + + val receiver = when (element) { + is JetDotQualifiedExpression -> element.getReceiverExpression() + is JetBinaryExpression -> element.getLeft() + else -> throw IllegalArgumentException("The expression ${element.getText()} cannot be converted to a for each loop.") + }!! + + val functionLiteral = getFunctionLiteralArgument(element)!! + + element.replace(JetPsiFactory.createExpression(element.getProject(), generateLoopText(receiver, functionLiteral))) + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt b/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt new file mode 100644 index 00000000000..410b703ca2d --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun main() { + val x = 1..4 + + x.reverse().forEach { it } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt.after b/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt.after new file mode 100644 index 00000000000..c1a7d5ce0ed --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/complexReceiver.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun main() { + val x = 1..4 + + for (it in x.reverse()) { + it + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt b/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt new file mode 100644 index 00000000000..c801e547fda --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + x.forEach({ y -> y }) +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt.after b/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt.after new file mode 100644 index 00000000000..b5c8d36759f --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + for (y in x) { + y + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/extraArguments.kt b/idea/testData/intentions/convertToForEachLoop/extraArguments.kt new file mode 100644 index 00000000000..224050414d6 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/extraArguments.kt @@ -0,0 +1,11 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +class Foo { + fun forEach(predicate: (Int) -> Int, bar: Int): Int = predicate(bar) +} + +fun main() { + val x = Foo() + + x.forEach({ it * 2 }, 2) +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt b/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt new file mode 100644 index 00000000000..e6ba3880d2d --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + x.forEach { it } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt.after b/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt.after new file mode 100644 index 00000000000..49160f46988 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + for (it in x) { + it + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/infixCall.kt b/idea/testData/intentions/convertToForEachLoop/infixCall.kt new file mode 100644 index 00000000000..8fa22e684c4 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/infixCall.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + x forEach { a -> a } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/infixCall.kt.after b/idea/testData/intentions/convertToForEachLoop/infixCall.kt.after new file mode 100644 index 00000000000..4e05c0e91d5 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/infixCall.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + for (a in x) { + a + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt b/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt new file mode 100644 index 00000000000..a6137d098a9 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun main() { + (1 rangeTo 2).forEach { x -> x } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt.after b/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt.after new file mode 100644 index 00000000000..1d0cf3af340 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/parenthesizedExpression.kt.after @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun main() { + for (x in 1 rangeTo 2) { + x + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/simple.kt b/idea/testData/intentions/convertToForEachLoop/simple.kt new file mode 100644 index 00000000000..fec99e3a5a8 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/simple.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + x.forEach { it.equals(1) } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/simple.kt.after b/idea/testData/intentions/convertToForEachLoop/simple.kt.after new file mode 100644 index 00000000000..f0b1a6a245a --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/simple.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + for (it in x) { + it.equals(1) + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt b/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt new file mode 100644 index 00000000000..543204fe6a8 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + x.forEach({ it }) +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt.after b/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt.after new file mode 100644 index 00000000000..49160f46988 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo() { + val x = 1..4 + + for (it in x) { + it + } +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/userDefined.kt b/idea/testData/intentions/convertToForEachLoop/userDefined.kt new file mode 100644 index 00000000000..c9d0f38a353 --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/userDefined.kt @@ -0,0 +1,11 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +class Foo { + fun forEach(predicate: (Int) -> Int): Int = predicate(0) +} + +fun main() { + val x = Foo() + + x.forEach({ it * 2 }) +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToForEachLoop/zeroArguments.kt b/idea/testData/intentions/convertToForEachLoop/zeroArguments.kt new file mode 100644 index 00000000000..7b5395fe0fb --- /dev/null +++ b/idea/testData/intentions/convertToForEachLoop/zeroArguments.kt @@ -0,0 +1,11 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +class Foo { + fun forEach(): Int = 0 +} + +fun main() { + val x = Foo() + + x.forEach() +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java index 458ddedec88..0d1227af873 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java @@ -266,6 +266,10 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes doTestIntention(path, new MakeTypeImplicitInLambdaIntention()); } + public void doTestConvertToForEachLoop(@NotNull String path) throws Exception { + doTestIntention(path, new ConvertToForEachLoopIntention()); + } + private void doTestIntention(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception { configureByFile(path); diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java index e7921f72a09..e4284ee6bbd 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/CodeTransformationTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({CodeTransformationTestGenerated.DoubleBangToIfThen.class, CodeTransformationTestGenerated.IfThenToDoubleBang.class, CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class, CodeTransformationTestGenerated.RemoveExplicitTypeArguments.class, CodeTransformationTestGenerated.ConvertAssertToIf.class, CodeTransformationTestGenerated.ConvertIfToAssert.class, CodeTransformationTestGenerated.MakeTypeExplicitInLambda.class, CodeTransformationTestGenerated.MakeTypeImplicitInLambda.class}) +@InnerTestClasses({CodeTransformationTestGenerated.DoubleBangToIfThen.class, CodeTransformationTestGenerated.IfThenToDoubleBang.class, CodeTransformationTestGenerated.ElvisToIfThen.class, CodeTransformationTestGenerated.IfThenToElvis.class, CodeTransformationTestGenerated.SafeAccessToIfThen.class, CodeTransformationTestGenerated.IfThenToSafeAccess.class, CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class, CodeTransformationTestGenerated.ReplaceGetIntention.class, CodeTransformationTestGenerated.ReplaceContainsIntention.class, CodeTransformationTestGenerated.ReplaceBinaryInfixIntention.class, CodeTransformationTestGenerated.ReplaceUnaryPrefixIntention.class, CodeTransformationTestGenerated.ReplaceInvokeIntention.class, CodeTransformationTestGenerated.SimplifyNegatedBinaryExpressionIntention.class, CodeTransformationTestGenerated.ConvertNegatedBooleanSequence.class, CodeTransformationTestGenerated.ConvertNegatedExpressionWithDemorgansLaw.class, CodeTransformationTestGenerated.SwapBinaryExpression.class, CodeTransformationTestGenerated.SplitIf.class, CodeTransformationTestGenerated.ReplaceWithOperatorAssign.class, CodeTransformationTestGenerated.ReplaceWithTraditionalAssignment.class, CodeTransformationTestGenerated.SimplifyBooleanWithConstants.class, CodeTransformationTestGenerated.InsertExplicitTypeArguments.class, CodeTransformationTestGenerated.RemoveExplicitTypeArguments.class, CodeTransformationTestGenerated.ConvertAssertToIf.class, CodeTransformationTestGenerated.ConvertIfToAssert.class, CodeTransformationTestGenerated.MakeTypeExplicitInLambda.class, CodeTransformationTestGenerated.MakeTypeImplicitInLambda.class, CodeTransformationTestGenerated.ConvertToForEachLoop.class}) public class CodeTransformationTestGenerated extends AbstractCodeTransformationTest { @TestMetadata("idea/testData/intentions/branched/doubleBangToIfThen") public static class DoubleBangToIfThen extends AbstractCodeTransformationTest { @@ -4124,6 +4124,59 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT } + @TestMetadata("idea/testData/intentions/convertToForEachLoop") + public static class ConvertToForEachLoop extends AbstractCodeTransformationTest { + public void testAllFilesPresentInConvertToForEachLoop() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/convertToForEachLoop"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("complexReceiver.kt") + public void testComplexReceiver() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/complexReceiver.kt"); + } + + @TestMetadata("explicitFunctionLiteral.kt") + public void testExplicitFunctionLiteral() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/explicitFunctionLiteral.kt"); + } + + @TestMetadata("extraArguments.kt") + public void testExtraArguments() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/extraArguments.kt"); + } + + @TestMetadata("implicitFunctionLiteralParameter.kt") + public void testImplicitFunctionLiteralParameter() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/implicitFunctionLiteralParameter.kt"); + } + + @TestMetadata("infixCall.kt") + public void testInfixCall() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/infixCall.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/simple.kt"); + } + + @TestMetadata("typeArgumentPresent.kt") + public void testTypeArgumentPresent() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/typeArgumentPresent.kt"); + } + + @TestMetadata("userDefined.kt") + public void testUserDefined() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/userDefined.kt"); + } + + @TestMetadata("zeroArguments.kt") + public void testZeroArguments() throws Exception { + doTestConvertToForEachLoop("idea/testData/intentions/convertToForEachLoop/zeroArguments.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("CodeTransformationTestGenerated"); suite.addTestSuite(DoubleBangToIfThen.class); @@ -4182,6 +4235,7 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT suite.addTestSuite(ConvertIfToAssert.class); suite.addTestSuite(MakeTypeExplicitInLambda.class); suite.addTestSuite(MakeTypeImplicitInLambda.class); + suite.addTestSuite(ConvertToForEachLoop.class); return suite; } }