Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ReceivingIntentsCheck to kotlin-analysis-api #506

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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