Inline: Fix inlining of if-expressions into qualified expressions

#KT-8008 Fixed
This commit is contained in:
Alexey Sedunov
2015-10-23 19:38:11 +03:00
parent 89132b3f66
commit 6dd58ad197
4 changed files with 19 additions and 0 deletions
@@ -483,6 +483,8 @@ public class KtPsiUtil {
}
if (innerExpression instanceof KtIfExpression) {
if (parentExpression instanceof KtQualifiedExpression) return true;
PsiElement current = parentExpression;
while (!(current instanceof KtBlockExpression || current instanceof KtDeclaration || current instanceof KtStatementExpression)) {
@@ -0,0 +1,6 @@
// WITH_RUNTIME
fun boo() : Pair<Int, String> {
val flag = true
val <caret>value = if (flag) 0 else 1
return value.to("value")
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun boo() : Pair<Int, String> {
val flag = true
return (if (flag) 0 else 1).to("value")
}
@@ -47,6 +47,12 @@ public class InlineTestGenerated extends AbstractInlineTest {
doTest(fileName);
}
@TestMetadata("ifInQualifiedExpression.kt")
public void testIfInQualifiedExpression() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/ifInQualifiedExpression.kt");
doTest(fileName);
}
@TestMetadata("InFunctionLiteral.kt")
public void testInFunctionLiteral() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/InFunctionLiteral.kt");