Skip to content

Commit 42ddd66

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: add hasApiName predicate
1 parent f933fc7 commit 42ddd66

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

java/ql/test/ext/TopJdkApis/TopJdkApis.qll

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,18 @@ predicate topJdkApiName(string apiName) {
6161
]
6262
}
6363

64-
/**
65-
* Gets information about the given API in the form expected by the
66-
* MaD modeling framework.
67-
*/
68-
string getApiName(Callable api) {
69-
result =
70-
api.getDeclaringType().getPackage() + "." + api.getDeclaringType().getSourceDeclaration() + "#" +
71-
api.getName() + paramsString(api)
64+
/** Holds if `c` has the MaD-formatted name `apiName`. */
65+
predicate hasApiName(Callable c, string apiName) {
66+
apiName =
67+
c.getDeclaringType().getPackage() + "." + c.getDeclaringType().getSourceDeclaration() + "#" +
68+
c.getName() + paramsString(c)
7269
}
7370

74-
/** Holds if the given API has a `Callable`. */
75-
predicate hasCallable(string apiName) { exists(Callable callable | apiName = getApiName(callable)) }
76-
7771
/** A top JDK API. */
7872
class TopJdkApi extends SummarizedCallableBase {
7973
TopJdkApi() {
8074
exists(string apiName |
81-
apiName = getApiName(this.asCallable()) and
75+
hasApiName(this.asCallable(), apiName) and
8276
topJdkApiName(apiName)
8377
)
8478
}

java/ql/test/ext/TopJdkApis/TopJdkApisTest.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ from string apiName, string message
55
where
66
// top jdk api names for which there is no callable
77
topJdkApiName(apiName) and
8-
not hasCallable(apiName) and
8+
not exists(Callable c | hasApiName(c, apiName)) and
99
message = "no callable"
1010
or
1111
// top jdk api names for which there isn't a manual model
1212
exists(TopJdkApi topApi |
1313
not topApi.hasManualMadModel() and
14-
apiName = getApiName(topApi.asCallable()) and
14+
hasApiName(topApi.asCallable(), apiName) and
1515
message = "no manual model"
1616
)
1717
select apiName, message order by apiName

0 commit comments

Comments
 (0)