@@ -1920,3 +1920,39 @@ private YamlMappingLikeNode resolveMatrixAccessPath(
19201920 else result = resolveMatrixAccessPath ( newRoot , rest )
19211921 )
19221922}
1923+
1924+ /** Holds if `c` has location information `(file, startline, startcolumn, endline, endcolumn)`. */
1925+ predicate yamlCommentHasLocationInfo (
1926+ @yaml_comment c , File file , int startline , int startcolumn , int endline , int endcolumn
1927+ ) {
1928+ exists ( @location l |
1929+ hasLocation ( c , l ) and
1930+ locations_default ( l , file , startline , startcolumn , endline , endcolumn )
1931+ )
1932+ }
1933+
1934+ /**
1935+ * A comment.
1936+ *
1937+ * Example:
1938+ *
1939+ * ```
1940+ * # here is a comment
1941+ * ```
1942+ */
1943+ class Comment extends @yaml_comment {
1944+ /** Gets the text of this comment, not including delimiters. */
1945+ string getText ( ) { comments ( this , _, _, result , _) }
1946+
1947+ /** Gets the location of this comment. */
1948+ Location getLocation ( ) {
1949+ exists ( File file , string filepath , int startline , int startcolumn , int endline , int endcolumn |
1950+ yamlCommentHasLocationInfo ( this , file , startline , startcolumn , endline , endcolumn ) and
1951+ filepath = file .getAbsolutePath ( ) and
1952+ result .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
1953+ )
1954+ }
1955+
1956+ /** Gets a string representation of this comment. */
1957+ string toString ( ) { comments ( this , _, _, _, result ) }
1958+ }
0 commit comments