Extract Function: Support multi-declaration initializers
#KT-5613 Fixed
This commit is contained in:
+2
-1
@@ -66,6 +66,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.lang.psi.JetMultiDeclaration
|
||||
|
||||
public open class ExtractKotlinFunctionHandlerHelper {
|
||||
open fun adjustGeneratorOptions(options: ExtractionGeneratorOptions): ExtractionGeneratorOptions = options
|
||||
@@ -206,7 +207,7 @@ fun selectElements(
|
||||
|
||||
val parent = declaration.getParent()?.let {
|
||||
when (it) {
|
||||
is JetProperty -> it.getParent()
|
||||
is JetProperty, is JetMultiDeclaration -> it.getParent()
|
||||
is JetParameterList -> it.getParent()?.getParent()
|
||||
else -> it
|
||||
}
|
||||
|
||||
+1
@@ -598,6 +598,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
val bodyElement = when (enclosingDeclaration) {
|
||||
is JetDeclarationWithBody -> enclosingDeclaration.getBodyExpression()
|
||||
is JetWithExpressionInitializer -> enclosingDeclaration.getInitializer()
|
||||
is JetMultiDeclaration -> enclosingDeclaration.getInitializer()
|
||||
is JetParameter -> enclosingDeclaration.getDefaultValue()
|
||||
is JetClassInitializer -> enclosingDeclaration.getBody()
|
||||
is JetClass -> {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
data class Pair<A, B>(val a: A, val b: B)
|
||||
fun <A, B> A.to(b: B) = Pair(this, b)
|
||||
|
||||
// SIBLING:
|
||||
fun foo() {
|
||||
val (a, b) = <selection>1 to 2</selection>
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
data class Pair<A, B>(val a: A, val b: B)
|
||||
fun <A, B> A.to(b: B) = Pair(this, b)
|
||||
|
||||
// SIBLING:
|
||||
fun foo() {
|
||||
val (a, b) = pair()
|
||||
}
|
||||
|
||||
private fun pair(): Pair<Int, Int> {
|
||||
return 1 to 2
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
data class Pair<A, B>(val a: A, val b: B)
|
||||
fun <A, B> A.to(b: B) = Pair(this, b)
|
||||
|
||||
// SIBLING:
|
||||
fun foo() {
|
||||
val (a, b) =
|
||||
if (true) {
|
||||
<selection>1 + 1</selection>
|
||||
1 to 2
|
||||
} else {
|
||||
2 to 3
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
data class Pair<A, B>(val a: A, val b: B)
|
||||
fun <A, B> A.to(b: B) = Pair(this, b)
|
||||
|
||||
// SIBLING:
|
||||
fun foo() {
|
||||
val (a, b) =
|
||||
if (true) {
|
||||
unit()
|
||||
1 to 2
|
||||
} else {
|
||||
2 to 3
|
||||
}
|
||||
}
|
||||
|
||||
private fun unit() {
|
||||
1 + 1
|
||||
}
|
||||
+10
@@ -974,6 +974,16 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/initializers/properties/memberPropertyWithLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/initializers/properties/multiDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedInMultiDeclaration.kt")
|
||||
public void testNestedInMultiDeclaration() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/initializers/properties/nestedInMultiDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelProperty.kt")
|
||||
public void testTopLevelProperty() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/initializers/properties/topLevelProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user