Merge pull request #410 from kuity/unnecessaryParensInWhenToIf

Fix KT-4385 "Unnecessary parentheses in "replace when with if"
This commit is contained in:
asedunov
2014-03-17 13:00:10 +01:00
4 changed files with 31 additions and 1 deletions
@@ -53,7 +53,8 @@ public class JetPsiUnparsingUtils {
return (expression instanceof JetParenthesizedExpression ||
expression instanceof JetConstantExpression ||
expression instanceof JetSimpleNameExpression)
expression instanceof JetSimpleNameExpression ||
expression instanceof JetDotQualifiedExpression)
? text : "(" + text + ")";
}
@@ -0,0 +1,13 @@
class G {
fun cat(x: Int, y: Int): Int {
return x + y
}
}
fun test(x: Int, y: Int): String {
when<caret> (G.cat(x, y)) {
1 -> return "one"
2 -> return "two"
else -> return "big"
}
}
@@ -0,0 +1,11 @@
class G {
fun cat(x: Int, y: Int): Int {
return x + y
}
}
fun test(x: Int, y: Int): String {
if (G.cat(x, y) == 1) return "one"
else if (G.cat(x, y) == 2) return "two"
else return "big"
}
@@ -971,6 +971,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/branched/ifWhen/whenToIf"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("whenWithDotQualifiedExpression.kt")
public void testWhenWithDotQualifiedExpression() throws Exception {
doTestWhenToIf("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithDotQualifiedExpression.kt");
}
@TestMetadata("whenWithEqualityTests.kt")
public void testWhenWithEqualityTests() throws Exception {
doTestWhenToIf("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithEqualityTests.kt");