Fix false positive 'Introduce import alias' on this/super
This commit is contained in:
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.idea.imports.canBeAddedToImport
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceImportAlias.KotlinIntroduceImportAliasHandler
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.references.resolveMainReferenceToDescriptors
|
||||
import org.jetbrains.kotlin.psi.KtInstanceExpressionWithLabel
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
|
||||
class IntroduceImportAliasIntention : SelfTargetingRangeIntention<KtNameReferenceExpression>(
|
||||
@@ -18,6 +19,7 @@ class IntroduceImportAliasIntention : SelfTargetingRangeIntention<KtNameReferenc
|
||||
"Introduce import alias"
|
||||
) {
|
||||
override fun applicabilityRange(element: KtNameReferenceExpression): TextRange? {
|
||||
if (element.parent is KtInstanceExpressionWithLabel) return null
|
||||
if (element.mainReference.getImportAlias() != null) return null
|
||||
|
||||
val targets = element.resolveMainReferenceToDescriptors()
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: false
|
||||
open class SuperClass {
|
||||
fun check() {}
|
||||
}
|
||||
|
||||
class Test : SuperClass() {
|
||||
fun test2() {
|
||||
<caret>super.check()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// IS_APPLICABLE: false
|
||||
class Test {
|
||||
fun check() {}
|
||||
fun test2() {
|
||||
<caret>this.check()
|
||||
}
|
||||
}
|
||||
@@ -10125,6 +10125,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/notApplicableStar.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notApplicableSuper.kt")
|
||||
public void testNotApplicableSuper() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/notApplicableSuper.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notApplicableThis.kt")
|
||||
public void testNotApplicableThis() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/notApplicableThis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("onImport.kt")
|
||||
public void testOnImport() throws Exception {
|
||||
runTest("idea/testData/intentions/introduceImportAlias/onImport.kt");
|
||||
|
||||
Reference in New Issue
Block a user