Skip to content

Commit 4941d9b

Browse files
committed
Java: Add query for CSV framework coverage.
1 parent ed250d5 commit 4941d9b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Framework coverage
3+
* @description The number of API endpoints covered by CSV models sorted by
4+
* package and source-, sink-, and summary-kind.
5+
* @kind metric
6+
* @id java/meta/framework-coverage
7+
*/
8+
9+
import java
10+
import semmle.code.java.dataflow.ExternalFlow
11+
12+
from string package, string kind, string part, int n
13+
where modelCoverage(package, kind, part, n)
14+
select package, kind, part, n

java/ql/src/semmle/code/java/dataflow/ExternalFlow.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,29 @@ private predicate summaryModel(
204204
)
205205
}
206206

207+
/**
208+
* Holds if CSV framework coverage of `package` is `n` api endpoints of the
209+
* kind `(kind, part)`.
210+
*/
211+
predicate modelCoverage(string package, string kind, string part, int n) {
212+
part = "source" and
213+
n =
214+
strictcount(string type, boolean subtypes, string name, string signature, string ext,
215+
string output | sourceModel(package, type, subtypes, name, signature, ext, output, kind))
216+
or
217+
part = "sink" and
218+
n =
219+
strictcount(string type, boolean subtypes, string name, string signature, string ext,
220+
string input | sinkModel(package, type, subtypes, name, signature, ext, input, kind))
221+
or
222+
part = "summary" and
223+
n =
224+
strictcount(string type, boolean subtypes, string name, string signature, string ext,
225+
string input, string output |
226+
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind)
227+
)
228+
}
229+
207230
/** Provides a query predicate to check the CSV data for validation errors. */
208231
module CsvValidation {
209232
/** Holds if some row in a CSV-based flow model appears to contain typos. */

0 commit comments

Comments
 (0)