Merge pull request #410 from kuity/unnecessaryParensInWhenToIf
Fix KT-4385 "Unnecessary parentheses in "replace when with if"
This commit is contained in:
@@ -53,7 +53,8 @@ public class JetPsiUnparsingUtils {
|
|||||||
|
|
||||||
return (expression instanceof JetParenthesizedExpression ||
|
return (expression instanceof JetParenthesizedExpression ||
|
||||||
expression instanceof JetConstantExpression ||
|
expression instanceof JetConstantExpression ||
|
||||||
expression instanceof JetSimpleNameExpression)
|
expression instanceof JetSimpleNameExpression ||
|
||||||
|
expression instanceof JetDotQualifiedExpression)
|
||||||
? text : "(" + text + ")";
|
? 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -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);
|
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")
|
@TestMetadata("whenWithEqualityTests.kt")
|
||||||
public void testWhenWithEqualityTests() throws Exception {
|
public void testWhenWithEqualityTests() throws Exception {
|
||||||
doTestWhenToIf("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithEqualityTests.kt");
|
doTestWhenToIf("idea/testData/intentions/branched/ifWhen/whenToIf/whenWithEqualityTests.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user