Extract Function: Fix 'this' label (extension case)

#KT-5456 Fixed
This commit is contained in:
Alexey Sedunov
2015-01-13 15:37:22 +03:00
parent 941e08b80f
commit d54b261c61
4 changed files with 42 additions and 2 deletions
@@ -622,8 +622,10 @@ private fun ExtractionData.inferParametersInfo(
val parameter = extractedDescriptorToParameter.getOrPut(descriptorToExtract) {
val argumentText =
if (hasThisReceiver && extractThis)
"this@${parameterType.getConstructor().getDeclarationDescriptor()!!.getName().asString()}"
if (hasThisReceiver && extractThis) {
val label = if (descriptorToExtract is ClassDescriptor) "@${descriptorToExtract.getName().asString()}" else ""
"this$label"
}
else
(thisExpr ?: ref).getText() ?: throw AssertionError("'this' reference shouldn't be empty: code fragment = ${getCodeFragmentText()}")
@@ -0,0 +1,14 @@
// PARAM_TYPES: A
// PARAM_TYPES: B
// PARAM_DESCRIPTOR: internal final class A defined in root package
// PARAM_DESCRIPTOR: internal final fun B.foo(): Int defined in A
// SIBLING:
class A {
val a = 1
fun B.foo() = <selection>a + b</selection>
}
class B {
val b = 1
}
@@ -0,0 +1,18 @@
// PARAM_TYPES: A
// PARAM_TYPES: B
// PARAM_DESCRIPTOR: internal final class A defined in root package
// PARAM_DESCRIPTOR: internal final fun B.foo(): Int defined in A
// SIBLING:
class A {
val a = 1
fun B.foo() = i(this@A, this)
}
private fun i(a1: A, b: B): Int {
return a1.a + b.b
}
class B {
val b = 1
}
@@ -1639,6 +1639,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/extractThis/implicitThisInMember.kt");
doExtractFunctionTest(fileName);
}
@TestMetadata("qualifiedThisAsArgument.kt")
public void testQualifiedThisAsArgument() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/extractThis/qualifiedThisAsArgument.kt");
doExtractFunctionTest(fileName);
}
}
@TestMetadata("idea/testData/refactoring/extractFunction/parameters/it")