@@ -226,15 +226,20 @@ class DeviationAttribute extends StdAttribute {
226226
227227 DeviationRecord getADeviationRecord ( ) { result = record }
228228
229- pragma [ nomagic ]
230- Element getASuppressedElement ( ) {
229+ /** Gets the element to which this attribute was applied. */
230+ Element getPrimarySuppressedElement ( ) {
231231 result .( Type ) .getAnAttribute ( ) = this
232232 or
233233 result .( Stmt ) .getAnAttribute ( ) = this
234234 or
235235 result .( Variable ) .getAnAttribute ( ) = this
236236 or
237237 result .( Function ) .getAnAttribute ( ) = this
238+ }
239+
240+ pragma [ nomagic]
241+ Element getASuppressedElement ( ) {
242+ result = this .getPrimarySuppressedElement ( )
238243 or
239244 result .( Expr ) .getEnclosingStmt ( ) = this .getASuppressedElement ( )
240245 or
@@ -336,26 +341,60 @@ class CodeIdentifierDeviation extends TCodeIndentifierDeviation {
336341 )
337342 }
338343
344+ predicate hasLocationInfo (
345+ string filepath , int suppressedLine , int suppressedColumn , int endline , int endcolumn
346+ ) {
347+ exists ( Comment commentMarker |
348+ this = TSingleLineDeviation ( _, commentMarker , filepath , suppressedLine ) and
349+ suppressedColumn = 1 and
350+ endline = suppressedLine
351+ |
352+ if commentMarker instanceof DeviationEndOfLineMarker
353+ then endcolumn = commentMarker .( DeviationEndOfLineMarker ) .getLocation ( ) .getEndColumn ( )
354+ else
355+ // Find the last column for a location on the next line
356+ endcolumn =
357+ max ( Location l |
358+ l .hasLocationInfo ( filepath , _, _, _, _) and
359+ l .getEndLine ( ) = suppressedLine
360+ |
361+ l .getEndColumn ( )
362+ )
363+ )
364+ or
365+ this = TMultiLineDeviation ( _, _, _, filepath , suppressedLine , endline ) and
366+ suppressedColumn = 1 and
367+ endcolumn = 1
368+ or
369+ exists ( DeviationAttribute attribute |
370+ this = TCodeIdentifierDeviation ( _, attribute ) and
371+ attribute
372+ .getPrimarySuppressedElement ( )
373+ .getLocation ( )
374+ .hasLocationInfo ( filepath , suppressedLine , suppressedColumn , endline , endcolumn )
375+ )
376+ }
377+
339378 string toString ( ) {
340379 exists ( string filepath |
341380 exists ( int suppressedLine |
342381 this = TSingleLineDeviation ( _, _, filepath , suppressedLine ) and
343382 result =
344- "Deviation record " + getADeviationRecord ( ) + " applied to " + filepath + " Line " +
383+ "Deviation of " + getADeviationRecord ( ) . getQuery ( ) + " applied to " + filepath + " Line " +
345384 suppressedLine
346385 )
347386 or
348387 exists ( int suppressedStartLine , int suppressedEndLine |
349388 this = TMultiLineDeviation ( _, _, _, filepath , suppressedStartLine , suppressedEndLine ) and
350389 result =
351- "Deviation record " + getADeviationRecord ( ) + " applied to " + filepath + " Line" +
390+ "Deviation of " + getADeviationRecord ( ) . getQuery ( ) + " applied to " + filepath + " Line " +
352391 suppressedStartLine + ":" + suppressedEndLine
353392 )
354393 )
355394 or
356395 exists ( DeviationAttribute attribute |
357396 this = TCodeIdentifierDeviation ( _, attribute ) and
358- result = "Deviation record " + getADeviationRecord ( ) + " applied to " + attribute
397+ result = "Deviation of " + getADeviationRecord ( ) . getQuery ( ) + " applied to " + attribute
359398 )
360399 }
361400}
0 commit comments