Java: clean up comments and predicates

This commit is contained in:
Jami Cogswell
2022-12-08 23:09:09 -05:00
parent ca00e0ab9e
commit a32ed21480

View File

@@ -6,31 +6,23 @@
* @tags summary
*/
//import java // not needed I guess
import semmle.code.java.dataflow.FlowSummary // for SummarizedCallable
import utils.modelgenerator.internal.CaptureModels // for DataFlowTargetApi
import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl // for NegativeSummarizedCallable
import java
import semmle.code.java.dataflow.FlowSummary
import utils.modelgenerator.internal.CaptureModels
// ! improve QLDoc?
/**
* A callable for a given library that is modeled by MaD.
* Specifically, this callable is the intersection of
* DataFlowTargetApis and SummarizedCallables.
* A callable with a Summary MaD model. Specifically, this callable is
* the intersection of DataFlowTargetApis and SummarizedCallables.
*/
class MadModeledCallable extends SummarizedCallableBase {
// ! better name for this class?
private class MadModeledCallable extends SummarizedCallableBase {
MadModeledCallable() {
this instanceof SummarizedCallable and
exists(DataFlowTargetApi dataFlowTargApi | this.asCallable() = dataFlowTargApi)
}
}
// ! move to other file
/**
* Returns the number of APIs with MaD models
* for a given package and provenance.
*/
float getNumMadModels(string package, string provenance) {
/** Returns the number of APIs with Summary MaD models for a given package and provenance. */
private float getNumApisWithMadModels(string package, string provenance) {
exists(MadModeledCallable mc |
package = mc.asCallable().getDeclaringType().getPackage().toString() and
provenance in ["generated", "manual", "both"]
@@ -39,40 +31,21 @@ float getNumMadModels(string package, string provenance) {
count(MadModeledCallable c |
package = c.asCallable().getDeclaringType().getPackage().toString() and
(
c.(SummarizedCallable).isAutoGenerated() and // generated and NOT manual = "auto-only"
c.(SummarizedCallable).isAutoGenerated() and // "auto-only"
provenance = "generated"
or
c.(SummarizedCallable).isManuallyGenerated() and // manual and NOT generated = "manual-only"
c.(SummarizedCallable).isManuallyGenerated() and // "manual-only"
provenance = "manual"
or
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // BOTH generated and manual = "both"
c.(SummarizedCallable).isBothAutoAndManuallyGenerated() and // "both"
provenance = "both"
)
)
)
}
// ! move to other file
/**
* Returns the number of APIs without SummarizedCallables
* (MaD models) for a given package.
*/
float getNumApisWithoutMadModel(string package) {
exists(DataFlowTargetApi dataFlowTargApi |
package = dataFlowTargApi.getDeclaringType().getPackage().toString()
|
result =
count(DataFlowTargetApi d |
package = d.getDeclaringType().getPackage().toString() and
not exists(MadModeledCallable sc | d = sc.asCallable())
)
)
}
/**
* Returns the total number of APIs for a given package.
*/
float getNumApis(string package) {
/** Returns the total number of `DataFlowTargetApi`s for a given package. */
private float getNumApis(string package) {
exists(DataFlowTargetApi dataFlowTargApi |
package = dataFlowTargApi.getDeclaringType().getPackage().toString()
|
@@ -84,20 +57,12 @@ from
string package, float generatedOnly, float both, float manualOnly, float non, float all,
float generatedCoverage, float manualCoverage
where
generatedOnly = getNumMadModels(package, "generated") and
manualOnly = getNumMadModels(package, "manual") and
both = getNumMadModels(package, "both") and
// non = getNumApisWithoutMadModel(package) and
// all = generatedOnly + both + manualOnly + non and
generatedOnly = getNumApisWithMadModels(package, "generated") and
manualOnly = getNumApisWithMadModels(package, "manual") and
both = getNumApisWithMadModels(package, "both") and
all = getNumApis(package) and
non = all - (generatedOnly + both + manualOnly) and
generatedCoverage = (both / (both + manualOnly)) and // Proportion of manual models covered by generated ones
manualCoverage = (both / (both + generatedOnly)) // Proportion of generated models covered by manual ones
select package, generatedOnly, both, manualOnly, non, all, generatedCoverage, manualCoverage
order by package
// * "all" and "none" tests
// from string package, float num
// where num = getNumApis(package) // allY2 = DFTAs
// // where num = getNumModeledApis(package) // allY1 = api that has either a positive or negative model
// // where num = getNumApisWithoutMadModel(package) // noneY2 = DFTAs \ SCs
// select package, num order by package