Introduce query for capture JDK API usage

This commit is contained in:
Benjamin Muskalla
2021-07-28 13:09:18 +02:00
parent fad1622730
commit 9b6ae9029f
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import java
private string jarName(CompilationUnit cu) {
result = cu.getParentContainer().toString().regexpCapture(".*/(.*\\.jar)/?.*", 1)
}
predicate isJavaRuntime(Callable call) {
jarName(call.getCompilationUnit()) = "rt.jar" or
call.getCompilationUnit().getParentContainer().toString().substring(0, 14) = "/modules/java."
}
// TODO Is this heuristic too broad?
predicate isInterestingAPI(Callable call) {
call.getNumberOfParameters() > 0 and
not (
call.getReturnType() instanceof VoidType or
call.getReturnType() instanceof PrimitiveType or
call.getReturnType() instanceof BoxedType
)
}

View File

@@ -0,0 +1,15 @@
/**
* @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, call as API, count(Call c | c.getCallee() = call) as calls order by calls desc