Remove braces from 'when' entry: do not suggest when statement is lambda that has no arrow

#KT-35288 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-12-06 21:52:33 +09:00
committed by Mikhail Glukhikh
parent afc680d5c9
commit 7b1771d432
5 changed files with 39 additions and 0 deletions
@@ -51,6 +51,7 @@ class RemoveBracesIntention : SelfTargetingIntention<KtElement>(KtElement::class
is KtWhenEntry -> {
text = "Remove braces from 'when' entry"
return singleStatement !is KtNamedDeclaration
&& !(singleStatement is KtLambdaExpression && singleStatement.functionLiteral.arrow == null)
}
else -> return false
}
+10
View File
@@ -0,0 +1,10 @@
// IS_APPLICABLE: false
fun test(v: Boolean): (String) -> Int {
return when (v) {
true -> <caret>{ { taskOne(it) } }
false -> { x -> taskTwo(x) }
}
}
fun taskOne(s: String) = s.length
fun taskTwo(s: String) = 42
+9
View File
@@ -0,0 +1,9 @@
fun test(v: Boolean): (String) -> Int {
return when (v) {
true -> <caret>{ { x -> taskOne(x) } }
false -> { x -> taskTwo(x) }
}
}
fun taskOne(s: String) = s.length
fun taskTwo(s: String) = 42
@@ -0,0 +1,9 @@
fun test(v: Boolean): (String) -> Int {
return when (v) {
true -> { x -> taskOne(x) }
false -> { x -> taskTwo(x) }
}
}
fun taskOne(s: String) = s.length
fun taskTwo(s: String) = 42
@@ -12825,6 +12825,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/removeBraces/whenLambda.kt");
}
@TestMetadata("whenLambda2.kt")
public void testWhenLambda2() throws Exception {
runTest("idea/testData/intentions/removeBraces/whenLambda2.kt");
}
@TestMetadata("whenLambda3.kt")
public void testWhenLambda3() throws Exception {
runTest("idea/testData/intentions/removeBraces/whenLambda3.kt");
}
@TestMetadata("whenMultiple.kt")
public void testWhenMultiple() throws Exception {
runTest("idea/testData/intentions/removeBraces/whenMultiple.kt");