Skip to content

Commit

Permalink
SONARKT-423 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 Jan 10, 2025
1 parent 8882ff2 commit f1ad28e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ fun Call.findCallInPrecedingCallChain(matcher: FunMatcherImpl, bindingContext: B
return receiver to receiverResolved
}

@Deprecated("use kotlin-analysis-api instead", ReplaceWith("this.predictRuntimeValueExpression().isNull()", imports = arrayOf("org.jetbrains.kotlin.psi.psiUtil.isNull")))
fun ResolvedValueArgument.isNull(bindingContext: BindingContext) = (
(this as? ExpressionValueArgument)
?.valueArgument
Expand Down
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.predictRuntimeValueExpression
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,11 @@ class ReceivingIntentsCheck : CallAbstractCheck() {

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

0 comments on commit f1ad28e

Please sign in to comment.