Inline: support compound case without containing block #KT-17296 Fixed
This commit is contained in:
@@ -182,8 +182,12 @@ internal class ExpressionReplacementPerformer(
|
||||
}
|
||||
}
|
||||
|
||||
//TODO
|
||||
throw UnsupportedOperationException()
|
||||
val runExpression = psiFactory.createExpressionByPattern("run { $0 }", elementToBeReplaced) as KtCallExpression
|
||||
val runAfterReplacement = elementToBeReplaced.replaced(runExpression)
|
||||
val block = runAfterReplacement.lambdaArguments[0].getLambdaExpression().bodyExpression!!
|
||||
elementToBeReplaced = block.statements.single()
|
||||
return elementToBeReplaced
|
||||
|
||||
}
|
||||
|
||||
private fun KtExpression.replaceWithBlock(): KtExpression {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
interface DelegateFace
|
||||
fun compoundDelegate(): DelegateFace {
|
||||
val result = object : DelegateFace {}
|
||||
return result
|
||||
}
|
||||
class DelegatingB : DelegateFace by <caret>compoundDelegate()
|
||||
@@ -0,0 +1,5 @@
|
||||
interface DelegateFace
|
||||
class DelegatingB : DelegateFace by run {
|
||||
val result = object : DelegateFace {}
|
||||
result
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun provideSimple() = listOf("statement 0")
|
||||
fun provideComplex(): MutableList<String> {
|
||||
val result = mutableListOf("statement 1")
|
||||
result.add("statement 2")
|
||||
return result
|
||||
}
|
||||
fun callInDefault(simple: List<String> = provideSimple(), complex: List<String> = <caret>provideComplex()) {
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun provideSimple() = listOf("statement 0")
|
||||
fun callInDefault(simple: List<String> = provideSimple(), complex: List<String> = run {
|
||||
val result = mutableListOf("statement 1")
|
||||
result.add("statement 2")
|
||||
result
|
||||
}) {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun compound(): String {
|
||||
val s = "Hello"
|
||||
return s
|
||||
}
|
||||
|
||||
fun outer() {
|
||||
class Container {
|
||||
val v = <caret>compound()
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun outer() {
|
||||
val s = "Hello"
|
||||
|
||||
class Container {
|
||||
val v = s
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun compound(): String {
|
||||
val s = "Hello"
|
||||
return s
|
||||
}
|
||||
|
||||
class Container {
|
||||
val v = <caret>compound()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Container {
|
||||
val v = run {
|
||||
val s = "Hello"
|
||||
s
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun compound(): String {
|
||||
val s = "Hello"
|
||||
return s
|
||||
}
|
||||
|
||||
val v = <caret>compound()
|
||||
@@ -0,0 +1,4 @@
|
||||
val v = run {
|
||||
val s = "Hello"
|
||||
s
|
||||
}
|
||||
@@ -388,18 +388,48 @@ public class InlineTestGenerated extends AbstractInlineTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassDelegate.kt")
|
||||
public void testClassDelegate() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/ClassDelegate.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConvertToBlockBody.kt")
|
||||
public void testConvertToBlockBody() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/ConvertToBlockBody.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DefaultParameter.kt")
|
||||
public void testDefaultParameter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/DefaultParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("MultipleStatements.kt")
|
||||
public void testMultipleStatements() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/MultipleStatements.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OnLocalMemberLevel.kt")
|
||||
public void testOnLocalMemberLevel() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/OnLocalMemberLevel.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OnMemberLevel.kt")
|
||||
public void testOnMemberLevel() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/OnMemberLevel.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OnTopLevel.kt")
|
||||
public void testOnTopLevel() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/OnTopLevel.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("PrivateMember.kt")
|
||||
public void testPrivateMember() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/inline/function/returnAtEnd/PrivateMember.kt");
|
||||
|
||||
Reference in New Issue
Block a user