@@ -29,7 +29,26 @@ newtype TType =
29
29
abstract class Type extends TType {
30
30
/** Gets the method `name` belonging to this type, if any. */
31
31
pragma [ nomagic]
32
- abstract Function getMethod ( string name ) ;
32
+ final Function getMethod ( string name ) {
33
+ result = this .getAMethod ( name ) and
34
+ (
35
+ // when a method exists in both source code and in library code, it is because
36
+ // we also extracted the source code as library code, and hence we only want
37
+ // the method from source code
38
+ result .fromSource ( )
39
+ or
40
+ not this .getAMethod ( name ) .fromSource ( )
41
+ )
42
+ }
43
+
44
+ /**
45
+ * Gets a method `name` belonging to this type, if any.
46
+ *
47
+ * Multiple methods may exist with the same name when it exists in both
48
+ * source code and in library code.
49
+ */
50
+ pragma [ nomagic]
51
+ abstract Function getAMethod ( string name ) ;
33
52
34
53
/** Gets the struct field `name` belonging to this type, if any. */
35
54
pragma [ nomagic]
@@ -74,7 +93,7 @@ abstract class Type extends TType {
74
93
abstract private class StructOrEnumType extends Type {
75
94
abstract ItemNode asItemNode ( ) ;
76
95
77
- final override Function getMethod ( string name ) {
96
+ final override Function getAMethod ( string name ) {
78
97
result = this .asItemNode ( ) .getASuccessor ( name ) and
79
98
exists ( ImplOrTraitItemNode impl | result = impl .getAnAssocItem ( ) |
80
99
impl instanceof Trait
@@ -138,7 +157,7 @@ class TraitType extends Type, TTrait {
138
157
139
158
TraitType ( ) { this = TTrait ( trait ) }
140
159
141
- override Function getMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
160
+ override Function getAMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
142
161
143
162
override StructField getStructField ( string name ) { none ( ) }
144
163
@@ -220,7 +239,7 @@ class ImplType extends Type, TImpl {
220
239
221
240
ImplType ( ) { this = TImpl ( impl ) }
222
241
223
- override Function getMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
242
+ override Function getAMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
224
243
225
244
override StructField getStructField ( string name ) { none ( ) }
226
245
@@ -247,7 +266,7 @@ class ImplType extends Type, TImpl {
247
266
class ArrayType extends Type , TArrayType {
248
267
ArrayType ( ) { this = TArrayType ( ) }
249
268
250
- override Function getMethod ( string name ) { none ( ) }
269
+ override Function getAMethod ( string name ) { none ( ) }
251
270
252
271
override StructField getStructField ( string name ) { none ( ) }
253
272
@@ -273,7 +292,7 @@ class ArrayType extends Type, TArrayType {
273
292
class RefType extends Type , TRefType {
274
293
RefType ( ) { this = TRefType ( ) }
275
294
276
- override Function getMethod ( string name ) { none ( ) }
295
+ override Function getAMethod ( string name ) { none ( ) }
277
296
278
297
override StructField getStructField ( string name ) { none ( ) }
279
298
@@ -318,7 +337,7 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
318
337
319
338
TypeParam getTypeParam ( ) { result = typeParam }
320
339
321
- override Function getMethod ( string name ) {
340
+ override Function getAMethod ( string name ) {
322
341
// NOTE: If the type parameter has trait bounds, then this finds methods
323
342
// on the bounding traits.
324
343
result = typeParam .( ItemNode ) .getASuccessor ( name )
@@ -377,7 +396,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
377
396
378
397
int getIndex ( ) { traitAliasIndex ( _, result , typeAlias ) }
379
398
380
- override Function getMethod ( string name ) { none ( ) }
399
+ override Function getAMethod ( string name ) { none ( ) }
381
400
382
401
override string toString ( ) { result = typeAlias .getName ( ) .getText ( ) }
383
402
@@ -388,7 +407,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
388
407
389
408
/** An implicit reference type parameter. */
390
409
class RefTypeParameter extends TypeParameter , TRefTypeParameter {
391
- override Function getMethod ( string name ) { none ( ) }
410
+ override Function getAMethod ( string name ) { none ( ) }
392
411
393
412
override string toString ( ) { result = "&T" }
394
413
@@ -411,7 +430,7 @@ class SelfTypeParameter extends TypeParameter, TSelfTypeParameter {
411
430
412
431
override TypeMention getABaseTypeMention ( ) { result = trait }
413
432
414
- override Function getMethod ( string name ) {
433
+ override Function getAMethod ( string name ) {
415
434
// The `Self` type parameter is an implementation of the trait, so it has
416
435
// all the trait's methods.
417
436
result = trait .( ItemNode ) .getASuccessor ( name )
0 commit comments