Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b6ae90

Browse files
author
Benjamin Muskalla
committed
Introduce query for capture JDK API usage
1 parent fad1622 commit 9b6ae90

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

java/ql/src/Telemetry/APIUsage.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java
2+
3+
private string jarName(CompilationUnit cu) {
4+
result = cu.getParentContainer().toString().regexpCapture(".*/(.*\\.jar)/?.*", 1)
5+
}
6+
7+
predicate isJavaRuntime(Callable call) {
8+
jarName(call.getCompilationUnit()) = "rt.jar" or
9+
call.getCompilationUnit().getParentContainer().toString().substring(0, 14) = "/modules/java."
10+
}
11+
12+
// TODO Is this heuristic too broad?
13+
predicate isInterestingAPI(Callable call) {
14+
call.getNumberOfParameters() > 0 and
15+
not (
16+
call.getReturnType() instanceof VoidType or
17+
call.getReturnType() instanceof PrimitiveType or
18+
call.getReturnType() instanceof BoxedType
19+
)
20+
}

java/ql/src/Telemetry/JDKUsage.ql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name JDK API Usage
3+
* @description A list of JDK APIs used in the source code.
4+
* @id java/telemetry/jdk-apis
5+
*/
6+
7+
import java
8+
import APIUsage
9+
10+
from Callable call, CompilationUnit cu
11+
where
12+
cu = call.getCompilationUnit() and
13+
isJavaRuntime(call) and
14+
isInterestingAPI(call)
15+
select cu, call as API, count(Call c | c.getCallee() = call) as calls order by calls desc

0 commit comments

Comments
 (0)