Don't report "Redundant Companion reference" on accessing nested object
So #KT-23620 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
94c5344fd1
commit
a5aad22fe7
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
|
|||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||||
|
|
||||||
class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
|
||||||
@@ -31,7 +32,7 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
|||||||
val grandParent = parent.parent as? KtQualifiedExpression
|
val grandParent = parent.parent as? KtQualifiedExpression
|
||||||
if (grandParent != null) {
|
if (grandParent != null) {
|
||||||
val grandParentDescriptor = grandParent.resolveToCall()?.resultingDescriptor ?: return
|
val grandParentDescriptor = grandParent.resolveToCall()?.resultingDescriptor ?: return
|
||||||
if (grandParentDescriptor is ConstructorDescriptor) return
|
if (grandParentDescriptor is ConstructorDescriptor || grandParentDescriptor is FakeCallableDescriptorForObject) return
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
|
|||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
|
||||||
|
class Owner {
|
||||||
|
companion object {
|
||||||
|
object InCompanion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val y = Owner.<caret>Companion.InCompanion
|
||||||
+6
@@ -2805,6 +2805,12 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("directCompanion.kt")
|
||||||
public void testDirectCompanion() throws Exception {
|
public void testDirectCompanion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantCompanionReference/directCompanion.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/redundantCompanionReference/directCompanion.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user