@@ -42,7 +42,8 @@ private newtype TParameterImpl =
4242 TInternalParameter ( Internal:: Parameter p ) or
4343 TUnderscore ( Scope scope ) {
4444 exists ( VarAccess va | va .getUserPath ( ) = "_" and scope = va .getEnclosingScope ( ) )
45- }
45+ } or
46+ TThisParameter ( Scope scope ) { exists ( scope .getEnclosingFunction ( ) .getDeclaringType ( ) ) }
4647
4748private class ParameterImpl extends TParameterImpl {
4849 abstract Location getLocation ( ) ;
@@ -109,9 +110,22 @@ private class Underscore extends ParameterImpl, TUnderscore {
109110 final override Scope getEnclosingScope ( ) { result = scope }
110111}
111112
113+ private class ThisParameter extends ParameterImpl , TThisParameter {
114+ Scope scope ;
115+
116+ ThisParameter ( ) { this = TThisParameter ( scope ) }
117+
118+ override Location getLocation ( ) { result = scope .getLocation ( ) }
119+
120+ override string getName ( ) { result = "this" }
121+
122+ final override Scope getEnclosingScope ( ) { result = scope }
123+ }
124+
112125private newtype TVariable =
113126 TLocalVariable ( string name , Scope scope ) {
114127 not isParameterImpl ( name , scope ) and
128+ not name = "this" and // This is modeled as a parameter
115129 exists ( VarAccess va | va .getUserPath ( ) = name and scope = va .getEnclosingScope ( ) )
116130 } or
117131 TParameter ( ParameterImpl p )
@@ -186,8 +200,11 @@ class Parameter extends AbstractLocalScopeVariable, TParameter {
186200
187201 predicate hasDefaultValue ( ) { exists ( this .getDefaultValue ( ) ) }
188202
203+ /** Holds if this is the `this` parameter. */
204+ predicate isThis ( ) { p instanceof ThisParameter }
205+
189206 /**
190- * Gets the index of this parameter.
207+ * Gets the index of this parameter, if any .
191208 *
192209 * The parameter may be in a parameter block or a function parameter.
193210 */
0 commit comments