Extract Function: Fix 'this' label (extension case)
#KT-5456 Fixed
This commit is contained in:
+4
-2
@@ -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()}")
|
||||
|
||||
|
||||
+14
@@ -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
|
||||
}
|
||||
+18
@@ -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
|
||||
}
|
||||
+6
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user