Don't report "Redundant Companion reference" on accessing nested object

So #KT-23620 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-04-06 07:27:27 +03:00
committed by Mikhail Glukhikh
parent 94c5344fd1
commit a5aad22fe7
3 changed files with 17 additions and 1 deletions
@@ -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(
@@ -0,0 +1,9 @@
// PROBLEM: none
class Owner {
companion object {
object InCompanion
}
}
val y = Owner.<caret>Companion.InCompanion
@@ -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");