Skip to content

Commit c062803

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: reduce code duplication
1 parent 640b450 commit c062803

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import semmle.code.java.dataflow.FlowSummary
55
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
66
private import semmle.code.java.dataflow.ExternalFlow
77

8+
/** Holds if the given API name is a top JDK API. */
89
predicate topJdkApiName(string apiName) {
910
apiName in [
1011
// top 100 JDK APIs
@@ -60,21 +61,24 @@ predicate topJdkApiName(string apiName) {
6061
]
6162
}
6263

63-
predicate hasCallable(string apiName) {
64-
exists(Callable c |
65-
apiName =
66-
c.getDeclaringType().getPackage() + "." + c.getDeclaringType().getSourceDeclaration() + "#" +
67-
c.getName() + paramsString(c)
68-
)
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)
6972
}
7073

74+
/** Holds if the given API has a `Callable`. */
75+
predicate hasCallable(string apiName) { exists(Callable callable | apiName = getApiName(callable)) }
76+
77+
/** A top JDK API. */
7178
class TopJdkApi extends SummarizedCallableBase {
7279
TopJdkApi() {
7380
exists(string apiName |
74-
apiName =
75-
this.asCallable().getDeclaringType().getPackage() + "." +
76-
this.asCallable().getDeclaringType().getSourceDeclaration() + "#" +
77-
this.asCallable().getName() + paramsString(this.asCallable()) and
81+
apiName = getApiName(this.asCallable()) and
7882
topJdkApiName(apiName)
7983
)
8084
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ where
1212
// top jdk api names for which there isn't a manual model
1313
exists(TopJdkApi topApi |
1414
not topApi.hasManualMadModel() and
15-
apiName =
16-
topApi.asCallable().getDeclaringType().getPackage() + "." +
17-
topApi.asCallable().getDeclaringType().getSourceDeclaration() + "#" +
18-
topApi.asCallable().getName() + paramsString(topApi.asCallable()) and
15+
apiName = getApiName(topApi.asCallable()) and
1916
message = "no manual model"
2017
)
2118
select apiName, message order by apiName

0 commit comments

Comments
 (0)