Skip to content

Commit 7879690

Browse files
committed
Model line-comment expectation syntax
Expose whether each expectation comment uses line-comment syntax so learning can distinguish comments that the current renderer can safely replace. Implement the classification in every inline-expectation adapter, including mixed line/block-comment languages. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1adfa307-c48e-43f5-94e3-8286e4a8c083
1 parent 83c72c1 commit 7879690

16 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎actions/ql/lib/codeql/actions/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Impl implements InlineExpectationsTestSig {
88
class ExpectationComment extends Yaml::YamlComment {
99
/** Gets the contents of this comment. */
1010
string getContents() { result = this.getText() }
11+
12+
/** YAML comments use line-comment syntax. */
13+
predicate isLineComment() { any() }
1114
}
1215

1316
class Location = L::Location;

‎actions/ql/test/utils/ActionsInlineExpectationsTestQuery.ql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private module Impl implements T::InlineExpectationsTestSig {
2828

2929
class ExpectationComment extends Yaml::YamlComment {
3030
string getContents() { result = this.getText() }
31+
32+
predicate isLineComment() { any() }
3133
}
3234
}
3335

‎cpp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module Impl implements InlineExpectationsTestSig {
1717
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
1818
string getContents() { result = comment.getContents().suffix(2) }
1919

20+
/** C++ expectation comments use line-comment syntax. */
21+
predicate isLineComment() { any() }
22+
2023
/** Gets a textual representation of this element. */
2124
string toString() { result = comment.toString() }
2225

‎csharp/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module Impl implements InlineExpectationsTestSig {
2929
result = this.asAspComment().getBody()
3030
}
3131

32+
/** Holds if this is a C# `//` comment. */
33+
predicate isLineComment() { exists(this.asCSharpComment()) }
34+
3235
/** Gets the location of this comment. */
3336
Location getLocation() {
3437
result = this.asCSharpComment().getLocation()

‎go/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module Impl implements InlineExpectationsTestSig {
1515
/** Returns the contents of the given comment, _without_ the preceding comment marker (`//`). */
1616
string getContents() { result = this.getText() }
1717

18+
/** Holds if this comment uses `//` syntax. */
19+
predicate isLineComment() { this instanceof G::LineComment }
20+
1821
/** Gets this element's location. */
1922
G::Location getLocation() { result = super.getLocation() }
2023
}

‎java/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ module Impl implements InlineExpectationsTestSig {
1212
abstract class ExpectationComment extends J::Top {
1313
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
1414
abstract string getContents();
15+
16+
/** Java expectation comments use line-comment syntax. */
17+
predicate isLineComment() { any() }
1518
}
1619

1720
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {

‎java/ql/test-kotlin1/TestUtilities/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module Impl implements InlineExpectationsTestSig {
99
abstract class ExpectationComment extends J::Top {
1010
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
1111
abstract string getContents();
12+
13+
/** Java and Kotlin expectation comments use line-comment syntax. */
14+
predicate isLineComment() { any() }
1215
}
1316

1417
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {

‎java/ql/test-kotlin2/TestUtilities/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module Impl implements InlineExpectationsTestSig {
99
abstract class ExpectationComment extends J::Top {
1010
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
1111
abstract string getContents();
12+
13+
/** Java and Kotlin expectation comments use line-comment syntax. */
14+
predicate isLineComment() { any() }
1215
}
1316

1417
private class JavadocExpectationComment extends J::Javadoc, ExpectationComment {

‎javascript/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module Impl implements InlineExpectationsTestSig {
2929
abstract private class ExpectationCommentImpl extends Locatable {
3030
abstract string getContents();
3131

32+
/** Holds if this comment uses line-comment syntax. */
33+
predicate isLineComment() { this instanceof LineComment }
34+
3235
/** Gets this element's location. */
3336
Location getLocation() { result = super.getLocation() }
3437
}

‎python/ql/lib/utils/test/internal/InlineExpectationsTestImpl.qll‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ module Impl implements InlineExpectationsTestSig {
66
* A class representing line comments in Python. As this is the only form of comment Python
77
* permits, we simply reuse the `Comment` class.
88
*/
9-
class ExpectationComment = PY::Comment;
9+
class ExpectationComment extends PY::Comment {
10+
/** Python comments use line-comment syntax. */
11+
predicate isLineComment() { any() }
12+
}
1013

1114
class Location = PY::Location;
1215

0 commit comments

Comments
 (0)