Extract Function: Fix NPE when extracting this in object
#KT-6238 Fixed
This commit is contained in:
+5
@@ -120,6 +120,11 @@ class AddPrefixReplacement(override val parameter: Parameter): ParameterReplacem
|
||||
class FqNameReplacement(val fqName: FqName): Replacement {
|
||||
[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")]
|
||||
override fun invoke(e: JetElement): JetElement {
|
||||
val thisExpr = e.getParent() as? JetThisExpression
|
||||
if (thisExpr != null) {
|
||||
return thisExpr.replaced(JetPsiFactory(e).createExpression(fqName.asString())).getQualifiedElementSelector()!!
|
||||
}
|
||||
|
||||
val newExpr = (e.getReference() as? JetSimpleNameReference)?.bindToFqName(fqName, ShorteningMode.NO_SHORTENING) as JetElement
|
||||
return if (newExpr is JetQualifiedExpression) newExpr.getSelectorExpression()!! else newExpr
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package p
|
||||
|
||||
// SIBLING:
|
||||
object O {
|
||||
val a = 1
|
||||
fun test() {
|
||||
<selection>this.a</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package p
|
||||
|
||||
// SIBLING:
|
||||
object O {
|
||||
val a = 1
|
||||
fun test() {
|
||||
unit()
|
||||
}
|
||||
}
|
||||
|
||||
private fun unit() {
|
||||
O.a
|
||||
}
|
||||
+6
@@ -1625,6 +1625,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("thisInObject.kt")
|
||||
public void testThisInObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/misc/thisInObject.kt");
|
||||
doExtractFunctionTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeRef.kt")
|
||||
public void testTypeRef() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/extractFunction/parameters/misc/typeRef.kt");
|
||||
|
||||
Reference in New Issue
Block a user