@@ -32,27 +32,64 @@ module ReportStats<StatsSig Stats> {
3232 }
3333}
3434
35- private predicate isNoSetterPropertyCallInConstructor ( PropertyCall c ) {
36- exists ( Property p |
37- p = c .getProperty ( ) and
38- not exists ( Setter a | a = p .getAnAccessor ( ) ) and
39- c .getEnclosingCallable ( ) .( Constructor ) .getDeclaringType ( ) .getASubType * ( ) = p .getDeclaringType ( )
40- )
41- }
42-
4335module CallTargetStats implements StatsSig {
4436 int getNumberOfOk ( ) { result = count ( Call c | exists ( c .getTarget ( ) ) ) }
4537
46- int getNumberOfNotOk ( ) {
47- result =
48- count ( Call c |
49- not exists ( c .getTarget ( ) ) and
50- not c instanceof DelegateCall and
51- not c instanceof DynamicExpr and
52- not isNoSetterPropertyCallInConstructor ( c )
38+ private predicate isNoSetterPropertyCallInConstructor ( PropertyCall c ) {
39+ exists ( Property p , Constructor ctor |
40+ p = c .getProperty ( ) and
41+ not exists ( Setter a | a = p .getAnAccessor ( ) ) and
42+ c .getEnclosingCallable ( ) = ctor and
43+ (
44+ c .hasThisQualifier ( )
45+ or
46+ ctor instanceof StaticConstructor and p .getDeclaringType ( ) = ctor .getDeclaringType ( )
5347 )
48+ )
49+ }
50+
51+ private predicate isNoSetterPropertyInitialization ( PropertyCall c ) {
52+ exists ( Property p , AssignExpr assign |
53+ p = c .getProperty ( ) and
54+ not exists ( Setter a | a = p .getAnAccessor ( ) ) and
55+ assign = c .getParent ( ) and
56+ assign .getLValue ( ) = c and
57+ assign .getParent ( ) instanceof Property
58+ )
59+ }
60+
61+ private predicate isAnonymousObjectMemberDeclaration ( PropertyCall c ) {
62+ exists ( Property p , AssignExpr assign |
63+ p = c .getProperty ( ) and
64+ assign = c .getParent ( ) and
65+ assign .getLValue ( ) = c and
66+ assign .getParent ( ) instanceof ObjectInitializer and
67+ assign .getParent ( ) .getParent ( ) instanceof AnonymousObjectCreation
68+ )
5469 }
5570
71+ private predicate isInitializedWithCollectionInitializer ( PropertyCall c ) {
72+ exists ( Property p , AssignExpr assign |
73+ p = c .getProperty ( ) and
74+ assign = c .getParent ( ) and
75+ assign .getLValue ( ) = c and
76+ assign .getRValue ( ) instanceof CollectionInitializer
77+ )
78+ }
79+
80+ additional predicate isNotOkCall ( Call c ) {
81+ not exists ( c .getTarget ( ) ) and
82+ not c instanceof DelegateCall and
83+ not c instanceof DynamicExpr and
84+ not isNoSetterPropertyCallInConstructor ( c ) and
85+ not isNoSetterPropertyInitialization ( c ) and
86+ not isAnonymousObjectMemberDeclaration ( c ) and
87+ not isInitializedWithCollectionInitializer ( c ) and
88+ not c .getParent + ( ) instanceof NameOfExpr
89+ }
90+
91+ int getNumberOfNotOk ( ) { result = count ( Call c | isNotOkCall ( c ) ) }
92+
5693 string getOkText ( ) { result = "calls with call target" }
5794
5895 string getNotOkText ( ) { result = "calls with missing call target" }
0 commit comments