Fold JDK API query into external API query

This commit is contained in:
Benjamin Muskalla
2021-08-02 11:52:01 +02:00
parent 0c04c9a2c2
commit 2064915d3b
4 changed files with 2 additions and 33 deletions

View File

@@ -2,11 +2,6 @@ import java
private import semmle.code.java.dataflow.FlowSteps
private import semmle.code.java.dataflow.ExternalFlow
predicate isJavaRuntime(Callable call) {
call.getCompilationUnit().getParentContainer*().getStem() = "rt" and
call.getCompilationUnit().getParentContainer().toString().substring(0, 14) = "/modules/java."
}
// TODO Is this heuristic too broad?
predicate isInterestingAPI(Callable call) {
call.getNumberOfParameters() > 0 and

View File

@@ -4,9 +4,7 @@ private import experimental.semmle.code.java.Logging
class ExternalAPI extends Callable {
ExternalAPI() {
not this.fromSource() and
not this.getDeclaringType().getPackage().getName().matches("java.%") and
not isJavaRuntime(this)
not this.fromSource()
}
string simpleName() {
@@ -14,13 +12,6 @@ class ExternalAPI extends Callable {
}
}
// TODO [bm]: Shall we move this into LoggingCall or a LoggingSetup predicate?
predicate loggingRelated(Call call) {
call instanceof LoggingCall or
call.getCallee().getName() = "getLogger" or // getLogger is not a LoggingCall
call.getCallee().getName() = "isDebugEnabled" // org.slf4j.Logger#isDebugEnabled is not a LoggingCall
}
class TestLibrary extends RefType {
TestLibrary() {
getPackage()

View File

@@ -15,7 +15,6 @@ where
select api.simpleName() as API,
count(Call c |
c.getCallee() = api and
not c.getFile() instanceof GeneratedFile and
not loggingRelated(c)
not c.getFile() instanceof GeneratedFile
) as Usages, supportKind(api) as Kind, api.getReturnType() as ReturnType,
api.getDeclaringType().getPackage() as Package order by Usages desc

View File

@@ -1,16 +0,0 @@
/**
* @name JDK API Usage
* @description A list of JDK APIs used in the source code.
* @id java/telemetry/jdk-apis
*/
import java
import APIUsage
from Callable call, CompilationUnit cu
where
cu = call.getCompilationUnit() and
isJavaRuntime(call) and
isInterestingAPI(call)
select cu as Class, call as API, supportKind(call) as Kind,
count(Call c | c.getCallee() = call) as Usages order by Usages desc