Fixed incorrect handling of this and super expressions in copy/paste processing and optimize imports
This commit is contained in:
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.references.JetMultiReference
|
|||||||
import org.jetbrains.kotlin.idea.references.JetReference
|
import org.jetbrains.kotlin.idea.references.JetReference
|
||||||
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
|
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
|
||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
|
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||||
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
import org.jetbrains.kotlin.idea.util.ImportInsertHelper
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
@@ -53,7 +54,6 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
import org.jetbrains.kotlin.psi.psiUtil.elementsInRange
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getReceiverExpression
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||||
@@ -156,8 +156,8 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
|
|||||||
|
|
||||||
if (!descriptor.isExtension) {
|
if (!descriptor.isExtension) {
|
||||||
if (element !is JetNameReferenceExpression) continue
|
if (element !is JetNameReferenceExpression) continue
|
||||||
if (element.getIdentifier() == null) continue // skip 'this' etc
|
if (CallTypeAndReceiver.detect(element).receiver != null) continue
|
||||||
if (element.getReceiverExpression() != null) continue
|
if (element.parent is JetThisExpression || element.parent is JetSuperExpression) continue // TODO: it's a bad design of PSI tree, we should change it
|
||||||
}
|
}
|
||||||
|
|
||||||
val fqName = descriptor.importableFqName ?: continue
|
val fqName = descriptor.importableFqName ?: continue
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
|||||||
if (!target.isExtension) { // for non-extension targets, count only non-qualified simple name usages
|
if (!target.isExtension) { // for non-extension targets, count only non-qualified simple name usages
|
||||||
if (element !is JetNameReferenceExpression) continue
|
if (element !is JetNameReferenceExpression) continue
|
||||||
if (CallTypeAndReceiver.detect(element).receiver != null) continue
|
if (CallTypeAndReceiver.detect(element).receiver != null) continue
|
||||||
|
if (element.parent is JetThisExpression || element.parent is JetSuperExpression) continue // TODO: it's a bad design of PSI tree, we should change it
|
||||||
}
|
}
|
||||||
|
|
||||||
val importableDescriptor = target.getImportableDescriptor()
|
val importableDescriptor = target.getImportableDescriptor()
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
open class `super`
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
class A : b.`super`() {
|
||||||
|
fun f() {
|
||||||
|
this.f()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getUsableSpace(): Long {
|
||||||
|
return super.getUsableSpace()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun g() {
|
||||||
|
this.g()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
class A : b.`super`() {
|
||||||
|
fun f() {
|
||||||
|
this.f()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getUsableSpace(): Long {
|
||||||
|
return super.getUsableSpace()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun g() {
|
||||||
|
this.g()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -209,6 +209,12 @@ public class OptimizeImportsTestGenerated extends AbstractOptimizeImportsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ThisAndSuper.kt")
|
||||||
|
public void testThisAndSuper() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/ThisAndSuper.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("UnusedImports.kt")
|
@TestMetadata("UnusedImports.kt")
|
||||||
public void testUnusedImports() throws Exception {
|
public void testUnusedImports() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/UnusedImports.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/editor/optimizeImports/UnusedImports.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user