@@ -9,11 +9,27 @@ private import ControlFlow::BasicBlocks
99
1010/** An assertion method. */
1111abstract class AssertMethod extends Method {
12- /** Gets the index of the parameter being asserted. */
13- abstract int getAssertionIndex ( ) ;
12+ /**
13+ * DEPRECATED: renamed to `getAnAssertionIndex`.
14+ *
15+ * Gets the index of a parameter being asserted.
16+ */
17+ deprecated int getAssertionIndex ( ) { result = getAnAssertionIndex ( ) }
18+
19+ /** Gets the index of a parameter being asserted. */
20+ abstract int getAnAssertionIndex ( ) ;
21+
22+ /**
23+ * DEPRECATED: renamed to `getAnAssertedParameter`.
24+ *
25+ * Gets a parameter being asserted.
26+ */
27+ deprecated Parameter getAssertedParameter ( ) { result = getAnAssertedParameter ( ) }
1428
15- /** Gets the parameter being asserted. */
16- final Parameter getAssertedParameter ( ) { result = this .getParameter ( this .getAssertionIndex ( ) ) }
29+ /** Gets a parameter being asserted. */
30+ final Parameter getAnAssertedParameter ( ) {
31+ result = this .getParameter ( this .getAnAssertionIndex ( ) )
32+ }
1733
1834 /** Gets the exception being thrown if the assertion fails, if any. */
1935 abstract Class getExceptionClass ( ) ;
@@ -40,8 +56,15 @@ class Assertion extends MethodCall {
4056 /** Gets the assertion method targeted by this assertion. */
4157 AssertMethod getAssertMethod ( ) { result = target }
4258
43- /** Gets the expression that this assertion pertains to. */
44- Expr getExpr ( ) { result = this .getArgumentForParameter ( target .getAssertedParameter ( ) ) }
59+ /**
60+ * DEPRECATED: renamed to `getAnExpr`.
61+ *
62+ * Gets an expression that this assertion pertains to.
63+ */
64+ deprecated Expr getExpr ( ) { result = this .getAnExpr ( ) }
65+
66+ /** Gets an expression that this assertion pertains to. */
67+ Expr getAnExpr ( ) { result = this .getArgumentForParameter ( target .getAnAssertedParameter ( ) ) }
4568
4669 /**
4770 * Holds if basic block `succ` is immediately dominated by this assertion.
@@ -144,7 +167,7 @@ class FailingAssertion extends Assertion {
144167 FailingAssertion ( ) {
145168 exists ( AssertMethod am , Expr e |
146169 am = this .getAssertMethod ( ) and
147- e = this .getExpr ( )
170+ e = this .getAnExpr ( )
148171 |
149172 am instanceof AssertTrueMethod and
150173 e .getValue ( ) = "false"
@@ -163,7 +186,7 @@ class SystemDiagnosticsDebugAssertTrueMethod extends AssertTrueMethod {
163186 this = any ( SystemDiagnosticsDebugClass c ) .getAssertMethod ( )
164187 }
165188
166- override int getAssertionIndex ( ) { result = 0 }
189+ override int getAnAssertionIndex ( ) { result = 0 }
167190
168191 override Class getExceptionClass ( ) {
169192 // A failing assertion generates a message box, see
@@ -186,7 +209,7 @@ class SystemDiagnosticsContractAssertTrueMethod extends AssertTrueMethod {
186209 )
187210 }
188211
189- override int getAssertionIndex ( ) { result = 0 }
212+ override int getAnAssertionIndex ( ) { result = 0 }
190213
191214 override Class getExceptionClass ( ) {
192215 // A failing assertion generates a message box, see
@@ -195,11 +218,50 @@ class SystemDiagnosticsContractAssertTrueMethod extends AssertTrueMethod {
195218 }
196219}
197220
221+ private predicate isDoesNotReturnIfAttributeParameter ( Parameter p , boolean value ) {
222+ exists ( Attribute a | a = p .getAnAttribute ( ) |
223+ a .getType ( ) instanceof SystemDiagnosticsCodeAnalysisDoesNotReturnIfAttributeClass and
224+ a .getConstructorArgument ( 0 ) .( BoolLiteral ) .getBoolValue ( ) = value
225+ )
226+ }
227+
228+ /**
229+ * A method with a parameter that is annotated with
230+ * `System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute(false)`.
231+ */
232+ class SystemDiagnosticsCodeAnalysisDoesNotReturnIfAnnotatedAssertTrueMethod extends AssertTrueMethod {
233+ private int i ;
234+
235+ SystemDiagnosticsCodeAnalysisDoesNotReturnIfAnnotatedAssertTrueMethod ( ) {
236+ isDoesNotReturnIfAttributeParameter ( this .getParameter ( i ) , false )
237+ }
238+
239+ override int getAnAssertionIndex ( ) { result = i }
240+
241+ override SystemExceptionClass getExceptionClass ( ) { any ( ) }
242+ }
243+
244+ /**
245+ * A method with a parameter that is annotated with
246+ * `System.Diagnostics.CodeAnalysis.DoesNotReturnIfAttribute(true)`.
247+ */
248+ class SystemDiagnosticsCodeAnalysisDoesNotReturnIfAnnotatedAssertFalseMethod extends AssertFalseMethod {
249+ private int i ;
250+
251+ SystemDiagnosticsCodeAnalysisDoesNotReturnIfAnnotatedAssertFalseMethod ( ) {
252+ isDoesNotReturnIfAttributeParameter ( this .getParameter ( i ) , true )
253+ }
254+
255+ override int getAnAssertionIndex ( ) { result = i }
256+
257+ override SystemExceptionClass getExceptionClass ( ) { any ( ) }
258+ }
259+
198260/** A Visual Studio assertion method. */
199261class VSTestAssertTrueMethod extends AssertTrueMethod {
200262 VSTestAssertTrueMethod ( ) { this = any ( VSTestAssertClass c ) .getIsTrueMethod ( ) }
201263
202- override int getAssertionIndex ( ) { result = 0 }
264+ override int getAnAssertionIndex ( ) { result = 0 }
203265
204266 override AssertFailedExceptionClass getExceptionClass ( ) { any ( ) }
205267}
@@ -208,7 +270,7 @@ class VSTestAssertTrueMethod extends AssertTrueMethod {
208270class VSTestAssertFalseMethod extends AssertFalseMethod {
209271 VSTestAssertFalseMethod ( ) { this = any ( VSTestAssertClass c ) .getIsFalseMethod ( ) }
210272
211- override int getAssertionIndex ( ) { result = 0 }
273+ override int getAnAssertionIndex ( ) { result = 0 }
212274
213275 override AssertFailedExceptionClass getExceptionClass ( ) { any ( ) }
214276}
@@ -217,7 +279,7 @@ class VSTestAssertFalseMethod extends AssertFalseMethod {
217279class VSTestAssertNullMethod extends AssertNullMethod {
218280 VSTestAssertNullMethod ( ) { this = any ( VSTestAssertClass c ) .getIsNullMethod ( ) }
219281
220- override int getAssertionIndex ( ) { result = 0 }
282+ override int getAnAssertionIndex ( ) { result = 0 }
221283
222284 override AssertFailedExceptionClass getExceptionClass ( ) { any ( ) }
223285}
@@ -226,14 +288,14 @@ class VSTestAssertNullMethod extends AssertNullMethod {
226288class VSTestAssertNonNullMethod extends AssertNonNullMethod {
227289 VSTestAssertNonNullMethod ( ) { this = any ( VSTestAssertClass c ) .getIsNotNullMethod ( ) }
228290
229- override int getAssertionIndex ( ) { result = 0 }
291+ override int getAnAssertionIndex ( ) { result = 0 }
230292
231293 override AssertFailedExceptionClass getExceptionClass ( ) { any ( ) }
232294}
233295
234296/** An NUnit assertion method. */
235297abstract class NUnitAssertMethod extends AssertMethod {
236- override int getAssertionIndex ( ) { result = 0 }
298+ override int getAnAssertionIndex ( ) { result = 0 }
237299
238300 override AssertionExceptionClass getExceptionClass ( ) { any ( ) }
239301}
@@ -292,11 +354,11 @@ class ForwarderAssertMethod extends AssertMethod {
292354 strictcount ( AssignableDefinition def | def .getTarget ( ) = p ) = 1 and
293355 forex ( ControlFlowElement body | body = this .getBody ( ) |
294356 bodyAsserts ( this , body , a ) and
295- a .getExpr ( ) = p .getAnAccess ( )
357+ a .getAnExpr ( ) = p .getAnAccess ( )
296358 )
297359 }
298360
299- override int getAssertionIndex ( ) { result = p .getPosition ( ) }
361+ override int getAnAssertionIndex ( ) { result = p .getPosition ( ) }
300362
301363 override Class getExceptionClass ( ) {
302364 result = this .getUnderlyingAssertMethod ( ) .getExceptionClass ( )
@@ -345,4 +407,4 @@ class ForwarderAssertNonNullMethod extends ForwarderAssertMethod, AssertNonNullM
345407}
346408
347409/** Holds if expression `e` appears in an assertion. */
348- predicate isExprInAssertion ( Expr e ) { e = any ( Assertion a ) .getExpr ( ) .getAChildExpr * ( ) }
410+ predicate isExprInAssertion ( Expr e ) { e = any ( Assertion a ) .getAnExpr ( ) .getAChildExpr * ( ) }
0 commit comments