Skip to content

Commit

Permalink
SONARKT-400 Migrate ReceivingIntentsCheck to kotlin-analysis-api
Browse files Browse the repository at this point in the history
  • Loading branch information
leveretka authored and Godin committed Dec 5, 2024
1 parent 096bf2e commit 6dceb23
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
package org.sonarsource.kotlin.checks

import org.jetbrains.kotlin.analysis.api.resolution.KaFunctionCall
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.psi.psiUtil.isNull
import org.sonar.check.Rule
import org.sonarsource.kotlin.api.checks.CallAbstractCheck
import org.sonarsource.kotlin.api.checks.FunMatcher
import org.sonarsource.kotlin.api.checks.isNull
import org.sonarsource.kotlin.api.checks.FunMatcherImpl
import org.sonarsource.kotlin.api.frontend.KotlinFileContext

@org.sonarsource.kotlin.api.frontend.K1only
@Rule(key = "S5322")
class ReceivingIntentsCheck : CallAbstractCheck() {
override val functionsToVisit = listOf(
Expand All @@ -33,11 +33,12 @@ class ReceivingIntentsCheck : CallAbstractCheck() {

override fun visitFunctionCall(
callExpression: KtCallExpression,
resolvedCall: ResolvedCall<*>,
resolvedCall: KaFunctionCall<*>,
matchedFun: FunMatcherImpl,
kotlinFileContext: KotlinFileContext
) {
val arguments = resolvedCall.valueArgumentsByIndex ?: return
if (arguments.size < 4 || arguments[2].isNull(kotlinFileContext.bindingContext)) {
val arguments = resolvedCall.argumentMapping.keys.toList()
if (arguments.size < 4 || arguments[2].isNull()) {
kotlinFileContext.reportIssue(callExpression.calleeExpression!!, "Make sure that intents are received safely here.")
}
}
Expand Down

0 comments on commit 6dceb23

Please sign in to comment.