@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor
23
23
import org.jetbrains.kotlin.psi.KtProperty
24
24
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
25
25
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
26
- import org.jetbrains.kotlin.resolve.BindingContext
27
26
import org.sonar.check.Rule
28
27
import org.sonarsource.kotlin.api.checks.AbstractCheck
29
28
import org.sonarsource.kotlin.api.checks.ArgumentMatcher
@@ -41,31 +40,30 @@ private val EXPECTED_OVERRIDES = listOf(
41
40
}
42
41
)
43
42
44
- @org.sonarsource.kotlin.api.frontend.K1only
45
43
@Rule(key = " S6218" )
46
44
class EqualsOverriddenWithArrayFieldCheck : AbstractCheck () {
47
45
override fun visitClass (klass : KtClass , context : KotlinFileContext ) {
48
- if (! klass.isData() || ! klass.hasAnArrayProperty(context.bindingContext )) {
46
+ if (! klass.isData() || ! klass.hasAnArrayProperty()) {
49
47
return
50
48
}
51
- klass.buildIssueMessage(context.bindingContext )?.let { context.reportIssue(klass.nameIdentifier!! , it) }
49
+ klass.buildIssueMessage()?.let { context.reportIssue(klass.nameIdentifier!! , it) }
52
50
}
53
51
54
- private fun KtClass.hasAnArrayProperty (bindingContext : BindingContext ): Boolean {
52
+ private fun KtClass.hasAnArrayProperty (): Boolean {
55
53
// Because we only call this function on data classes, we can assume they have constructor
56
54
val constructor = this .findDescendantOfType<KtPrimaryConstructor >()!!
57
- val oneParameterIsAnArray = constructor .valueParameters.any { it.isAnArray(bindingContext ) }
55
+ val oneParameterIsAnArray = constructor .valueParameters.any { it.isAnArray() }
58
56
return if (oneParameterIsAnArray) {
59
57
true
60
58
} else {
61
- this .body?.properties?.any { it.isAnArray(bindingContext ) } ? : false
59
+ this .body?.properties?.any { it.isAnArray() } ? : false
62
60
}
63
61
}
64
62
65
- private fun KtClass.buildIssueMessage (bindingContext : BindingContext ): String? {
63
+ private fun KtClass.buildIssueMessage (): String? {
66
64
val functions = this .collectOverridingFunctions()
67
65
val missingFunctionNames = EXPECTED_OVERRIDES
68
- .filter { matcher -> ! functions.any { function -> matcher.matches(function, bindingContext ) } }
66
+ .filter { matcher -> ! functions.any { function -> matcher.matches(function) } }
69
67
.map { it.names.first() }
70
68
return when (missingFunctionNames.size) {
71
69
1 -> " Override ${missingFunctionNames[0 ]} to consider array content in the method."
@@ -78,9 +76,9 @@ class EqualsOverriddenWithArrayFieldCheck : AbstractCheck() {
78
76
this .collectDescendantsOfType<KtNamedFunction >()
79
77
.filter { it.overrides() }
80
78
81
- private fun KtParameter.isAnArray (bindingContext : BindingContext ): Boolean =
82
- this .determineTypeAsString(bindingContext, printTypeArguments = false ) == " kotlin.Array"
79
+ private fun KtParameter.isAnArray (): Boolean =
80
+ this .determineTypeAsString() == " kotlin.Array"
83
81
84
- private fun KtProperty.isAnArray (bindingContext : BindingContext ): Boolean =
85
- this .determineTypeAsString(bindingContext, printTypeArguments = false ) == " kotlin.Array"
82
+ private fun KtProperty.isAnArray (): Boolean =
83
+ this .determineTypeAsString() == " kotlin.Array"
86
84
}
0 commit comments