|
1 | 1 | private import csharp as CS |
| 2 | +private import semmle.code.asp.AspNet as ASP |
2 | 3 | private import codeql.util.test.InlineExpectationsTest |
3 | 4 |
|
4 | 5 | module Impl implements InlineExpectationsTestSig { |
| 6 | + private newtype TExpectationComment = |
| 7 | + TCSharpComment(CS::SinglelineComment c) or |
| 8 | + TXmlComment(CS::XmlComment c) or |
| 9 | + TAspComment(ASP::AspComment c) |
| 10 | + |
5 | 11 | /** |
6 | | - * A class representing line comments in C# used by the InlineExpectations core code |
| 12 | + * A class representing comments that may contain inline expectations. |
| 13 | + * Supports C# single-line comments (`//`), XML comments (`<!-- -->`), and |
| 14 | + * ASP.NET comments (`<!-- -->` and `<%-- --%>`) in their respective file types. |
7 | 15 | */ |
8 | | - class ExpectationComment extends CS::SinglelineComment { |
9 | | - /** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */ |
10 | | - string getContents() { result = this.getText() } |
| 16 | + class ExpectationComment extends TExpectationComment { |
| 17 | + CS::SinglelineComment asCSharpComment() { this = TCSharpComment(result) } |
| 18 | + |
| 19 | + CS::XmlComment asXmlComment() { this = TXmlComment(result) } |
| 20 | + |
| 21 | + ASP::AspComment asAspComment() { this = TAspComment(result) } |
| 22 | + |
| 23 | + /** Gets the contents of this comment, _without_ the preceding comment marker. */ |
| 24 | + string getContents() { |
| 25 | + result = this.asCSharpComment().getText() |
| 26 | + or |
| 27 | + result = this.asXmlComment().getText() |
| 28 | + or |
| 29 | + result = this.asAspComment().getBody() |
| 30 | + } |
| 31 | + |
| 32 | + /** Gets the location of this comment. */ |
| 33 | + Location getLocation() { |
| 34 | + result = this.asCSharpComment().getLocation() |
| 35 | + or |
| 36 | + result = this.asXmlComment().getLocation() |
| 37 | + or |
| 38 | + result = this.asAspComment().getLocation() |
| 39 | + } |
| 40 | + |
| 41 | + /** Gets a textual representation of this comment. */ |
| 42 | + string toString() { |
| 43 | + result = this.asCSharpComment().toString() |
| 44 | + or |
| 45 | + result = this.asXmlComment().toString() |
| 46 | + or |
| 47 | + result = this.asAspComment().toString() |
| 48 | + } |
11 | 49 | } |
12 | 50 |
|
13 | 51 | class Location = CS::Location; |
|
0 commit comments