Import as alias with another name is now counted as usage itself #KT-11933 Fixed
This commit is contained in:
@@ -251,6 +251,9 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
as? KtClassOrObject ?: return true
|
||||
return importedFrom.declarations.none { it is KtNamedDeclaration && hasNonTrivialUsages(it) }
|
||||
}
|
||||
else if (import.aliasName != null && import.aliasName != declaration.name) {
|
||||
return false
|
||||
}
|
||||
else {
|
||||
if (import.importedFqName != declaration.fqName) {
|
||||
val importedDeclaration = import.importedReference?.getQualifiedElementSelector()?.mainReference?.resolve() as? KtNamedDeclaration
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import Imported as Alias
|
||||
|
||||
object <caret>Imported
|
||||
+1
@@ -0,0 +1 @@
|
||||
Usage in import 2 import Imported as Alias
|
||||
@@ -0,0 +1,5 @@
|
||||
import <caret>Imported as Alias
|
||||
|
||||
object Imported
|
||||
|
||||
// REF: (<root>).Imported
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Safe delete 'Imported'" "false"
|
||||
// ACTION: Create test
|
||||
// ACTION: Move 'Imported' to separate file
|
||||
import Imported as Alias
|
||||
|
||||
object <caret>Imported
|
||||
|
||||
fun use() {
|
||||
Alias.hashCode()
|
||||
}
|
||||
@@ -744,6 +744,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinImportedObjectUsages.0.kt")
|
||||
public void testKotlinImportedObjectUsages() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findObjectUsages/kotlinImportedObjectUsages.0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinLocalObjectUsages1.0.kt")
|
||||
public void testKotlinLocalObjectUsages1() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findObjectUsages/kotlinLocalObjectUsages1.0.kt");
|
||||
|
||||
+6
@@ -125,6 +125,12 @@ public class KotlinGotoImplementationTestGenerated extends AbstractKotlinGotoImp
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ObjectImported.kt")
|
||||
public void testObjectImported() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/implementations/ObjectImported.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("OverridesInEnumEntries.kt")
|
||||
public void testOverridesInEnumEntries() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/navigation/implementations/OverridesInEnumEntries.kt");
|
||||
|
||||
@@ -6477,6 +6477,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeUnused/unusedTypeParameter.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("usedObjectAsAlias.kt")
|
||||
public void testUsedObjectAsAlias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeUnused/usedObjectAsAlias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/removeUnusedReceiver")
|
||||
|
||||
Reference in New Issue
Block a user