-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathComment.java
More file actions
60 lines (50 loc) · 1.57 KB
/
Comment.java
File metadata and controls
60 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.semmle.js.ast;
import static com.semmle.js.ast.Comment.Kind.BLOCK;
import static com.semmle.js.ast.Comment.Kind.HTML_END;
import static com.semmle.js.ast.Comment.Kind.HTML_START;
import static com.semmle.js.ast.Comment.Kind.LINE;
/**
* A source code comment.
*
* <p>This is not part of the SpiderMonkey AST format.
*/
public class Comment extends SourceElement {
/** The kinds of comments recognized by the parser. */
public static enum Kind {
/** A C++-style line comment starting with two slashes. */
LINE,
/** A C-style block comment starting with slash-star and ending with star-slash. */
BLOCK,
/** The start of an HTML comment (<code><!--</code>). */
HTML_START,
/** The end of an HTML comment (<code>--></code>). */
HTML_END
};
private final String text;
private final Kind kind;
public Comment(SourceLocation loc, String text) {
super(loc);
this.text = text;
String raw = getLoc().getSource();
if (raw.startsWith("//")) this.kind = LINE;
else if (raw.startsWith("/*")) this.kind = BLOCK;
else if (raw.startsWith("<!--")) this.kind = HTML_START;
else this.kind = HTML_END;
}
/** What kind of comment is this? */
public Kind getKind() {
return kind;
}
/** Is this a JSDoc documentation comment? */
public boolean isDocComment() {
return kind == BLOCK && text.startsWith("*");
}
/**
* The text of the comment, not including its delimiters.
*
* <p>For documentation comments, the leading asterisk is included.
*/
public String getText() {
return text;
}
}