Redundant companion reference: fix false positive for class with name Companion #KT-27861 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
4b8f8604f2
commit
d0d98dc283
+1
@@ -40,6 +40,7 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
|||||||
if (expression.text != objectDeclaration.name) return
|
if (expression.text != objectDeclaration.name) return
|
||||||
|
|
||||||
val containingClass = objectDeclaration.containingClass() ?: return
|
val containingClass = objectDeclaration.containingClass() ?: return
|
||||||
|
if (expression.containingClass() != containingClass && expression == parent.receiverExpression) return
|
||||||
if (parent.getStrictParentOfType<KtEnumEntry>()?.containingClass() == containingClass) return
|
if (parent.getStrictParentOfType<KtEnumEntry>()?.containingClass() == containingClass) return
|
||||||
val containingClassDescriptor = containingClass.descriptor as? ClassDescriptor ?: return
|
val containingClassDescriptor = containingClass.descriptor as? ClassDescriptor ?: return
|
||||||
val selectorDescriptor = selectorExpression?.getCallableDescriptor()
|
val selectorDescriptor = selectorExpression?.getCallableDescriptor()
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class Companion {
|
||||||
|
fun test() {
|
||||||
|
<caret>Companion.foo
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
class Companion {
|
||||||
|
fun test() {
|
||||||
|
foo
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
class Test {
|
||||||
|
fun test() {
|
||||||
|
Companion.<caret>Companion.foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Companion {
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
class Test {
|
||||||
|
fun test() {
|
||||||
|
Companion.foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Companion {
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
fun test() {
|
||||||
|
<caret>Companion.foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class Companion {
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// PROBLEM: none
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
fun test() {
|
||||||
|
<caret>Companion.foo
|
||||||
|
}
|
||||||
|
|
||||||
|
class Companion {
|
||||||
|
companion object {
|
||||||
|
val foo = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -3896,6 +3896,26 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
|||||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/basic.kt");
|
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")
|
@TestMetadata("companionDoubleNested.kt")
|
||||||
public void testCompanionDoubleNested() throws Exception {
|
public void testCompanionDoubleNested() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionDoubleNested.kt");
|
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/companionDoubleNested.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user