Kotlin: Support apply

This commit is contained in:
Tony Torralba
2023-07-10 16:14:37 +02:00
parent 3c3b53001f
commit 0f18c0227b
6 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Added support for the Kotlin method `apply`.

View File

@@ -3,5 +3,7 @@ extensions:
pack: codeql/java-all
extensible: summaryModel
data:
- ["kotlin", "StandardKt", False, "apply", "", "", "Argument[0]", "Argument[1].Parameter[0]", "value", "manual"]
- ["kotlin", "StandardKt", False, "apply", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
- ["kotlin", "StandardKt", False, "with", "", "", "Argument[0]", "Argument[1].Parameter[0]", "value", "manual"]
- ["kotlin", "StandardKt", False, "with", "", "", "Argument[1].ReturnValue", "ReturnValue", "value", "manual"]

View File

@@ -0,0 +1,21 @@
/** Provides classes and predicates related to `kotlin`. */
import java
/** A call to Kotlin's `apply` method. */
class KotlinApply extends MethodAccess {
ExtensionMethod m;
KotlinApply() {
this.getMethod() = m and
m.hasQualifiedName("kotlin", "StandardKt", "apply")
}
/** Gets the function block argument of this call. */
LambdaExpr getLambdaArg() {
result = this.getArgument(m.getExtensionReceiverParameterIndex() + 1)
}
/** Gets the receiver argument of this call. */
Argument getReceiver() { result = this.getArgument(m.getExtensionReceiverParameterIndex()) }
}