mirror of
https://github.com/github/codeql.git
synced 2026-07-08 21:15:32 +02:00
Allow inline expectation comments in more file formats
This commit is contained in:
@@ -1,13 +1,51 @@
|
||||
private import csharp as CS
|
||||
private import semmle.code.asp.AspNet as ASP
|
||||
private import codeql.util.test.InlineExpectationsTest
|
||||
|
||||
module Impl implements InlineExpectationsTestSig {
|
||||
private newtype TExpectationComment =
|
||||
TCSharpComment(CS::SinglelineComment c) or
|
||||
TXmlComment(CS::XmlComment c) or
|
||||
TAspComment(ASP::AspComment c)
|
||||
|
||||
/**
|
||||
* A class representing line comments in C# used by the InlineExpectations core code
|
||||
* A class representing comments that may contain inline expectations.
|
||||
* Supports C# single-line comments (`//`), XML comments (`<!-- -->`), and
|
||||
* ASP.NET comments (`<!-- -->` and `<%-- --%>`) in their respective file types.
|
||||
*/
|
||||
class ExpectationComment extends CS::SinglelineComment {
|
||||
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
|
||||
string getContents() { result = this.getText() }
|
||||
class ExpectationComment extends TExpectationComment {
|
||||
CS::SinglelineComment asCSharpComment() { this = TCSharpComment(result) }
|
||||
|
||||
CS::XmlComment asXmlComment() { this = TXmlComment(result) }
|
||||
|
||||
ASP::AspComment asAspComment() { this = TAspComment(result) }
|
||||
|
||||
/** Gets the contents of this comment, _without_ the preceding comment marker. */
|
||||
string getContents() {
|
||||
result = this.asCSharpComment().getText()
|
||||
or
|
||||
result = this.asXmlComment().getText()
|
||||
or
|
||||
result = this.asAspComment().getBody()
|
||||
}
|
||||
|
||||
/** Gets the location of this comment. */
|
||||
Location getLocation() {
|
||||
result = this.asCSharpComment().getLocation()
|
||||
or
|
||||
result = this.asXmlComment().getLocation()
|
||||
or
|
||||
result = this.asAspComment().getLocation()
|
||||
}
|
||||
|
||||
/** Gets a textual representation of this comment. */
|
||||
string toString() {
|
||||
result = this.asCSharpComment().toString()
|
||||
or
|
||||
result = this.asXmlComment().toString()
|
||||
or
|
||||
result = this.asAspComment().toString()
|
||||
}
|
||||
}
|
||||
|
||||
class Location = CS::Location;
|
||||
|
||||
Reference in New Issue
Block a user