Skip to content

Commit 53f32f5

Browse files
authored
Merge pull request #9186 from atorralba/atorralba/kotlin-inline-expectations-tests
Kotlin: Add support for InlineExpectationsTest
2 parents 629e90f + dbf249b commit 53f32f5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

java/ql/lib/semmle/code/java/Javadoc.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ class KtComment extends Top, @ktcomment {
153153
/** Gets the full text of this comment. */
154154
string getText() { ktComments(this, _, result) }
155155

156+
/** Holds if this comment is an EOL comment. */
157+
predicate isEolComment() { ktComments(this, 1, _) }
158+
159+
/** Holds if this comment is a block comment. */
160+
predicate isBlockComment() { ktComments(this, 2, _) }
161+
162+
/** Holds if this comment is a KDoc comment. */
163+
predicate isDocComment() { ktComments(this, 3, _) }
164+
156165
/** Gets the sections of this comment. */
157166
KtCommentSection getSections() { ktCommentSections(result, this, _) }
158167

java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ import java
44
* A class representing line comments in Java, which is simply Javadoc restricted
55
* to EOL comments, with an extra accessor used by the InlineExpectations core code
66
*/
7-
class ExpectationComment extends Javadoc {
8-
ExpectationComment() { isEolComment(this) }
9-
7+
abstract class ExpectationComment extends Top {
108
/** Gets the contents of the given comment, _without_ the preceding comment marker (`//`). */
11-
string getContents() { result = this.getChild(0).toString() }
9+
abstract string getContents();
10+
}
11+
12+
private class JavadocExpectationComment extends Javadoc, ExpectationComment {
13+
JavadocExpectationComment() { isEolComment(this) }
14+
15+
override string getContents() { result = this.getChild(0).toString() }
16+
}
17+
18+
private class KtExpectationComment extends KtComment, ExpectationComment {
19+
KtExpectationComment() { this.isEolComment() }
20+
21+
override string getContents() { result = this.getText().suffix(2).trim() }
1222
}

0 commit comments

Comments
 (0)