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>,
|
elements: List<PsiElement>,
|
||||||
targetSibling: PsiElement
|
targetSibling: PsiElement
|
||||||
) {
|
) {
|
||||||
fun adjustElements(elements: List<PsiElement>): List<PsiElement> {
|
val adjustedElements = (elements.singleOrNull() as? JetBlockExpression)?.getStatements() ?: elements
|
||||||
if (elements.size() != 1) return elements
|
val extractionData = ExtractionData(file, adjustedElements.toRange(false), targetSibling)
|
||||||
|
|
||||||
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)
|
|
||||||
ExtractionEngine(helper).run(editor, extractionData) {
|
ExtractionEngine(helper).run(editor, extractionData) {
|
||||||
processDuplicates(it.duplicateReplacers, file.getProject(), editor)
|
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);
|
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")
|
@TestMetadata("fakeOverride.kt")
|
||||||
public void testFakeOverride() throws Exception {
|
public void testFakeOverride() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/fakeOverride.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/basic/fakeOverride.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user