Redundant companion reference: Fix false positive in enum entry #KT-27861 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
d88fd8aa6f
commit
7a9effe30d
+4
-3
@@ -40,6 +40,7 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
||||
if (expression.text != objectDeclaration.name) return
|
||||
|
||||
val containingClass = objectDeclaration.containingClass() ?: return
|
||||
if (parent.getStrictParentOfType<KtEnumEntry>()?.containingClass() == containingClass) return
|
||||
val containingClassDescriptor = containingClass.descriptor as? ClassDescriptor ?: return
|
||||
val selectorDescriptor = selectorExpression?.getCallableDescriptor()
|
||||
when (selectorDescriptor) {
|
||||
@@ -52,9 +53,9 @@ class RedundantCompanionReferenceInspection : AbstractKotlinInspection() {
|
||||
is FunctionDescriptor -> {
|
||||
val name = selectorDescriptor.name
|
||||
val function = containingClass.findFunctionByName(name.asString())?.descriptor
|
||||
?: expression.getResolutionScope().findFunction(name, NoLookupLocation.FROM_IDE)?.takeIf {
|
||||
it.isLocalOrExtension(containingClassDescriptor)
|
||||
}
|
||||
?: expression.getResolutionScope().findFunction(name, NoLookupLocation.FROM_IDE)?.takeIf {
|
||||
it.isLocalOrExtension(containingClassDescriptor)
|
||||
}
|
||||
if (function is FunctionDescriptor) {
|
||||
val functionParams = function.valueParameters
|
||||
val calleeParams =
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
enum class E {
|
||||
E1;
|
||||
|
||||
fun test() {
|
||||
bar(<caret>Companion.foo)
|
||||
}
|
||||
|
||||
fun bar(s: String) {}
|
||||
|
||||
companion object {
|
||||
const val foo = ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
enum class E {
|
||||
E1;
|
||||
|
||||
fun test() {
|
||||
bar(foo)
|
||||
}
|
||||
|
||||
fun bar(s: String) {}
|
||||
|
||||
companion object {
|
||||
const val foo = ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// PROBLEM: none
|
||||
// DISABLE-ERRORS
|
||||
|
||||
enum class E(val value: String) {
|
||||
E1(<caret>Companion.foo);
|
||||
|
||||
companion object {
|
||||
const val foo = ""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
enum class E(val value: String) {
|
||||
E1(A.<caret>Companion.foo);
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
const val foo = ""
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
enum class E(val value: String) {
|
||||
E1(A.foo);
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
const val foo = ""
|
||||
}
|
||||
}
|
||||
+15
@@ -3926,6 +3926,21 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/import.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inEnum.kt")
|
||||
public void testInEnum() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/inEnum.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inEnumEntry.kt")
|
||||
public void testInEnumEntry() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inEnumEntry2.kt")
|
||||
public void testInEnumEntry2() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/inEnumEntry2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("methodArgument.kt")
|
||||
public void testMethodArgument() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/redundantCompanionReference/methodArgument.kt");
|
||||
|
||||
Reference in New Issue
Block a user