mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Introduce query for capture JDK API usage
This commit is contained in:
20
java/ql/src/Telemetry/APIUsage.qll
Normal file
20
java/ql/src/Telemetry/APIUsage.qll
Normal 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
|
||||
)
|
||||
}
|
||||
15
java/ql/src/Telemetry/JDKUsage.ql
Normal file
15
java/ql/src/Telemetry/JDKUsage.ql
Normal 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
|
||||
Reference in New Issue
Block a user