Create ExtensionMethodAccess class

This commit is contained in:
Tony Torralba
2022-03-10 11:44:13 +01:00
committed by Ian Lynagh
parent 270beecef5
commit fcb334180d
8 changed files with 83 additions and 22 deletions

View File

@@ -550,12 +550,23 @@ private module ControlFlowGraphImpl {
or
index = 0 and result = this.(RValue).getQualifier() and not result instanceof TypeAccess
or
exists(Call e | e = this |
exists(Call e | e = this and not e instanceof ExtensionMethodAccess |
index = -1 and result = e.getQualifier() and not result instanceof TypeAccess
or
result = e.getArgument(index)
)
or
exists(ExtensionMethodAccess e | e = this |
// the actual qualifier of the expression method access
index = -1 and result.(Expr).isNthChildOf(this, index)
or
// the extension receiver
index = 0 and result = e.getQualifier()
or
// the arguments
result = e.getArgument(index)
)
or
exists(StringTemplateExpr e | e = this | result = e.getComponent(index))
or
index = 0 and result = this.(ClassExpr).getExpr()

View File

@@ -1957,6 +1957,22 @@ class MethodAccess extends Expr, Call, @methodaccess {
override string getAPrimaryQlClass() { result = "MethodAccess" }
}
/**
* An invocation of a Kotlin `ExtensionMethod`.
*
* The syntactical qualifier of an extension method is its receiver (arg 0),
* whereas the actual arguments begin at index 1.
*/
class ExtensionMethodAccess extends MethodAccess {
ExtensionMethodAccess() { this.getMethod() instanceof ExtensionMethod }
override Expr getQualifier() { result.isNthChildOf(this, 0) }
override Expr getAnArgument() { result.getIndex() >= 1 and result.getParent() = this }
override Expr getArgument(int index) { result = super.getArgument(index + 1) }
}
/** A type access is a (possibly qualified) reference to a type. */
class TypeAccess extends Expr, Annotatable, @typeaccess {
/** Gets the qualifier of this type access, if any. */