@@ -28,11 +28,16 @@ class TestLibrary extends RefType {
2828 * An external API from either the C# Standard Library or a 3rd party library.
2929 */
3030class ExternalApi extends DotNet:: Callable {
31- ExternalApi ( ) { this .isUnboundDeclaration ( ) and this .fromLibrary ( ) }
31+ ExternalApi ( ) {
32+ this .isUnboundDeclaration ( ) and
33+ this .fromLibrary ( ) and
34+ this .( Modifiable ) .isEffectivelyPublic ( )
35+ }
3236
3337 /**
3438 * Gets the unbound type, name and parameter types of this API.
3539 */
40+ bindingset [ this ]
3641 private string getSignature ( ) {
3742 result =
3843 this .getDeclaringType ( ) .getUnboundDeclaration ( ) + "." + this .getName ( ) + "(" +
@@ -42,41 +47,33 @@ class ExternalApi extends DotNet::Callable {
4247 /**
4348 * Gets the namespace of this API.
4449 */
45- private string getNamespace ( ) { this .getDeclaringType ( ) .hasQualifiedName ( result , _) }
46-
47- /**
48- * Gets the assembly file name containing this API.
49- */
50- private string getAssembly ( ) { result = this .getFile ( ) .getBaseName ( ) }
50+ bindingset [ this ]
51+ string getNamespace ( ) { this .getDeclaringType ( ) .hasQualifiedName ( result , _) }
5152
5253 /**
53- * Gets the assembly file name and namespace of this API.
54+ * Gets the namespace and signature of this API.
5455 */
55- string getInfoPrefix ( ) { result = this .getAssembly ( ) + "#" + this .getNamespace ( ) }
56-
57- /**
58- * Gets the assembly file name, namespace and signature of this API.
59- */
60- string getInfo ( ) { result = this .getInfoPrefix ( ) + "#" + this .getSignature ( ) }
61-
62- /** Gets a call to this API callable. */
63- DispatchCall getACall ( ) {
64- this = result .getADynamicTarget ( ) .getUnboundDeclaration ( )
65- or
66- this = result .getAStaticTarget ( ) .getUnboundDeclaration ( )
67- }
56+ bindingset [ this ]
57+ string getApiName ( ) { result = this .getNamespace ( ) + "#" + this .getSignature ( ) }
6858
6959 /** Gets a node that is an input to a call to this API. */
7060 private ArgumentNode getAnInput ( ) {
71- result .getCall ( ) .( DataFlowDispatch:: NonDelegateDataFlowCall ) .getDispatchCall ( ) = this .getACall ( )
61+ result
62+ .getCall ( )
63+ .( DataFlowDispatch:: NonDelegateDataFlowCall )
64+ .getATarget ( _)
65+ .getUnboundDeclaration ( ) = this
7266 }
7367
7468 /** Gets a node that is an output from a call to this API. */
7569 private DataFlow:: Node getAnOutput ( ) {
76- exists ( DataFlowDispatch:: NonDelegateDataFlowCall call , DataFlowImplCommon:: ReturnKindExt ret |
77- result = ret .getAnOutNode ( call )
70+ exists (
71+ Call c , DataFlowDispatch:: NonDelegateDataFlowCall dc , DataFlowImplCommon:: ReturnKindExt ret
72+ |
73+ dc .getDispatchCall ( ) .getCall ( ) = c and
74+ c .getTarget ( ) .getUnboundDeclaration ( ) = this
7875 |
79- this . getACall ( ) = call . getDispatchCall ( )
76+ result = ret . getAnOutNode ( dc )
8077 )
8178 }
8279
@@ -125,30 +122,30 @@ signature predicate relevantApi(ExternalApi api);
125122 * for restricting the number or returned results based on a certain limit.
126123 */
127124module Results< relevantApi / 1 getRelevantUsages> {
128- private int getUsages ( string apiInfo ) {
125+ private int getUsages ( string apiName ) {
129126 result =
130- strictcount ( DispatchCall c , ExternalApi api |
131- c = api . getACall ( ) and
132- apiInfo = api .getInfo ( ) and
127+ strictcount ( Call c , ExternalApi api |
128+ c . getTarget ( ) . getUnboundDeclaration ( ) = api and
129+ apiName = api .getApiName ( ) and
133130 getRelevantUsages ( api )
134131 )
135132 }
136133
137- private int getOrder ( string apiInfo ) {
138- apiInfo =
139- rank [ result ] ( string info , int usages |
140- usages = getUsages ( info )
134+ private int getOrder ( string apiName ) {
135+ apiName =
136+ rank [ result ] ( string name , int usages |
137+ usages = getUsages ( name )
141138 |
142- info order by usages desc , info
139+ name order by usages desc , name
143140 )
144141 }
145142
146143 /**
147- * Holds if there exists an API with `apiInfo ` that is being used `usages` times
144+ * Holds if there exists an API with `apiName ` that is being used `usages` times
148145 * and if it is in the top results (guarded by resultLimit).
149146 */
150- predicate restrict ( string apiInfo , int usages ) {
151- usages = getUsages ( apiInfo ) and
152- getOrder ( apiInfo ) <= resultLimit ( )
147+ predicate restrict ( string apiName , int usages ) {
148+ usages = getUsages ( apiName ) and
149+ getOrder ( apiName ) <= resultLimit ( )
153150 }
154151}
0 commit comments