From 5c4e0341712fb56d9a8ac36186c341b859f68722 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 8 Sep 2017 16:43:26 +0300 Subject: [PATCH] Unused symbol: do not search for internal member light methods Use direct references search instead So #KT-19811 Fixed --- .../idea/inspections/UnusedSymbolInspection.kt | 2 +- .../inspectionsLocal/unusedSymbol/.inspection | 1 + .../inspectionsLocal/unusedSymbol/internal.kt | 9 +++++++++ .../inspections/LocalInspectionTestGenerated.java | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/unusedSymbol/.inspection create mode 100644 idea/testData/inspectionsLocal/unusedSymbol/internal.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt index f570baa64f5..71a40fea87e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt @@ -274,7 +274,7 @@ class UnusedSymbolInspection : AbstractKotlinInspection() { return false } - if (declaration is KtCallableDeclaration) { + if (declaration is KtCallableDeclaration && !declaration.hasModifier(KtTokens.INTERNAL_KEYWORD)) { val lightMethods = declaration.toLightMethods() if (lightMethods.isNotEmpty()) { return lightMethods.any { method -> diff --git a/idea/testData/inspectionsLocal/unusedSymbol/.inspection b/idea/testData/inspectionsLocal/unusedSymbol/.inspection new file mode 100644 index 00000000000..92d81ff196a --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.UnusedSymbolInspection \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/unusedSymbol/internal.kt b/idea/testData/inspectionsLocal/unusedSymbol/internal.kt new file mode 100644 index 00000000000..9d60229cc49 --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/internal.kt @@ -0,0 +1,9 @@ +// PROBLEM: none + +class Foo { + fun test() { + abacaba("") + } + + internal fun abacaba(s: String): String = s +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 8831197735d..db8746ff195 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -1842,6 +1842,21 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/unusedSymbol") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class UnusedSymbol extends AbstractLocalInspectionTest { + public void testAllFilesPresentInUnusedSymbol() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/unusedSymbol"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("internal.kt") + public void testInternal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/unusedSymbol/internal.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/inspectionsLocal/useExpressionBody") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)