@@ -29,7 +29,26 @@ newtype TType =
2929abstract class Type extends TType {
3030 /** Gets the method `name` belonging to this type, if any. */
3131 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 ) ;
3352
3453 /** Gets the struct field `name` belonging to this type, if any. */
3554 pragma [ nomagic]
@@ -74,7 +93,7 @@ abstract class Type extends TType {
7493abstract private class StructOrEnumType extends Type {
7594 abstract ItemNode asItemNode ( ) ;
7695
77- final override Function getMethod ( string name ) {
96+ final override Function getAMethod ( string name ) {
7897 result = this .asItemNode ( ) .getASuccessor ( name ) and
7998 exists ( ImplOrTraitItemNode impl | result = impl .getAnAssocItem ( ) |
8099 impl instanceof Trait
@@ -138,7 +157,7 @@ class TraitType extends Type, TTrait {
138157
139158 TraitType ( ) { this = TTrait ( trait ) }
140159
141- override Function getMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
160+ override Function getAMethod ( string name ) { result = trait .( ItemNode ) .getASuccessor ( name ) }
142161
143162 override StructField getStructField ( string name ) { none ( ) }
144163
@@ -220,7 +239,7 @@ class ImplType extends Type, TImpl {
220239
221240 ImplType ( ) { this = TImpl ( impl ) }
222241
223- override Function getMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
242+ override Function getAMethod ( string name ) { result = impl .( ItemNode ) .getASuccessor ( name ) }
224243
225244 override StructField getStructField ( string name ) { none ( ) }
226245
@@ -247,7 +266,7 @@ class ImplType extends Type, TImpl {
247266class ArrayType extends Type , TArrayType {
248267 ArrayType ( ) { this = TArrayType ( ) }
249268
250- override Function getMethod ( string name ) { none ( ) }
269+ override Function getAMethod ( string name ) { none ( ) }
251270
252271 override StructField getStructField ( string name ) { none ( ) }
253272
@@ -273,7 +292,7 @@ class ArrayType extends Type, TArrayType {
273292class RefType extends Type , TRefType {
274293 RefType ( ) { this = TRefType ( ) }
275294
276- override Function getMethod ( string name ) { none ( ) }
295+ override Function getAMethod ( string name ) { none ( ) }
277296
278297 override StructField getStructField ( string name ) { none ( ) }
279298
@@ -318,7 +337,7 @@ class TypeParamTypeParameter extends TypeParameter, TTypeParamTypeParameter {
318337
319338 TypeParam getTypeParam ( ) { result = typeParam }
320339
321- override Function getMethod ( string name ) {
340+ override Function getAMethod ( string name ) {
322341 // NOTE: If the type parameter has trait bounds, then this finds methods
323342 // on the bounding traits.
324343 result = typeParam .( ItemNode ) .getASuccessor ( name )
@@ -377,7 +396,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
377396
378397 int getIndex ( ) { traitAliasIndex ( _, result , typeAlias ) }
379398
380- override Function getMethod ( string name ) { none ( ) }
399+ override Function getAMethod ( string name ) { none ( ) }
381400
382401 override string toString ( ) { result = typeAlias .getName ( ) .getText ( ) }
383402
@@ -388,7 +407,7 @@ class AssociatedTypeTypeParameter extends TypeParameter, TAssociatedTypeTypePara
388407
389408/** An implicit reference type parameter. */
390409class RefTypeParameter extends TypeParameter , TRefTypeParameter {
391- override Function getMethod ( string name ) { none ( ) }
410+ override Function getAMethod ( string name ) { none ( ) }
392411
393412 override string toString ( ) { result = "&T" }
394413
@@ -411,7 +430,7 @@ class SelfTypeParameter extends TypeParameter, TSelfTypeParameter {
411430
412431 override TypeMention getABaseTypeMention ( ) { result = trait }
413432
414- override Function getMethod ( string name ) {
433+ override Function getAMethod ( string name ) {
415434 // The `Self` type parameter is an implementation of the trait, so it has
416435 // all the trait's methods.
417436 result = trait .( ItemNode ) .getASuccessor ( name )
0 commit comments