Skip to content

Commit 8595ae7

Browse files
author
Benjamin Muskalla
committed
Simplify api coverage detection
Fixes a bug that doesn't take super types into account when computing the usage of a specific API.
1 parent 3365634 commit 8595ae7

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

java/ql/src/Telemetry/APIUsage.qll

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,25 @@ import java
22
private import semmle.code.java.dataflow.FlowSteps
33
private import semmle.code.java.dataflow.ExternalFlow
44

5-
// TODO Is this heuristic too broad?
6-
predicate isInterestingAPI(Callable call) {
7-
call.getNumberOfParameters() > 0 and
8-
not (
9-
call.getReturnType() instanceof VoidType or
10-
call.getReturnType() instanceof PrimitiveType or
11-
call.getReturnType() instanceof BoxedType
12-
)
13-
}
14-
15-
// TODO [bm] Fails to detect Collection flow yet (e.g. Map#put)
165
string supportKind(Callable api) {
176
if api instanceof TaintPreservingCallable
187
then result = "taint-preserving"
198
else
20-
if
21-
summaryModel(api.getCompilationUnit().getPackage().toString(),
22-
api.getDeclaringType().toString(), _, api.getName(), _, _, _, _, _)
9+
if summaryModel(packageName(api), typeName(api), _, api.getName(), _, _, _, _, _)
2310
then result = "summary"
2411
else
25-
if
26-
sinkModel(api.getCompilationUnit().getPackage().toString(),
27-
api.getDeclaringType().toString(), _, api.getName(), _, _, _, _)
12+
if sinkModel(packageName(api), typeName(api), _, api.getName(), _, _, _, _)
2813
then result = "sink"
2914
else
30-
if
31-
sourceModel(api.getCompilationUnit().getPackage().toString(),
32-
api.getDeclaringType().toString(), _, api.getName(), _, _, _, _)
15+
if sourceModel(packageName(api), typeName(api), _, api.getName(), _, _, _, _)
3316
then result = "source"
3417
else result = "?"
3518
}
19+
20+
private string packageName(Callable api) {
21+
result = api.getCompilationUnit().getPackage().toString()
22+
}
23+
24+
private string typeName(Callable api) {
25+
result = api.getDeclaringType().getAnAncestor().getSourceDeclaration().toString()
26+
}

0 commit comments

Comments
 (0)