use of com.sun.tools.javac.parser.Tokens.Comment in project error-prone by google.
the class ASTHelpersTest method testCommentTokens.
@Test
public void testCommentTokens() {
writeFile("A.java", "public class A {", " Runnable theRunnable = new Runnable() {", " /**", " * foo", " */", " public void run() {", " /* bar1 */", " /* bar2 */", " System.err.println(\"Hi\");", " }", " // baz number 1", " // baz number 2", " };", "}");
TestScanner scanner = new TestScanner() {
@Override
public Void visitNewClass(NewClassTree tree, VisitorState state) {
setAssertionsComplete();
List<String> comments = new ArrayList<>();
for (ErrorProneToken t : state.getTokensForNode(tree)) {
if (!t.comments().isEmpty()) {
for (Comment c : t.comments()) {
Verify.verify(c.getSourcePos(0) >= 0);
comments.add(c.getText());
}
}
}
assertThat(comments).containsExactly("/**\n * foo\n */", "/* bar1 */", "/* bar2 */", "// baz number 1", "// baz number 2").inOrder();
return super.visitNewClass(tree, state);
}
};
tests.add(scanner);
assertCompiles(scanner);
}
Aggregations