Skip to content

Commit d558f93

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: update DataFlowTargetApi for funcexpr and paramless constructor exclusions
1 parent e9e5f92 commit d558f93

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ class MadModeledCallable extends SummarizedCallableBase {
2424
this instanceof SummarizedCallable or
2525
this instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
2626
) and
27-
exists(DataFlowTargetApi dataFlowTargApi |
28-
this.asCallable() = dataFlowTargApi and
29-
not exists(FunctionalExpr funcExpr | dataFlowTargApi = funcExpr.asMethod()) // ! remove this if DataFlowTargetApi itself is adjusted to exclude FunctionalExpr (see static-team slack thread)
30-
)
27+
exists(DataFlowTargetApi dataFlowTargApi | this.asCallable() = dataFlowTargApi)
3128
}
3229
}
3330

@@ -84,13 +81,11 @@ float getNumMadModels(string package, string provenance, string posOrNeg) {
8481
*/
8582
float getNumApisWithoutMadModel(string package) {
8683
exists(DataFlowTargetApi dataFlowTargApi |
87-
package = dataFlowTargApi.getDeclaringType().getPackage().toString() and
88-
not exists(FunctionalExpr fe | dataFlowTargApi = fe.asMethod()) // remove lambdas // ! remove this if DataFlowTargetApi itself is adjusted to exclude FunctionalExpr (see static-team slack thread)
84+
package = dataFlowTargApi.getDeclaringType().getPackage().toString()
8985
|
9086
result =
9187
count(DataFlowTargetApi d |
9288
package = d.getDeclaringType().getPackage().toString() and
93-
not exists(FunctionalExpr funcExpr | d = funcExpr.asMethod()) and // remove lambdas // ! remove this if DataFlowTargetApi itself is adjusted to exclude FunctionalExpr (see static-team slack thread)
9489
not exists(SummarizedCallable sc | d = sc.asCallable()) and
9590
not exists(FlowSummaryImpl::Public::NegativeSummarizedCallable nc | d = nc.asCallable())
9691
)

java/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,21 @@ private predicate isJdkInternal(J::CompilationUnit cu) {
5252
cu.getPackage().getName() = ""
5353
}
5454

55+
/** Holds if the given API is a constructor without parameters. */
56+
private predicate isParameterlessConstructor(J::Callable api) {
57+
api instanceof J::Constructor and api.getNumberOfParameters() = 0
58+
} // ! merge with PR #11624
59+
5560
/**
5661
* Holds if it is relevant to generate models for `api`.
5762
*/
5863
private predicate isRelevantForModels(J::Callable api) {
5964
not isInTestFile(api.getCompilationUnit().getFile()) and
6065
not isJdkInternal(api.getCompilationUnit()) and
6166
not api instanceof J::MainMethod and
62-
not api instanceof J::StaticInitializer
67+
not api instanceof J::StaticInitializer and
68+
not exists(J::FunctionalExpr funcExpr | api = funcExpr.asMethod()) and // ! merge with PR #11623
69+
not isParameterlessConstructor(api) // ! merge with PR #11624
6370
}
6471

6572
/**

0 commit comments

Comments
 (0)