@@ -22,6 +22,8 @@ class Type = J::Type;
2222
2323class Unit = J:: Unit ;
2424
25+ class Callable = J:: Callable ;
26+
2527private J:: Method superImpl ( J:: Method m ) {
2628 result = m .getAnOverride ( ) and
2729 not exists ( result .getAnOverride ( ) ) and
@@ -36,7 +38,7 @@ private predicate isInfrequentlyUsed(J::CompilationUnit cu) {
3638/**
3739 * Holds if it is relevant to generate models for `api`.
3840 */
39- private predicate isRelevantForModels ( J :: Callable api ) {
41+ private predicate isRelevantForModels ( Callable api ) {
4042 not isUninterestingForModels ( api ) and
4143 not isInfrequentlyUsed ( api .getCompilationUnit ( ) ) and
4244 // Disregard all APIs that have a manual model.
@@ -48,7 +50,7 @@ private predicate isRelevantForModels(J::Callable api) {
4850/**
4951 * Holds if it is relevant to generate models for `api` based on data flow analysis.
5052 */
51- predicate isRelevantForDataFlowModels ( J :: Callable api ) {
53+ predicate isRelevantForDataFlowModels ( Callable api ) {
5254 isRelevantForModels ( api ) and
5355 ( not api .getDeclaringType ( ) instanceof J:: Interface or exists ( api .getBody ( ) ) )
5456}
@@ -61,7 +63,7 @@ predicate isRelevantForTypeBasedFlowModels = isRelevantForModels/1;
6163 * In the Standard library and 3rd party libraries it the Callables that can be called
6264 * from outside the library itself.
6365 */
64- class TargetApiSpecific extends J :: Callable {
66+ class TargetApiSpecific extends Callable {
6567 TargetApiSpecific ( ) {
6668 this .isPublic ( ) and
6769 this .fromSource ( ) and
@@ -71,6 +73,15 @@ class TargetApiSpecific extends J::Callable {
7173 ) and
7274 isRelevantForModels ( this )
7375 }
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+ }
7485}
7586
7687private string isExtensible ( J:: RefType ref ) {
@@ -84,9 +95,7 @@ private string typeAsModel(J::RefType type) {
8495}
8596
8697private J:: RefType bestTypeForModel ( TargetApiSpecific api ) {
87- if exists ( superImpl ( api ) )
88- then superImpl ( api ) .fromSource ( ) and result = superImpl ( api ) .getDeclaringType ( )
89- else result = api .getDeclaringType ( )
98+ result = api .lift ( ) .getDeclaringType ( )
9099}
91100
92101/**
@@ -200,7 +209,7 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
200209/**
201210 * Gets the enclosing callable of `ret`.
202211 */
203- J :: Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
212+ Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
204213 result = DataFlowImplCommon:: getNodeEnclosingCallable ( ret ) .asCallable ( )
205214}
206215
0 commit comments