mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Fold JDK API query into external API query
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user