Adjust getExtensionReceiverParameterIndex predicate name and change note

This commit is contained in:
Tamas Vajk
2022-12-09 10:23:54 +01:00
parent e410e2744b
commit 6bcfdfca88
5 changed files with 8 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
---
category: minorAnalysis
---
* The extraction of extension methods have been improved when default parameter values are present. The dispatch and extension receiver parameters are extracted in the correct order. The `ExtensionMethod::getExtensionParameterIndex` predicate has been introduced to facilitate getting the correct extension parameter index.
* The extraction of Kotlin extension methods has been improved when default parameter values are present. The dispatch and extension receiver parameters are extracted in the correct order. The `ExtensionMethod::getExtensionReceiverParameterIndex` predicate has been introduced to facilitate getting the correct extension parameter index.

View File

@@ -820,7 +820,7 @@ class ExtensionMethod extends Method {
* extension methods that are defined as members, the index is 1. Index 0 is the dispatch receiver of the `$default`
* method.
*/
int getExtensionParameterIndex() {
int getExtensionReceiverParameterIndex() {
if
exists(Method src |
this = src.getKotlinParameterDefaultsProxy() and

View File

@@ -91,7 +91,7 @@ class Parameter extends Element, @param, LocalScopeVariable {
/** Holds if this formal parameter is a parameter representing the dispatch receiver in an extension method. */
predicate isExtensionParameter() {
this.getPosition() = this.getCallable().(ExtensionMethod).getExtensionParameterIndex()
this.getPosition() = this.getCallable().(ExtensionMethod).getExtensionReceiverParameterIndex()
}
/**

View File

@@ -299,7 +299,8 @@ private class PathNormalizeSanitizer extends MethodAccess {
*/
private Expr getVisualQualifier(MethodAccess ma) {
if ma.getMethod() instanceof ExtensionMethod
then result = ma.getArgument(ma.getMethod().(ExtensionMethod).getExtensionParameterIndex())
then
result = ma.getArgument(ma.getMethod().(ExtensionMethod).getExtensionReceiverParameterIndex())
else result = ma.getQualifier()
}
@@ -313,7 +314,8 @@ private Argument getVisualArgument(MethodAccess ma, int argPos) {
if ma.getMethod() instanceof ExtensionMethod
then
result =
ma.getArgument(argPos + ma.getMethod().(ExtensionMethod).getExtensionParameterIndex() + 1)
ma.getArgument(argPos + ma.getMethod().(ExtensionMethod).getExtensionReceiverParameterIndex() +
1)
else result = ma.getArgument(argPos)
}

View File

@@ -29,7 +29,7 @@ query predicate extensionsMismatch(Method src, Method def) {
query predicate extensionIndex(ExtensionMethod m, int i, Type t) {
m.fromSource() and
m.getExtensionParameterIndex() = i and
m.getExtensionReceiverParameterIndex() = i and
m.getExtendedType() = t and
m.getParameter(i).getType() = t
}