Add QL classes and tests for comments

This commit is contained in:
Tamas Vajk
2021-09-27 15:24:11 +02:00
committed by Ian Lynagh
parent 7d479943db
commit ab77ed085f
4 changed files with 103 additions and 0 deletions

View File

@@ -147,3 +147,37 @@ class JavadocText extends JavadocElement, @javadocText {
override string getAPrimaryQlClass() { result = "JavadocText" }
}
/** A Kotlin comment. */
class KtComment extends Top, @ktcomment {
/** Gets the full text of this comment. */
string getText() { ktComments(this, _, result) }
/** Gets the sections of this comment. */
KtCommentSection getSections() { ktCommentSections(result, this, _) }
/** Gets the owner of this comment, if any. */
Top getOwner() { ktCommentOwners(this, result) }
override string toString() { result = this.getText() }
override string getAPrimaryQlClass() { result = "KtComment" }
}
/** A Kotlin comment. */
class KtCommentSection extends @ktcommentsection {
/** Gets the content text of this section. */
string getContent() { ktCommentSections(this, _, result) }
/** Gets the parent comment. */
KtComment getParent() { ktCommentSections(this, result, _) }
/** Gets the section name if any. */
string getName() { ktCommentSectionNames(this, result) }
/** Gets the section subject name if any. */
string getSubjectName() { ktCommentSectionSubjectNames(this, result) }
/** Gets the string representation of this section. */
string toString() { result = this.getContent() }
}

View File

@@ -0,0 +1,31 @@
comments
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | /** Kdoc with no owner */ |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ |
| comments.kt:13:5:16:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ |
| comments.kt:18:9:18:25 | // A line comment | // A line comment |
| comments.kt:22:5:24:6 | /*\n A block comment\n */ | /*\n A block comment\n */ |
commentOwners
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | <init> |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | Group |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | equals |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | hashCode |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | other |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | comments.kt:12:1:25:1 | toString |
| comments.kt:13:5:16:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | comments.kt:17:5:20:5 | add |
commentSections
| comments.kt:1:1:1:25 | /** Kdoc with no owner */ | Kdoc with no owner |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | Creates an empty group. |
| comments.kt:4:1:11:3 | /**\n * A group of *members*.\n *\n * This class has no useful logic; it's just a documentation example.\n *\n * @property name the name of this group.\n * @constructor Creates an empty group.\n */ | the name of this group. |
| comments.kt:13:5:16:7 | /**\n * Adds a [member] to this group.\n * @return the new size of the group.\n */ | Adds a [member] to this group.\n |
commentSectionContents
| A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n | A group of *members*.\n\nThis class has no useful logic; it's just a documentation example.\n\n |
| Adds a [member] to this group.\n | Adds a [member] to this group.\n |
| Creates an empty group. | Creates an empty group. |
| Kdoc with no owner | Kdoc with no owner |
| the name of this group. | the name of this group. |
commentSectionNames
| Creates an empty group. | constructor |
| the name of this group. | property |
commentSectionSubjectNames
| the name of this group. | name |

View File

@@ -0,0 +1,25 @@
/** Kdoc with no owner */
package foo.bar
/**
* A group of *members*.
*
* This class has no useful logic; it's just a documentation example.
*
* @property name the name of this group.
* @constructor Creates an empty group.
*/
class Group(val name: String) {
/**
* Adds a [member] to this group.
* @return the new size of the group.
*/
fun add(member: Int): Int {
// A line comment
return 42
}
/*
A block comment
*/
}

View File

@@ -0,0 +1,13 @@
import java
query predicate comments(KtComment c, string s) { c.getText() = s }
query predicate commentOwners(KtComment c, Top t) { c.getOwner() = t }
query predicate commentSections(KtComment c, KtCommentSection s) { c.getSections() = s }
query predicate commentSectionContents(KtCommentSection s, string c) { s.getContent() = c }
query predicate commentSectionNames(KtCommentSection s, string c) { s.getName() = c }
query predicate commentSectionSubjectNames(KtCommentSection s, string c) { s.getSubjectName() = c }