Java: reduce code duplication

This commit is contained in:
Jami Cogswell
2022-12-16 10:28:34 -05:00
parent 640b450c47
commit c0628035fa
2 changed files with 15 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ private import semmle.code.java.dataflow.FlowSummary
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
private import semmle.code.java.dataflow.ExternalFlow
/** Holds if the given API name is a top JDK API. */
predicate topJdkApiName(string apiName) {
apiName in [
// top 100 JDK APIs
@@ -60,21 +61,24 @@ predicate topJdkApiName(string apiName) {
]
}
predicate hasCallable(string apiName) {
exists(Callable c |
apiName =
c.getDeclaringType().getPackage() + "." + c.getDeclaringType().getSourceDeclaration() + "#" +
c.getName() + paramsString(c)
)
/**
* Gets information about the given API in the form expected by the
* MaD modeling framework.
*/
string getApiName(Callable api) {
result =
api.getDeclaringType().getPackage() + "." + api.getDeclaringType().getSourceDeclaration() + "#" +
api.getName() + paramsString(api)
}
/** Holds if the given API has a `Callable`. */
predicate hasCallable(string apiName) { exists(Callable callable | apiName = getApiName(callable)) }
/** A top JDK API. */
class TopJdkApi extends SummarizedCallableBase {
TopJdkApi() {
exists(string apiName |
apiName =
this.asCallable().getDeclaringType().getPackage() + "." +
this.asCallable().getDeclaringType().getSourceDeclaration() + "#" +
this.asCallable().getName() + paramsString(this.asCallable()) and
apiName = getApiName(this.asCallable()) and
topJdkApiName(apiName)
)
}

View File

@@ -12,10 +12,7 @@ where
// top jdk api names for which there isn't a manual model
exists(TopJdkApi topApi |
not topApi.hasManualMadModel() and
apiName =
topApi.asCallable().getDeclaringType().getPackage() + "." +
topApi.asCallable().getDeclaringType().getSourceDeclaration() + "#" +
topApi.asCallable().getName() + paramsString(topApi.asCallable()) and
apiName = getApiName(topApi.asCallable()) and
message = "no manual model"
)
select apiName, message order by apiName