From a5aad22fe736bc829f3c5bdb7119604847a31561 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Fri, 6 Apr 2018 07:27:27 +0300 Subject: [PATCH] Don't report "Redundant Companion reference" on accessing nested object So #KT-23620 Fixed --- .../inspections/RedundantCompanionReferenceInspection.kt | 3 ++- .../redundantCompanionReference/companionNestedObject.kt | 9 +++++++++ .../idea/inspections/LocalInspectionTestGenerated.java | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 idea/testData/inspectionsLocal/redundantCompanionReference/companionNestedObject.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt index 79d368ae975..e291455075b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType +import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject class RedundantCompanionReferenceInspection : AbstractKotlinInspection() { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { @@ -31,7 +32,7 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() { val grandParent = parent.parent as? KtQualifiedExpression if (grandParent != null) { val grandParentDescriptor = grandParent.resolveToCall()?.resultingDescriptor ?: return - if (grandParentDescriptor is ConstructorDescriptor) return + if (grandParentDescriptor is ConstructorDescriptor || grandParentDescriptor is FakeCallableDescriptorForObject) return } holder.registerProblem( diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionNestedObject.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/companionNestedObject.kt new file mode 100644 index 00000000000..deaba121711 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionNestedObject.kt @@ -0,0 +1,9 @@ +// PROBLEM: none + +class Owner { + companion object { + object InCompanion + } +} + +val y = Owner.Companion.InCompanion \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 41c7f680314..347a01561e6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -2805,6 +2805,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { doTest(fileName); } + @TestMetadata("companionNestedObject.kt") + public void testCompanionNestedObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantCompanionReference/companionNestedObject.kt"); + doTest(fileName); + } + @TestMetadata("directCompanion.kt") public void testDirectCompanion() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantCompanionReference/directCompanion.kt");