9
9
//import java // not needed I guess
10
10
import semmle.code.java.dataflow.FlowSummary // for SummarizedCallable
11
11
import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
12
- import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl // for NegativeSummarizedCallable
13
12
14
13
// ! improve QLDoc?
15
14
/**
@@ -20,57 +19,35 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl //
20
19
class MadModeledCallable extends SummarizedCallableBase {
21
20
// ! better name for this class?
22
21
MadModeledCallable ( ) {
23
- (
24
- this instanceof SummarizedCallable or
25
- this instanceof FlowSummaryImpl:: Public:: NegativeSummarizedCallable
26
- ) and
22
+ this instanceof SummarizedCallable and
27
23
exists ( DataFlowTargetApi dataFlowTargApi | this .asCallable ( ) = dataFlowTargApi )
28
24
}
29
25
}
30
26
31
27
// ! move to other file
32
- // ! separate this into pos and neg predicates instead of using `posOrNeg` flag?
33
28
/**
34
29
* Returns the number of APIs with MaD models
35
30
* for a given package and provenance.
36
31
*/
37
- float getNumMadModels ( string package , string provenance , string posOrNeg ) {
32
+ float getNumMadModels ( string package , string provenance ) {
38
33
exists ( MadModeledCallable mc |
39
34
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" ]
42
36
|
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"
73
49
)
50
+ )
74
51
)
75
52
}
76
53
@@ -86,8 +63,7 @@ float getNumApisWithoutMadModel(string package) {
86
63
result =
87
64
count ( DataFlowTargetApi d |
88
65
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 ( ) )
91
67
)
92
68
)
93
69
}
@@ -106,18 +82,14 @@ float getNumApisWithoutMadModel(string package) {
106
82
*/
107
83
108
84
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
111
87
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
118
91
notModeled = getNumApisWithoutMadModel ( package ) and
119
- all = generatedPos + manualPos + bothPos + generatedNeg + manualNeg + bothNeg + notModeled and
92
+ all = generatedPos + manualPos + bothPos + notModeled and
120
93
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