use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrintVisitorTest method emptyJavadocGetsFormatted.
@Test
public void emptyJavadocGetsFormatted() {
CompilationUnit cu = new CompilationUnit();
cu.addClass("X").addMethod("abc").setJavadocComment("");
assertEqualsNoEol("public class X {\n" + "\n" + " /**\n" + " */\n" + " void abc() {\n" + " }\n" + "}\n", cu.toString());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrintVisitorTest method printClassWithoutJavaDocButWithComment.
@Test
public void printClassWithoutJavaDocButWithComment() {
String code = String.format("/** javadoc */ public class A { %s// stuff%s}", EOL, EOL);
CompilationUnit cu = JavaParser.parse(code);
PrettyPrinterConfiguration ignoreJavaDoc = new PrettyPrinterConfiguration().setPrintJavadoc(false);
String content = cu.toString(ignoreJavaDoc);
assertEquals(String.format("public class A {%s // stuff%s}%s", EOL, EOL, EOL), content);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrintVisitorTest method blockcommentGetsNoFormatting.
@Test
public void blockcommentGetsNoFormatting() {
CompilationUnit cu = JavaParser.parse("class A {\n" + " public void helloWorld(String greeting, String name) {\n" + " //sdfsdfsdf\n" + " //sdfds\n" + " /*\n" + " dgfdgfdgfdgfdgfd\n" + " */\n" + " }\n" + "}\n");
assertEqualsNoEol("class A {\n" + "\n" + " public void helloWorld(String greeting, String name) {\n" + " // sdfsdfsdf\n" + " // sdfds\n" + " /*\n" + " dgfdgfdgfdgfdgfd\n" + " */\n" + " }\n" + "}\n", cu.toString());
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrintVisitorTest method printImportsDefaultOrder.
@Test
public void printImportsDefaultOrder() {
String code = "import x.y.z;import a.b.c;import static b.c.d;class c {}";
CompilationUnit cu = JavaParser.parse(code);
String content = cu.toString();
assertEqualsNoEol("import x.y.z;\n" + "import a.b.c;\n" + "import static b.c.d;\n" + "\n" + "class c {\n" + "}\n", content);
}
use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.
the class PrettyPrinterTest method enumConstantsVertically.
@Test
public void enumConstantsVertically() {
CompilationUnit cu = parse("enum X{A, B, C, D, E, F}");
assertEqualsNoEol("enum X {\n\n A,\n B,\n C,\n D,\n E,\n F\n}\n", new PrettyPrinter().print(cu));
}
Aggregations