diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt index c0d470a45dc..58a0716cbe1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RedundantCompanionReferenceInspection.kt @@ -40,6 +40,7 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() { if (expression.text != objectDeclaration.name) return val containingClass = objectDeclaration.containingClass() ?: return + if (expression.containingClass() != containingClass && expression == parent.receiverExpression) return if (parent.getStrictParentOfType()?.containingClass() == containingClass) return val containingClassDescriptor = containingClass.descriptor as? ClassDescriptor ?: return val selectorDescriptor = selectorExpression?.getCallableDescriptor() diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt new file mode 100644 index 00000000000..8fa5ebcb823 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt @@ -0,0 +1,9 @@ +class Companion { + fun test() { + Companion.foo + } + + companion object { + val foo = "" + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt.after b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt.after new file mode 100644 index 00000000000..6cc668b5006 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt.after @@ -0,0 +1,9 @@ +class Companion { + fun test() { + foo + } + + companion object { + val foo = "" + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt new file mode 100644 index 00000000000..79dce4dc135 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt @@ -0,0 +1,10 @@ +class Test { + fun test() { + Companion.Companion.foo + } +} +class Companion { + companion object { + val foo = "" + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt.after b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt.after new file mode 100644 index 00000000000..3a2f0c5018f --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt.after @@ -0,0 +1,10 @@ +class Test { + fun test() { + Companion.foo + } +} +class Companion { + companion object { + val foo = "" + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass3.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass3.kt new file mode 100644 index 00000000000..184a4f61553 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass3.kt @@ -0,0 +1,12 @@ +// PROBLEM: none + +class Test { + fun test() { + Companion.foo + } +} +class Companion { + companion object { + val foo = "" + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass4.kt b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass4.kt new file mode 100644 index 00000000000..cb5403dd5d1 --- /dev/null +++ b/idea/testData/inspectionsLocal/redundantCompanionReference/companionClass4.kt @@ -0,0 +1,13 @@ +// PROBLEM: none + +class Test { + fun test() { + Companion.foo + } + + class Companion { + companion object { + val foo = "" + } + } +} \ 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 7c82c425738..93853fff690 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -3896,6 +3896,26 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/redundantCompanionReference/basic.kt"); } + @TestMetadata("companionClass.kt") + public void testCompanionClass() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionClass.kt"); + } + + @TestMetadata("companionClass2.kt") + public void testCompanionClass2() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionClass2.kt"); + } + + @TestMetadata("companionClass3.kt") + public void testCompanionClass3() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionClass3.kt"); + } + + @TestMetadata("companionClass4.kt") + public void testCompanionClass4() throws Exception { + runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionClass4.kt"); + } + @TestMetadata("companionDoubleNested.kt") public void testCompanionDoubleNested() throws Exception { runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionDoubleNested.kt");