Search in sources :

Example 36 with CompilationUnit

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());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 37 with CompilationUnit

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);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 38 with CompilationUnit

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());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 39 with CompilationUnit

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);
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 40 with CompilationUnit

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));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Aggregations

CompilationUnit (com.github.javaparser.ast.CompilationUnit)489 Test (org.junit.Test)304 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)160 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)140 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)128 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)101 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)70 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)66 Context (com.github.javaparser.symbolsolver.core.resolution.Context)62 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)55 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)51 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)45 File (java.io.File)39 Expression (com.github.javaparser.ast.expr.Expression)38 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 MethodUsage (com.github.javaparser.resolution.MethodUsage)34 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)33 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)29 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)29 ArrayList (java.util.ArrayList)29