66 * @tags summary
77 */
88
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
1312
14- // ! improve QLDoc?
1513/**
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.
1916 */
20- class MadModeledCallable extends SummarizedCallableBase {
21- // ! better name for this class?
17+ private class MadModeledCallable extends SummarizedCallableBase {
2218 MadModeledCallable ( ) {
2319 this instanceof SummarizedCallable and
2420 exists ( DataFlowTargetApi dataFlowTargApi | this .asCallable ( ) = dataFlowTargApi )
2521 }
2622}
2723
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 ) {
3426 exists ( MadModeledCallable mc |
3527 package = mc .asCallable ( ) .getDeclaringType ( ) .getPackage ( ) .toString ( ) and
3628 provenance in [ "generated" , "manual" , "both" ]
@@ -39,40 +31,21 @@ float getNumMadModels(string package, string provenance) {
3931 count ( MadModeledCallable c |
4032 package = c .asCallable ( ) .getDeclaringType ( ) .getPackage ( ) .toString ( ) and
4133 (
42- c .( SummarizedCallable ) .isAutoGenerated ( ) and // generated and NOT manual = "auto-only"
34+ c .( SummarizedCallable ) .isAutoGenerated ( ) and // "auto-only"
4335 provenance = "generated"
4436 or
45- c .( SummarizedCallable ) .isManuallyGenerated ( ) and // manual and NOT generated = "manual-only"
37+ c .( SummarizedCallable ) .isManuallyGenerated ( ) and // "manual-only"
4638 provenance = "manual"
4739 or
48- c .( SummarizedCallable ) .isBothAutoAndManuallyGenerated ( ) and // BOTH generated and manual = "both"
40+ c .( SummarizedCallable ) .isBothAutoAndManuallyGenerated ( ) and // "both"
4941 provenance = "both"
5042 )
5143 )
5244 )
5345}
5446
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 ) {
7649 exists ( DataFlowTargetApi dataFlowTargApi |
7750 package = dataFlowTargApi .getDeclaringType ( ) .getPackage ( ) .toString ( )
7851 |
8457 string package , float generatedOnly , float both , float manualOnly , float non , float all ,
8558 float generatedCoverage , float manualCoverage
8659where
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
9263 all = getNumApis ( package ) and
9364 non = all - ( generatedOnly + both + manualOnly ) and
9465 generatedCoverage = ( both / ( both + manualOnly ) ) and // Proportion of manual models covered by generated ones
9566 manualCoverage = ( both / ( both + generatedOnly ) ) // Proportion of generated models covered by manual ones
9667select package , generatedOnly , both , manualOnly , non , all , generatedCoverage , manualCoverage
9768 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