Lift assignment out: if last statement is lambda, enclose it in parentheses if necessary
#KT-38155 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
e6476c39ca
commit
ee406f1622
@@ -0,0 +1,12 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
<caret>if (i == 1) {
|
||||
f = { true }
|
||||
} else {
|
||||
foo { i }
|
||||
f = { false }
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
fun foo(f: () -> Int) {}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
f = if (i == 1) {
|
||||
{ true }
|
||||
} else {
|
||||
foo { i }
|
||||
({ false })
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
fun foo(f: () -> Int) {}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
<caret>if (i == 1) {
|
||||
f = { true }
|
||||
} else {
|
||||
val foo = Foo().foo { i } // comment
|
||||
f = { false }
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun foo(f: () -> Int) {}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
f = if (i == 1) {
|
||||
{ true }
|
||||
} else {
|
||||
val foo = Foo().foo { i } // comment
|
||||
({ false })
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
class Foo {
|
||||
fun foo(f: () -> Int) {}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
<caret>if (i == 1) {
|
||||
f = { true }
|
||||
} else {
|
||||
val g: () -> Boolean = { false }
|
||||
f = { g() }
|
||||
}
|
||||
f()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
f = if (i == 1) {
|
||||
{ true }
|
||||
} else {
|
||||
val g: () -> Boolean = { false }
|
||||
{ g() }
|
||||
}
|
||||
f()
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
<caret>if (i == 1) {
|
||||
f = { true }
|
||||
} else {
|
||||
val foo = foo()
|
||||
f = { false }
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fun test(i: Int) {
|
||||
val f: () -> Boolean
|
||||
f = if (i == 1) {
|
||||
{ true }
|
||||
} else {
|
||||
val foo = foo()
|
||||
({ false })
|
||||
}
|
||||
f()
|
||||
}
|
||||
|
||||
fun foo() {}
|
||||
+20
@@ -5603,6 +5603,26 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("afterRightBrace.kt")
|
||||
public void testAfterRightBrace() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/liftOut/ifToAssignment/afterRightBrace.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("afterRightBrace2.kt")
|
||||
public void testAfterRightBrace2() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/liftOut/ifToAssignment/afterRightBrace2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("afterRightBrace3.kt")
|
||||
public void testAfterRightBrace3() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/liftOut/ifToAssignment/afterRightBrace3.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("afterRightParenthesis.kt")
|
||||
public void testAfterRightParenthesis() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/liftOut/ifToAssignment/afterRightParenthesis.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInIfToAssignment() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/inspectionsLocal/liftOut/ifToAssignment"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user