55private import java as J
66private import semmle.code.java.dataflow.internal.DataFlowPrivate
77private import semmle.code.java.dataflow.internal.ContainerFlow as ContainerFlow
8+ private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
89private import semmle.code.java.dataflow.internal.ModelExclusions
910private import semmle.code.java.dataflow.DataFlow as Df
1011private import semmle.code.java.dataflow.SSA as Ssa
@@ -21,6 +22,8 @@ class Type = J::Type;
2122
2223class Unit = J:: Unit ;
2324
25+ class Callable = J:: Callable ;
26+
2427private J:: Method superImpl ( J:: Method m ) {
2528 result = m .getAnOverride ( ) and
2629 not exists ( result .getAnOverride ( ) ) and
@@ -35,15 +38,19 @@ private predicate isInfrequentlyUsed(J::CompilationUnit cu) {
3538/**
3639 * Holds if it is relevant to generate models for `api`.
3740 */
38- private predicate isRelevantForModels ( J :: Callable api ) {
41+ private predicate isRelevantForModels ( Callable api ) {
3942 not isUninterestingForModels ( api ) and
40- not isInfrequentlyUsed ( api .getCompilationUnit ( ) )
43+ not isInfrequentlyUsed ( api .getCompilationUnit ( ) ) and
44+ // Disregard all APIs that have a manual model.
45+ not api = any ( FlowSummaryImpl:: Public:: SummarizedCallable sc | sc .applyManualModel ( ) ) .asCallable ( ) and
46+ not api =
47+ any ( FlowSummaryImpl:: Public:: NeutralSummaryCallable sc | sc .hasManualModel ( ) ) .asCallable ( )
4148}
4249
4350/**
4451 * Holds if it is relevant to generate models for `api` based on data flow analysis.
4552 */
46- predicate isRelevantForDataFlowModels ( J :: Callable api ) {
53+ predicate isRelevantForDataFlowModels ( Callable api ) {
4754 isRelevantForModels ( api ) and
4855 ( not api .getDeclaringType ( ) instanceof J:: Interface or exists ( api .getBody ( ) ) )
4956}
@@ -56,7 +63,7 @@ predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
5663 * In the Standard library and 3rd party libraries it the Callables that can be called
5764 * from outside the library itself.
5865 */
59- class TargetApiSpecific extends J :: Callable {
66+ class TargetApiSpecific extends Callable {
6067 TargetApiSpecific ( ) {
6168 this .isPublic ( ) and
6269 this .fromSource ( ) and
@@ -66,6 +73,15 @@ class TargetApiSpecific extends J::Callable {
6673 ) and
6774 isRelevantForModels ( this )
6875 }
76+
77+ /**
78+ * Gets the callable that a model will be lifted to, if any.
79+ */
80+ Callable lift ( ) {
81+ exists ( Method m | m = superImpl ( this ) and m .fromSource ( ) | result = m )
82+ or
83+ not exists ( superImpl ( this ) ) and result = this
84+ }
6985}
7086
7187private string isExtensible ( J:: RefType ref ) {
@@ -79,9 +95,7 @@ private string typeAsModel(J::RefType type) {
7995}
8096
8197private J:: RefType bestTypeForModel ( TargetApiSpecific api ) {
82- if exists ( superImpl ( api ) )
83- then superImpl ( api ) .fromSource ( ) and result = superImpl ( api ) .getDeclaringType ( )
84- else result = api .getDeclaringType ( )
98+ result = api .lift ( ) .getDeclaringType ( )
8599}
86100
87101/**
@@ -195,7 +209,7 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
195209/**
196210 * Gets the enclosing callable of `ret`.
197211 */
198- J :: Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
212+ Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
199213 result = DataFlowImplCommon:: getNodeEnclosingCallable ( ret ) .asCallable ( )
200214}
201215
0 commit comments