Search in sources :

Example 66 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class JavaParserTest method rangeOfAnnotationMemberDeclarationIsCorrect.

@Test
public void rangeOfAnnotationMemberDeclarationIsCorrect() {
    String code = "@interface AD { String foo(); }";
    CompilationUnit cu = JavaParser.parse(code);
    AnnotationMemberDeclaration memberDeclaration = cu.getAnnotationDeclarationByName("AD").get().getMember(0).asAnnotationMemberDeclaration();
    assertEquals(true, memberDeclaration.getRange().isPresent());
    assertEquals(new Range(new Position(1, 17), new Position(1, 29)), memberDeclaration.getRange().get());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) AnnotationMemberDeclaration(com.github.javaparser.ast.body.AnnotationMemberDeclaration) Test(org.junit.Test)

Example 67 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ModuleDeclarationTest method jlsExample2HasAnOpenModule.

@Test
public void jlsExample2HasAnOpenModule() {
    CompilationUnit cu = parse("open module M.N {}");
    ModuleDeclaration module = cu.getModule().get();
    assertEquals("M.N", module.getNameAsString());
    assertEquals(true, module.isOpen());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 68 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ModuleDeclarationTest method testPrettyPrinting.

@Test
public void testPrettyPrinting() {
    CompilationUnit cu = parse("@Foo(1) @Foo(2) @Bar " + "module M.N {" + "  requires A.B;" + "  requires transitive C.D;" + "  requires static E.F;" + "  requires transitive static G.H;" + "" + "  exports P.Q;" + "  exports R.S to T1.U1, T2.U2;" + "" + "  opens P.Q;" + "  opens R.S to T1.U1, T2.U2;" + "" + "  uses V.W;" + "  provides X.Y with Z1.Z2, Z3.Z4;" + "}");
    assertEquals("@Foo(1) @Foo(2) @Bar " + EOL + "module M.N {" + EOL + "    requires A.B;" + EOL + "    requires transitive C.D;" + EOL + "    requires static E.F;" + EOL + "    requires static transitive G.H;" + EOL + "    exports P.Q;" + EOL + "    exports R.S to T1.U1, T2.U2;" + EOL + "    opens P.Q;" + EOL + "    opens R.S to T1.U1, T2.U2;" + EOL + "    uses V.W;" + EOL + "    provides X.Y with Z1.Z2, Z3.Z4;" + EOL + "}" + EOL, cu.toString());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 69 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ModuleDeclarationTest method issue988RequireTransitiveShouldRequireAModuleCalledTransitive.

@Test
public void issue988RequireTransitiveShouldRequireAModuleCalledTransitive() {
    CompilationUnit cu = parse("module X { requires transitive; }");
    ModuleRequiresStmt requiresTransitive = (ModuleRequiresStmt) cu.getModule().get().getModuleStmts().get(0);
    assertEquals("transitive", requiresTransitive.getNameAsString());
    assertEquals(IDENTIFIER, requiresTransitive.getName().getTokenRange().get().getBegin().getKind());
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) Test(org.junit.Test)

Example 70 with CompilationUnit

use of com.github.javaparser.ast.CompilationUnit in project javaparser by javaparser.

the class ConcreteSyntaxModelAcceptanceTest method printingExamplePrettyPrintVisitor.

@Test
public void printingExamplePrettyPrintVisitor() throws IOException {
    CompilationUnit cu = JavaParser.parse(rootDir.resolve("com/github/javaparser/printer/PrettyPrintVisitor.java"));
    assertEquals(prettyPrintedExpectation("PrettyPrintVisitor"), prettyPrint(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