Do not convert anonymous object to lambda if its function is recursive

#KT-10348 Fixed
This commit is contained in:
Natalia Ukhorskaya
2015-12-17 13:25:55 +03:00
parent 43476bd773
commit d40e9ffc13
3 changed files with 23 additions and 0 deletions
@@ -60,6 +60,11 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
if (!singleFunction.hasBody()) return null
if (singleFunction.valueParameters.any { it.name == null }) return null
// Recursive call, skip labels
if (ReferencesSearch.search(singleFunction, LocalSearchScope(singleFunction.bodyExpression!!)).any { it.element !is KtLabelReferenceExpression }) {
return null
}
return TextRange(element.objectDeclaration.getObjectKeyword().startOffset, baseTypeRef.endOffset)
}
@@ -0,0 +1,12 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
fun foo(runnable: Runnable) {}
fun bar() {
foo(<caret>object : Runnable {
override fun run() {
run()
}
})
}
@@ -6189,6 +6189,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("Recursive.kt")
public void testRecursive() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/objectLiteralToLambda/Recursive.kt");
doTest(fileName);
}
@TestMetadata("ReturnNoValue.kt")
public void testReturnNoValue() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/objectLiteralToLambda/ReturnNoValue.kt");