Skip to content

Commit 9e0027c

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: remove negative models
1 parent d558f93 commit 9e0027c

File tree

1 file changed

+25
-53
lines changed

1 file changed

+25
-53
lines changed

java/ql/src/Metrics/Summaries/GeneratedVsManualCoverage.ql

Lines changed: 25 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//import java // not needed I guess
1010
import semmle.code.java.dataflow.FlowSummary // for SummarizedCallable
1111
import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
12-
import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl // for NegativeSummarizedCallable
1312

1413
// ! improve QLDoc?
1514
/**
@@ -20,57 +19,35 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl //
2019
class MadModeledCallable extends SummarizedCallableBase {
2120
// ! better name for this class?
2221
MadModeledCallable() {
23-
(
24-
this instanceof SummarizedCallable or
25-
this instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
26-
) and
22+
this instanceof SummarizedCallable and
2723
exists(DataFlowTargetApi dataFlowTargApi | this.asCallable() = dataFlowTargApi)
2824
}
2925
}
3026

3127
// ! move to other file
32-
// ! separate this into pos and neg predicates instead of using `posOrNeg` flag?
3328
/**
3429
* Returns the number of APIs with MaD models
3530
* for a given package and provenance.
3631
*/
37-
float getNumMadModels(string package, string provenance, string posOrNeg) {
32+
float getNumMadModels(string package, string provenance) {
3833
exists(MadModeledCallable mc |
3934
package = mc.asCallable().getDeclaringType().getPackage().toString() and
40-
provenance in ["generated", "manual", "both"] and
41-
posOrNeg in ["positive", "negative"]
35+
provenance in ["generated", "manual", "both"]
4236
|
43-
if posOrNeg = "positive"
44-
then
45-
result =
46-
count(MadModeledCallable c |
47-
package = c.asCallable().getDeclaringType().getPackage().toString() and
48-
(
49-
c.(SummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
50-
provenance = "generated"
51-
or
52-
c.(SummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
53-
provenance = "manual"
54-
or
55-
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
56-
provenance = "both"
57-
)
58-
)
59-
else
60-
result =
61-
count(MadModeledCallable c |
62-
package = c.asCallable().getDeclaringType().getPackage().toString() and
63-
(
64-
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
65-
provenance = "generated"
66-
or
67-
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
68-
provenance = "manual"
69-
or
70-
c.(FlowSummaryImpl::Public::NegativeSummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
71-
provenance = "both"
72-
)
37+
result =
38+
count(MadModeledCallable c |
39+
package = c.asCallable().getDeclaringType().getPackage().toString() and
40+
(
41+
c.(SummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
42+
provenance = "generated"
43+
or
44+
c.(SummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
45+
provenance = "manual"
46+
or
47+
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
48+
provenance = "both"
7349
)
50+
)
7451
)
7552
}
7653

@@ -86,8 +63,7 @@ float getNumApisWithoutMadModel(string package) {
8663
result =
8764
count(DataFlowTargetApi d |
8865
package = d.getDeclaringType().getPackage().toString() and
89-
not exists(SummarizedCallable sc | d = sc.asCallable()) and
90-
not exists(FlowSummaryImpl::Public::NegativeSummarizedCallable nc | d = nc.asCallable())
66+
not exists(SummarizedCallable sc | d = sc.asCallable())
9167
)
9268
)
9369
}
@@ -106,18 +82,14 @@ float getNumApisWithoutMadModel(string package) {
10682
*/
10783

10884
from
109-
string package, float generatedPos, float manualPos, float bothPos, float generatedNeg,
110-
float manualNeg, float bothNeg, float notModeled, float all, float metric1, float metric2
85+
string package, float generatedPos, float manualPos, float bothPos, float notModeled, float all,
86+
float metric1, float metric2
11187
where
112-
generatedPos = getNumMadModels(package, "generated", "positive") and
113-
manualPos = getNumMadModels(package, "manual", "positive") and
114-
bothPos = getNumMadModels(package, "both", "positive") and
115-
generatedNeg = getNumMadModels(package, "generated", "negative") and
116-
manualNeg = getNumMadModels(package, "manual", "negative") and
117-
bothNeg = getNumMadModels(package, "both", "negative") and
88+
generatedPos = getNumMadModels(package, "generated") and
89+
manualPos = getNumMadModels(package, "manual") and
90+
bothPos = getNumMadModels(package, "both") and
11891
notModeled = getNumApisWithoutMadModel(package) and
119-
all = generatedPos + manualPos + bothPos + generatedNeg + manualNeg + bothNeg + notModeled and
92+
all = generatedPos + manualPos + bothPos + notModeled and
12093
metric1 = (bothPos / (bothPos + manualPos)) and // ! I believe this metric was intended to be only on the positive ones?
121-
metric2 = (generatedPos + generatedNeg + bothPos + bothNeg + manualPos + manualNeg) / all
122-
select package, generatedPos, manualPos, bothPos, generatedNeg, manualNeg, bothNeg, notModeled, all,
123-
metric1, metric2 order by package
94+
metric2 = (generatedPos + bothPos + manualPos) / all
95+
select package, generatedPos, manualPos, bothPos, notModeled, all, metric1, metric2 order by package

0 commit comments

Comments
 (0)