From 693e15875988c7be37b418e1bd730bcc790dcc7e Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Tue, 15 Dec 2015 10:22:53 +0300 Subject: [PATCH] Intention to convert anonymous function to lambda --- .../after.kt.template | 7 ++ .../before.kt.template | 9 ++ .../description.html | 5 + idea/src/META-INF/plugin.xml | 5 + .../AnonymousFunctionToLambdaIntention.kt | 102 ++++++++++++++++++ .../ObjectLiteralToLambdaIntention.kt | 63 ++--------- .../kotlin/idea/intentions/ReturnSaver.kt | 101 +++++++++++++++++ .../anonymousFunctionToLambda/.intention | 1 + .../callMultiline.kt | 10 ++ .../callMultiline.kt.after | 10 ++ .../anonymousFunctionToLambda/constructor.kt | 7 ++ .../constructor.kt.after | 5 + .../expressionBody.kt | 7 ++ .../expressionBody.kt.after | 7 ++ .../anonymousFunctionToLambda/fullParam.kt | 9 ++ .../fullParam.kt.after | 7 ++ .../anonymousFunctionToLambda/moveOut.kt | 9 ++ .../moveOut.kt.after | 7 ++ .../anonymousFunctionToLambda/paramName.kt | 9 ++ .../paramName.kt.after | 7 ++ .../replaceReturnWithExpression.kt | 9 ++ .../replaceReturnWithExpression.kt.after | 7 ++ .../replaceReturnWithLabel.kt | 13 +++ .../replaceReturnWithLabel.kt.after | 13 +++ .../anonymousFunctionToLambda/simple.kt | 9 ++ .../anonymousFunctionToLambda/simple.kt.after | 7 ++ .../intentions/IntentionTestGenerated.java | 63 +++++++++++ 27 files changed, 451 insertions(+), 57 deletions(-) create mode 100644 idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/description.html create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/AnonymousFunctionToLambdaIntention.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/intentions/ReturnSaver.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/.intention create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/constructor.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/constructor.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/paramName.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/paramName.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt.after create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/simple.kt create mode 100644 idea/testData/intentions/anonymousFunctionToLambda/simple.kt.after diff --git a/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/after.kt.template b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/after.kt.template new file mode 100644 index 00000000000..b1515663e20 --- /dev/null +++ b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/after.kt.template @@ -0,0 +1,7 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo { 1 } +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/before.kt.template b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/before.kt.template new file mode 100644 index 00000000000..41a16354305 --- /dev/null +++ b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/before.kt.template @@ -0,0 +1,9 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo(fun(): Int { + return 1 + }) +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/description.html b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/description.html new file mode 100644 index 00000000000..6aff0d3e6fb --- /dev/null +++ b/idea/resources/intentionDescriptions/AnonymousFunctionToLambdaIntention/description.html @@ -0,0 +1,5 @@ + + +Converts an anonymous function in call to lambda expression. + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index d1975249664..1cf7a0dca24 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -1105,6 +1105,11 @@ Kotlin + + org.jetbrains.kotlin.idea.intentions.AnonymousFunctionToLambdaIntention + Kotlin + + ( + KtNamedFunction::class.java, + "Convert to lambda expression", + "Convert anonymous function to lambda expression" +) { + override fun applicabilityRange(element: KtNamedFunction): TextRange? { + if (element.name != null) return null + + if (!element.hasBody()) return null + + val callElement = element.getParentOfTypeAndBranch { valueArgumentList } ?: return null + if (callElement.getCalleeExpressionIfAny() !is KtNameReferenceExpression) { + return null + } + + return element.funKeyword!!.textRange + } + + override fun applyTo(element: KtNamedFunction, editor: Editor) { + applyTo(element) + } + + fun applyTo(element: KtNamedFunction) { + val commentSaver = CommentSaver(element) + val returnSaver = ReturnSaver(element) + + val body = element.bodyExpression!! + + val newExpression = KtPsiFactory(element).buildExpression { + appendFixedText("{") + + val parameters = element.valueParameters + + val needParameters = parameters.count() > 1 || parameters.any { parameter -> ReferencesSearch.search(parameter, LocalSearchScope(body)).any() } + if (needParameters) { + parameters.forEachIndexed { index, parameter -> + if (index > 0) { + appendFixedText(",") + } + appendName(parameter.nameAsSafeName) + } + + appendFixedText("->") + } + + if (element.hasBlockBody()) { + appendChildRange((body as KtBlockExpression).contentRange()) + } + else { + appendExpression(body) + } + + appendFixedText("}") + } + + val replaced = element.replaced(newExpression) as KtLambdaExpression + commentSaver.restore(replaced, forceAdjustIndent = true/* by some reason lambda body is sometimes not properly indented */) + + val callExpression = replaced.parents.firstIsInstance() + val callee = callExpression.getCalleeExpressionIfAny()!! as KtNameReferenceExpression + + val returnLabel = callee.getReferencedNameAsName() + returnSaver.restore(replaced, returnLabel) + + val moveLambdaOutsideParenthesesIntention = MoveLambdaOutsideParenthesesIntention() + if (moveLambdaOutsideParenthesesIntention.isApplicableTo(callExpression, replaced.textOffset)) { + moveLambdaOutsideParenthesesIntention.applyTo(callExpression) + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt index 05c1045d500..6eba9c31102 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ObjectLiteralToLambdaIntention.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.openapi.editor.Editor -import com.intellij.openapi.util.Key import com.intellij.openapi.util.TextRange import com.intellij.psi.search.LocalSearchScope import com.intellij.psi.search.searches.ReferencesSearch @@ -34,9 +33,10 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils import org.jetbrains.kotlin.psi.* -import org.jetbrains.kotlin.psi.psiUtil.* +import org.jetbrains.kotlin.psi.psiUtil.contentRange +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.bindingContextUtil.getTargetFunction import org.jetbrains.kotlin.resolve.calls.callUtil.getCalleeExpressionIfAny import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.KotlinType @@ -72,14 +72,9 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention("RETURN_KEY") + val returnSaver = ReturnSaver(singleFunction) val body = singleFunction.bodyExpression!! - body.forEachDescendantOfType { - if (it.getTargetFunction(it.analyze(BodyResolveMode.PARTIAL)) == singleFunction) { - it.putCopyableUserData(RETURN_KEY, Unit) - } - } val factory = KtPsiFactory(element) val newExpression = factory.buildExpression { @@ -111,8 +106,6 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention { it.putCopyableUserData(RETURN_KEY, null) } - val replaced = element.replaced(newExpression) commentSaver.restore(replaced, forceAdjustIndent = true/* by some reason lambda body is sometimes not properly indented */) @@ -120,26 +113,8 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention() { it.getCopyableUserData(RETURN_KEY) != null } - val returnLabel = callee.getReferencedNameAsName() - for (returnExpression in returnToReplace) { - val value = returnExpression.returnedExpression - val replaceWith = if (value != null && returnExpression.isValueOfBlock(lambdaBody)) { - value - } - else if (value != null) { - factory.createExpressionByPattern("return@$0 $1", returnLabel, value) - } - else { - factory.createExpressionByPattern("return@$0", returnLabel) - } - - returnExpression.replace(replaceWith) - - } + returnSaver.restore(functionLiteral, returnLabel) val parentCall = ((replaced.parent as? KtValueArgument) ?.parent as? KtValueArgumentList) @@ -152,32 +127,6 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention { - return this == inBlock.statements.last() - } - - is KtBlockExpression -> { - return isValueOfBlock(parent) && parent.isValueOfBlock(inBlock) - } - - is KtContainerNode -> { - val owner = parent.parent - if (owner is KtIfExpression) { - return (this == owner.then || this == owner.`else`) && owner.isValueOfBlock(inBlock) - } - } - - is KtWhenEntry -> { - return this == parent.expression && (parent.parent as KtWhenExpression).isValueOfBlock(inBlock) - } - } - - return false - } - private data class Data( val baseTypeRef: KtTypeReference, val baseType: KotlinType, @@ -197,4 +146,4 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention("RETURN_KEY") + + init { + save() + } + + private fun save() { + val body = function.bodyExpression!! + body.forEachDescendantOfType { + if (it.getTargetFunction(it.analyze(BodyResolveMode.PARTIAL)) == function) { + it.putCopyableUserData(RETURN_KEY, Unit) + } + } + } + + private fun clear() { + val body = function.bodyExpression!! + body.forEachDescendantOfType { it.putCopyableUserData(RETURN_KEY, null) } + } + + fun restore(lambda: KtLambdaExpression, label: Name) { + clear() + + val factory = KtPsiFactory(lambda) + + val lambdaBody = lambda.bodyExpression!! + + val returnToReplace = lambda.collectDescendantsOfType() { it.getCopyableUserData(RETURN_KEY) != null } + + for (returnExpression in returnToReplace) { + val value = returnExpression.returnedExpression + val replaceWith = if (value != null && returnExpression.isValueOfBlock(lambdaBody)) { + value + } + else if (value != null) { + factory.createExpressionByPattern("return@$0 $1", label, value) + } + else { + factory.createExpressionByPattern("return@$0", label) + } + + returnExpression.replace(replaceWith) + + } + } + + private fun KtExpression.isValueOfBlock(inBlock: KtBlockExpression): Boolean { + val parent = parent + when (parent) { + inBlock -> { + return this == inBlock.statements.last() + } + + is KtBlockExpression -> { + return isValueOfBlock(parent) && parent.isValueOfBlock(inBlock) + } + + is KtContainerNode -> { + val owner = parent.parent + if (owner is KtIfExpression) { + return (this == owner.then || this == owner.`else`) && owner.isValueOfBlock(inBlock) + } + } + + is KtWhenEntry -> { + return this == parent.expression && (parent.parent as KtWhenExpression).isValueOfBlock(inBlock) + } + } + + return false + } + +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/.intention b/idea/testData/intentions/anonymousFunctionToLambda/.intention new file mode 100644 index 00000000000..c040f0bebf9 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/.intention @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.intentions.AnonymousFunctionToLambdaIntention diff --git a/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt b/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt new file mode 100644 index 00000000000..c8fef17d43f --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt @@ -0,0 +1,10 @@ +fun foo(f: () -> Unit) { + f() +} + +fun main(args: String) { + foo(fun() { + val p1 = 1 + val p2 = 1 + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt.after new file mode 100644 index 00000000000..c0ffcfe8301 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt.after @@ -0,0 +1,10 @@ +fun foo(f: () -> Unit) { + f() +} + +fun main(args: String) { + foo { + val p1 = 1 + val p2 = 1 + } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt b/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt new file mode 100644 index 00000000000..d21d8fbe4f0 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt @@ -0,0 +1,7 @@ +class Foo(f: () -> Unit) + +fun main(args: String) { + Foo(fun() { + val p = 1 + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt.after new file mode 100644 index 00000000000..aada22587ca --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/constructor.kt.after @@ -0,0 +1,5 @@ +class Foo(f: () -> Unit) + +fun main(args: String) { + Foo { val p = 1 } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt b/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt new file mode 100644 index 00000000000..b119ec33e7f --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt @@ -0,0 +1,7 @@ +fun foo3(f: () -> Int) { + f() +} + +fun main(args: String) { + foo3(fun () = 1) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt.after new file mode 100644 index 00000000000..df91e6e0b49 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt.after @@ -0,0 +1,7 @@ +fun foo3(f: () -> Int) { + f() +} + +fun main(args: String) { + foo3 { 1 } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt b/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt new file mode 100644 index 00000000000..7e2eb0ed106 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt @@ -0,0 +1,9 @@ +fun foo2(f: (Int) -> Unit) { + f(1) +} + +fun main(args: String) { + foo2(fun(i: Int) { + val p = i + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt.after new file mode 100644 index 00000000000..d0f1402df7c --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt.after @@ -0,0 +1,7 @@ +fun foo2(f: (Int) -> Unit) { + f(1) +} + +fun main(args: String) { + foo2 { i -> val p = i } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt b/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt new file mode 100644 index 00000000000..e85aaf02324 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt @@ -0,0 +1,9 @@ +fun foo(f: () -> Unit, i: Int) { + f() +} + +fun main(args: String) { + foo(fun() { + val p = 1 + }, 1) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt.after new file mode 100644 index 00000000000..12239ef20d4 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt.after @@ -0,0 +1,7 @@ +fun foo(f: () -> Unit, i: Int) { + f() +} + +fun main(args: String) { + foo({ val p = 1 }, 1) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt b/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt new file mode 100644 index 00000000000..cdecdfffc46 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt @@ -0,0 +1,9 @@ +fun foo2(f: (Int) -> Unit) { + f(1) +} + +fun main(args: String) { + foo2(fun(i) { + val p = i + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt.after new file mode 100644 index 00000000000..d0f1402df7c --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/paramName.kt.after @@ -0,0 +1,7 @@ +fun foo2(f: (Int) -> Unit) { + f(1) +} + +fun main(args: String) { + foo2 { i -> val p = i } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt new file mode 100644 index 00000000000..79e948c4638 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt @@ -0,0 +1,9 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo(fun(): Int { + return 1 + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt.after new file mode 100644 index 00000000000..b1515663e20 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt.after @@ -0,0 +1,7 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo { 1 } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt new file mode 100644 index 00000000000..89e6e866329 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt @@ -0,0 +1,13 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo(fun(): Int { + val a = 1 + if (a > 1) { + return 1 + } + return 2 + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt.after new file mode 100644 index 00000000000..3c268a7bfca --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt.after @@ -0,0 +1,13 @@ +fun foo(f: () -> Int) { + f() +} + +fun main(args: String) { + foo { + val a = 1 + if (a > 1) { + return@foo 1 + } + 2 + } +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/simple.kt b/idea/testData/intentions/anonymousFunctionToLambda/simple.kt new file mode 100644 index 00000000000..105373d4526 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/simple.kt @@ -0,0 +1,9 @@ +fun foo(f: () -> Unit) { + f() +} + +fun main(args: String) { + foo(fun() { + val p = 1 + }) +} \ No newline at end of file diff --git a/idea/testData/intentions/anonymousFunctionToLambda/simple.kt.after b/idea/testData/intentions/anonymousFunctionToLambda/simple.kt.after new file mode 100644 index 00000000000..8acb271bd83 --- /dev/null +++ b/idea/testData/intentions/anonymousFunctionToLambda/simple.kt.after @@ -0,0 +1,7 @@ +fun foo(f: () -> Unit) { + f() +} + +fun main(args: String) { + foo { val p = 1 } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index ec5a5bb06d3..689f306db58 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -362,6 +362,69 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } + @TestMetadata("idea/testData/intentions/anonymousFunctionToLambda") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AnonymousFunctionToLambda extends AbstractIntentionTest { + public void testAllFilesPresentInAnonymousFunctionToLambda() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/anonymousFunctionToLambda"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true); + } + + @TestMetadata("callMultiline.kt") + public void testCallMultiline() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/callMultiline.kt"); + doTest(fileName); + } + + @TestMetadata("constructor.kt") + public void testConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/constructor.kt"); + doTest(fileName); + } + + @TestMetadata("expressionBody.kt") + public void testExpressionBody() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/expressionBody.kt"); + doTest(fileName); + } + + @TestMetadata("fullParam.kt") + public void testFullParam() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/fullParam.kt"); + doTest(fileName); + } + + @TestMetadata("moveOut.kt") + public void testMoveOut() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt"); + doTest(fileName); + } + + @TestMetadata("paramName.kt") + public void testParamName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/paramName.kt"); + doTest(fileName); + } + + @TestMetadata("replaceReturnWithExpression.kt") + public void testReplaceReturnWithExpression() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithExpression.kt"); + doTest(fileName); + } + + @TestMetadata("replaceReturnWithLabel.kt") + public void testReplaceReturnWithLabel() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/replaceReturnWithLabel.kt"); + doTest(fileName); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/anonymousFunctionToLambda/simple.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/intentions/branched") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)