use of com.sun.source.tree.NewClassTree in project error-prone by google.
the class DefaultCharset method handlePrintWriterOutputStream.
private Description handlePrintWriterOutputStream(NewClassTree tree, VisitorState state) {
Tree outputStream = tree.getArguments().get(0);
Description.Builder description = buildDescription(tree);
for (CharsetFix charsetFix : CharsetFix.values()) {
SuggestedFix.Builder fix = SuggestedFix.builder().prefixWith(outputStream, "new BufferedWriter(new OutputStreamWriter(").postfixWith(outputStream, String.format(", %s))", charsetFix.replacement()));
charsetFix.addImport(fix, state);
fix.addImport("java.io.BufferedWriter");
fix.addImport("java.io.OutputStreamWriter");
description.addFix(fix.build());
}
return description.build();
}
use of com.sun.source.tree.NewClassTree 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