Extract Function: Extract block contents
#KT-8235 Fixed
This commit is contained in:
+2
-10
@@ -56,16 +56,8 @@ public class ExtractKotlinFunctionHandler(
|
||||
elements: List<PsiElement>,
|
||||
targetSibling: PsiElement
|
||||
) {
|
||||
fun adjustElements(elements: List<PsiElement>): List<PsiElement> {
|
||||
if (elements.size() != 1) return elements
|
||||
|
||||
val e = elements.first()
|
||||
if (e is JetBlockExpression && e.getParent() is JetFunctionLiteral) return e.getStatements()
|
||||
|
||||
return elements
|
||||
}
|
||||
|
||||
val extractionData = ExtractionData(file, adjustElements(elements).toRange(false), targetSibling)
|
||||
val adjustedElements = (elements.singleOrNull() as? JetBlockExpression)?.getStatements() ?: elements
|
||||
val extractionData = ExtractionData(file, adjustedElements.toRange(false), targetSibling)
|
||||
ExtractionEngine(helper).run(editor, extractionData) {
|
||||
processDuplicates(it.duplicateReplacers, file.getProject(), editor)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun test() {
|
||||
if (true) <selection>{
|
||||
println("Hello world!")
|
||||
}</selection>
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fun test() {
|
||||
if (true) {
|
||||
__dummyTestFun__()
|
||||
}
|
||||
}
|
||||
|
||||
private fun __dummyTestFun__() {
|
||||
println("Hello world!")
|
||||
}
|
||||
+6
@@ -366,6 +366,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extractBlockContent.kt")
|
||||
public void testExtractBlockContent() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/extractBlockContent.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("fakeOverride.kt")
|
||||
public void testFakeOverride() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/fakeOverride.kt");
|
||||
|
||||
Reference in New Issue
Block a user