44
55private import python
66private import semmle.python.ApiGraphs
7+ private import semmle.python.filters.Tests
78
8- /**
9- * A file that probably contains tests.
10- */
11- class TestFile extends File {
12- TestFile ( ) {
13- this .getRelativePath ( ) .regexpMatch ( ".*(test|spec|examples).+" ) and
14- not this .getAbsolutePath ( ) .matches ( "%/ql/test/%" ) // allows our test cases to work
9+ class RelevantScope extends Scope {
10+ RelevantScope ( ) {
11+ this .isPublic ( ) and
12+ not this instanceof TestScope and
13+ exists ( this .getLocation ( ) .getFile ( ) .getRelativePath ( ) )
1514 }
1615}
1716
18- /**
19- * A file that is relevant in the context of library modeling.
20- *
21- * In practice, this means a file that is not part of test code.
22- */
23- class RelevantFile extends File {
24- RelevantFile ( ) { not this instanceof TestFile and not this .inStdlib ( ) }
25- }
26-
2717/**
2818 * Gets the dotted path of a scope.
2919 */
30- string computeScopePath ( Scope scope ) {
20+ string computeScopePath ( RelevantScope scope ) {
3121 // base case
3222 if scope instanceof Module
3323 then
@@ -39,9 +29,8 @@ string computeScopePath(Scope scope) {
3929 else
4030 //recursive cases
4131 if scope instanceof Class or scope instanceof Function
42- then
43- result = computeScopePath ( scope .getEnclosingScope ( ) ) + "." + scope .getName ( )
44- else result = "unknown: " + scope .toString ( )
32+ then result = computeScopePath ( scope .getEnclosingScope ( ) ) + "." + scope .getName ( )
33+ else result = "unknown: " + scope .toString ( )
4534}
4635
4736signature predicate modelSig ( string type , string path ) ;
@@ -55,7 +44,7 @@ module FindModel<modelSig/2 model> {
5544 /**
5645 * Holds if the given scope has a model as identified by the provided predicate `model`.
5746 */
58- predicate hasModel ( Scope scope ) {
47+ predicate hasModel ( RelevantScope scope ) {
5948 exists ( string type , string path , string searchPath | model ( type , path ) |
6049 searchPath = possibleMemberPathPrefix ( path , scope .getName ( ) ) and
6150 pathToScope ( scope , type , searchPath )
@@ -76,8 +65,7 @@ module FindModel<modelSig/2 model> {
7665 * Holds if `(type,path)` identifies `scope`.
7766 */
7867 bindingset [ type, path]
79- predicate pathToScope ( Scope scope , string type , string path ) {
80- scope instanceof Endpoint
68+ predicate pathToScope ( RelevantScope scope , string type , string path ) {
8169 computeScopePath ( scope ) =
8270 type .replaceAll ( "!" , "" ) + "." +
8371 path .replaceAll ( "Member[" , "" ) .replaceAll ( "]" , "" ) .replaceAll ( "Instance." , "" ) +
0 commit comments