From 0ee1102e24e2ef04331aea01da5366e5b65df648 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 24 Aug 2016 19:13:17 +0300 Subject: [PATCH] KT-13536 related: correct handling of objects (cherry picked from commit 7ae9b6b) --- .../kotlin/idea/inspections/UnusedSymbolInspection.kt | 4 ++-- .../unusedSymbol/enum/inspectionData/expected.xml | 9 --------- .../unusedSymbol/object/inspectionData/expected.xml | 9 --------- idea/testData/quickfix/removeUnused/importObjectFun.kt | 8 ++++++++ .../kotlin/idea/quickfix/QuickFixTestGenerated.java | 6 ++++++ 5 files changed, 16 insertions(+), 20 deletions(-) create mode 100644 idea/testData/quickfix/removeUnused/importObjectFun.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt index 798ec4b44f8..a7fdb839926 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt @@ -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) } } } diff --git a/idea/testData/inspections/unusedSymbol/enum/inspectionData/expected.xml b/idea/testData/inspections/unusedSymbol/enum/inspectionData/expected.xml index 53d8bd62c2d..575b4734672 100644 --- a/idea/testData/inspections/unusedSymbol/enum/inspectionData/expected.xml +++ b/idea/testData/inspections/unusedSymbol/enum/inspectionData/expected.xml @@ -8,15 +8,6 @@ Function 'f' is never used - - usedViaMemberImport.kt - 16 - light_idea_test_case - - Unused symbol - Class 'E3' is never used - - usedViaMemberImport.kt 20 diff --git a/idea/testData/inspections/unusedSymbol/object/inspectionData/expected.xml b/idea/testData/inspections/unusedSymbol/object/inspectionData/expected.xml index 4f234e1dfe5..590bef56aa9 100644 --- a/idea/testData/inspections/unusedSymbol/object/inspectionData/expected.xml +++ b/idea/testData/inspections/unusedSymbol/object/inspectionData/expected.xml @@ -44,15 +44,6 @@ Function 'bar' is never used - - usedViaMemberImport.kt - 10 - light_idea_test_case - - Unused symbol - Object 'O2' is never used - - usedViaMemberImport.kt 14 diff --git a/idea/testData/quickfix/removeUnused/importObjectFun.kt b/idea/testData/quickfix/removeUnused/importObjectFun.kt new file mode 100644 index 00000000000..ca9d6ea576e --- /dev/null +++ b/idea/testData/quickfix/removeUnused/importObjectFun.kt @@ -0,0 +1,8 @@ +// "Safe delete 'MyObj'" "false" +// ACTION: Create test + +import MyObj.foo + +object MyObj { + fun foo() {} +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 8e492ab0e59..8dd56fa1b4c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -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");