6
6
* @tags summary
7
7
*/
8
8
9
- //import java // not needed I guess
10
- import semmle.code.java.dataflow.FlowSummary // for SummarizedCallable
11
- import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
12
- import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl // for NegativeSummarizedCallable
9
+ import java
10
+ import semmle.code.java.dataflow.FlowSummary
11
+ import utils.modelgenerator.internal.CaptureModels
13
12
14
- // ! improve QLDoc?
15
13
/**
16
- * A callable for a given library that is modeled by MaD.
17
- * Specifically, this callable is the intersection of
18
- * DataFlowTargetApis and SummarizedCallables.
14
+ * A callable with a Summary MaD model. Specifically, this callable is
15
+ * the intersection of DataFlowTargetApis and SummarizedCallables.
19
16
*/
20
- class MadModeledCallable extends SummarizedCallableBase {
21
- // ! better name for this class?
17
+ private class MadModeledCallable extends SummarizedCallableBase {
22
18
MadModeledCallable ( ) {
23
19
this instanceof SummarizedCallable and
24
20
exists ( DataFlowTargetApi dataFlowTargApi | this .asCallable ( ) = dataFlowTargApi )
25
21
}
26
22
}
27
23
28
- // ! move to other file
29
- /**
30
- * Returns the number of APIs with MaD models
31
- * for a given package and provenance.
32
- */
33
- float getNumMadModels ( string package , string provenance ) {
24
+ /** Returns the number of APIs with Summary MaD models for a given package and provenance. */
25
+ private float getNumApisWithMadModels ( string package , string provenance ) {
34
26
exists ( MadModeledCallable mc |
35
27
package = mc .asCallable ( ) .getDeclaringType ( ) .getPackage ( ) .toString ( ) and
36
28
provenance in [ "generated" , "manual" , "both" ]
@@ -39,40 +31,21 @@ float getNumMadModels(string package, string provenance) {
39
31
count ( MadModeledCallable c |
40
32
package = c .asCallable ( ) .getDeclaringType ( ) .getPackage ( ) .toString ( ) and
41
33
(
42
- c .( SummarizedCallable ) .isAutoGenerated ( ) and // generated and NOT manual = "auto-only"
34
+ c .( SummarizedCallable ) .isAutoGenerated ( ) and // "auto-only"
43
35
provenance = "generated"
44
36
or
45
- c .( SummarizedCallable ) .isManuallyGenerated ( ) and // manual and NOT generated = "manual-only"
37
+ c .( SummarizedCallable ) .isManuallyGenerated ( ) and // "manual-only"
46
38
provenance = "manual"
47
39
or
48
- c .( SummarizedCallable ) .isBothAutoAndManuallyGenerated ( ) and // BOTH generated and manual = "both"
40
+ c .( SummarizedCallable ) .isBothAutoAndManuallyGenerated ( ) and // "both"
49
41
provenance = "both"
50
42
)
51
43
)
52
44
)
53
45
}
54
46
55
- // ! move to other file
56
- /**
57
- * Returns the number of APIs without SummarizedCallables
58
- * (MaD models) for a given package.
59
- */
60
- float getNumApisWithoutMadModel ( string package ) {
61
- exists ( DataFlowTargetApi dataFlowTargApi |
62
- package = dataFlowTargApi .getDeclaringType ( ) .getPackage ( ) .toString ( )
63
- |
64
- result =
65
- count ( DataFlowTargetApi d |
66
- package = d .getDeclaringType ( ) .getPackage ( ) .toString ( ) and
67
- not exists ( MadModeledCallable sc | d = sc .asCallable ( ) )
68
- )
69
- )
70
- }
71
-
72
- /**
73
- * Returns the total number of APIs for a given package.
74
- */
75
- float getNumApis ( string package ) {
47
+ /** Returns the total number of `DataFlowTargetApi`s for a given package. */
48
+ private float getNumApis ( string package ) {
76
49
exists ( DataFlowTargetApi dataFlowTargApi |
77
50
package = dataFlowTargApi .getDeclaringType ( ) .getPackage ( ) .toString ( )
78
51
|
84
57
string package , float generatedOnly , float both , float manualOnly , float non , float all ,
85
58
float generatedCoverage , float manualCoverage
86
59
where
87
- generatedOnly = getNumMadModels ( package , "generated" ) and
88
- manualOnly = getNumMadModels ( package , "manual" ) and
89
- both = getNumMadModels ( package , "both" ) and
90
- // non = getNumApisWithoutMadModel(package) and
91
- // all = generatedOnly + both + manualOnly + non and
60
+ generatedOnly = getNumApisWithMadModels ( package , "generated" ) and
61
+ manualOnly = getNumApisWithMadModels ( package , "manual" ) and
62
+ both = getNumApisWithMadModels ( package , "both" ) and
92
63
all = getNumApis ( package ) and
93
64
non = all - ( generatedOnly + both + manualOnly ) and
94
65
generatedCoverage = ( both / ( both + manualOnly ) ) and // Proportion of manual models covered by generated ones
95
66
manualCoverage = ( both / ( both + generatedOnly ) ) // Proportion of generated models covered by manual ones
96
67
select package , generatedOnly , both , manualOnly , non , all , generatedCoverage , manualCoverage
97
68
order by package
98
- // * "all" and "none" tests
99
- // from string package, float num
100
- // where num = getNumApis(package) // allY2 = DFTAs
101
- // // where num = getNumModeledApis(package) // allY1 = api that has either a positive or negative model
102
- // // where num = getNumApisWithoutMadModel(package) // noneY2 = DFTAs \ SCs
103
- // select package, num order by package
0 commit comments