KT-13536 related: correct handling of objects
(cherry picked from commit 7ae9b6b)
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6ac4bf3f17
commit
0ee1102e24
@@ -265,8 +265,8 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
if (import.importedFqName != declaration.fqName) {
|
||||
val importedDeclaration =
|
||||
import.importedReference?.getQualifiedElementSelector()?.mainReference?.resolve() as? KtNamedDeclaration
|
||||
return importedDeclaration == null ||
|
||||
(importedDeclaration != declaration && !hasNonTrivialUsages(importedDeclaration))
|
||||
?: return true
|
||||
return declaration !in importedDeclaration.parentsWithSelf && !hasNonTrivialUsages(importedDeclaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,6 @@
|
||||
<description>Function 'f' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>usedViaMemberImport.kt</file>
|
||||
<line>16</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="usedViaMemberImport.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused symbol</problem_class>
|
||||
<description>Class 'E3' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>usedViaMemberImport.kt</file>
|
||||
<line>20</line>
|
||||
|
||||
@@ -44,15 +44,6 @@
|
||||
<description>Function 'bar' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>usedViaMemberImport.kt</file>
|
||||
<line>10</line>
|
||||
<module>light_idea_test_case</module>
|
||||
<entry_point TYPE="file" FQNAME="usedViaMemberImport.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused symbol</problem_class>
|
||||
<description>Object 'O2' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>usedViaMemberImport.kt</file>
|
||||
<line>14</line>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Safe delete 'MyObj'" "false"
|
||||
// ACTION: Create test
|
||||
|
||||
import MyObj.foo
|
||||
|
||||
object <caret>MyObj {
|
||||
fun foo() {}
|
||||
}
|
||||
@@ -6934,6 +6934,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("importObjectFun.kt")
|
||||
public void testImportObjectFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeUnused/importObjectFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notTriangle.kt")
|
||||
public void testNotTriangle() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/removeUnused/notTriangle.kt");
|
||||
|
||||
Reference in New Issue
Block a user