Convrt anonymous function to lambda: fix incorrectly conversion
#KT-28618
This commit is contained in:
committed by
Mikhail Glukhikh
parent
f6323cdee4
commit
9ee9965c7a
@@ -164,15 +164,15 @@ fun KtElement.blockExpressionsOrSingle(): Sequence<KtElement> =
|
||||
fun KtExpression.lastBlockStatementOrThis(): KtExpression = (this as? KtBlockExpression)?.statements?.lastOrNull() ?: this
|
||||
|
||||
fun KtBlockExpression.contentRange(): PsiChildRange {
|
||||
val first = (lBrace?.nextSibling ?: firstChild)
|
||||
?.siblings(withItself = false)
|
||||
?.firstOrNull { it !is PsiWhiteSpace }
|
||||
val rBrace = rBrace
|
||||
val lBrace = this.lBrace ?: return PsiChildRange.EMPTY
|
||||
val rBrace = this.rBrace ?: return PsiChildRange.EMPTY
|
||||
|
||||
val first = lBrace.siblings(withItself = false).firstOrNull { it !is PsiWhiteSpace }
|
||||
if (first == rBrace) return PsiChildRange.EMPTY
|
||||
val last = rBrace!!
|
||||
.siblings(forward = false, withItself = false)
|
||||
.first { it !is PsiWhiteSpace }
|
||||
|
||||
val last = rBrace.siblings(forward = false, withItself = false).first { it !is PsiWhiteSpace }
|
||||
if (last == lBrace) return PsiChildRange.EMPTY
|
||||
|
||||
return PsiChildRange(first, last)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(f: (Int) -> Boolean) {
|
||||
f(1)
|
||||
}
|
||||
fun test() {
|
||||
foo(<caret>fun(i: Int): Boolean {return i > 0 })
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun foo(f: (Int) -> Boolean) {
|
||||
f(1)
|
||||
}
|
||||
fun test() {
|
||||
foo { i -> i > 0 }
|
||||
}
|
||||
@@ -1954,6 +1954,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/anonymousFunctionToLambda/moveOut.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noSpaceAfterFunctionLeftBrace.kt")
|
||||
public void testNoSpaceAfterFunctionLeftBrace() throws Exception {
|
||||
runTest("idea/testData/intentions/anonymousFunctionToLambda/noSpaceAfterFunctionLeftBrace.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("paramName.kt")
|
||||
public void testParamName() throws Exception {
|
||||
runTest("idea/testData/intentions/anonymousFunctionToLambda/paramName.kt");
|
||||
|
||||
Reference in New Issue
Block a user