Search in sources :

Example 11 with Name

use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.

the class NodeListTest method addAfterLast.

@Test
public void addAfterLast() {
    Name cde = new Name("cde");
    final NodeList<Name> list = nodeList(new Name("abc"), new Name("bcd"), cde);
    list.addAfter(new Name("xxx"), cde);
    assertEquals("[abc, bcd, cde, xxx]", list.toString());
}
Also used : SimpleName(com.github.javaparser.ast.expr.SimpleName) Name(com.github.javaparser.ast.expr.Name) Test(org.junit.Test)

Example 12 with Name

use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.

the class NodeListTest method addAfter.

@Test
public void addAfter() {
    Name n = new Name("bcd");
    final NodeList<Name> list = nodeList(new Name("abc"), n, new Name("cde"));
    list.addAfter(new Name("xxx"), n);
    assertEquals("[abc, bcd, xxx, cde]", list.toString());
}
Also used : SimpleName(com.github.javaparser.ast.expr.SimpleName) Name(com.github.javaparser.ast.expr.Name) Test(org.junit.Test)

Example 13 with Name

use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.

the class CompilationUnitTransformationsTest method replacingPackageDeclaration.

@Test
public void replacingPackageDeclaration() throws IOException {
    considerCode("package foo.bar; class A {}");
    cu.setPackageDeclaration(new PackageDeclaration(new Name(new Name("foo2"), "baz")));
    assertTransformedToString("package foo2.baz;" + EOL + EOL + " class A {}", cu);
}
Also used : PackageDeclaration(com.github.javaparser.ast.PackageDeclaration) Name(com.github.javaparser.ast.expr.Name) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 14 with Name

use of com.github.javaparser.ast.expr.Name in project javaparser by javaparser.

the class ModuleDeclarationTest method jlsExample1.

@Test
public void jlsExample1() {
    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;" + "}");
    ModuleDeclaration module = cu.getModule().get();
    assertEquals("M.N", module.getNameAsString());
    assertEquals(false, module.isOpen());
    assertThat(module.getAnnotations()).containsExactly(new SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("1")), new SingleMemberAnnotationExpr(new Name("Foo"), new IntegerLiteralExpr("2")), new MarkerAnnotationExpr(new Name("Bar")));
    ModuleRequiresStmt moduleRequiresStmt = module.getModuleStmts().get(0).asModuleRequiresStmt();
    assertThat(moduleRequiresStmt.getNameAsString()).isEqualTo("A.B");
    assertThat(moduleRequiresStmt.getModifiers()).isEmpty();
    ModuleExportsStmt moduleExportsStmt = module.getModuleStmts().get(5).asModuleExportsStmt();
    assertThat(moduleExportsStmt.getNameAsString()).isEqualTo("R.S");
    assertThat(moduleExportsStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));
    ModuleOpensStmt moduleOpensStmt = module.getModuleStmts().get(7).asModuleOpensStmt();
    assertThat(moduleOpensStmt.getNameAsString()).isEqualTo("R.S");
    assertThat(moduleOpensStmt.getModuleNames()).containsExactly(parseName("T1.U1"), parseName("T2.U2"));
    ModuleUsesStmt moduleUsesStmt = module.getModuleStmts().get(8).asModuleUsesStmt();
    assertThat(moduleUsesStmt.getType().toString()).isEqualTo("V.W");
    ModuleProvidesStmt moduleProvidesStmt = module.getModuleStmts().get(9).asModuleProvidesStmt();
    assertThat(moduleProvidesStmt.getType().toString()).isEqualTo("X.Y");
    assertThat(moduleProvidesStmt.getWithTypes()).containsExactly(new ClassOrInterfaceType(parseClassOrInterfaceType("Z1"), "Z2"), new ClassOrInterfaceType(parseClassOrInterfaceType("Z3"), "Z4"));
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) SingleMemberAnnotationExpr(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr) IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) MarkerAnnotationExpr(com.github.javaparser.ast.expr.MarkerAnnotationExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) JavaParser.parseClassOrInterfaceType(com.github.javaparser.JavaParser.parseClassOrInterfaceType) Name(com.github.javaparser.ast.expr.Name) JavaParser.parseName(com.github.javaparser.JavaParser.parseName) Test(org.junit.Test)

Aggregations

Name (com.github.javaparser.ast.expr.Name)14 Test (org.junit.Test)13 SimpleName (com.github.javaparser.ast.expr.SimpleName)8 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)2 NodeList (com.github.javaparser.ast.NodeList)2 PackageDeclaration (com.github.javaparser.ast.PackageDeclaration)2 NormalAnnotationExpr (com.github.javaparser.ast.expr.NormalAnnotationExpr)2 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)2 JavaParser.parseClassOrInterfaceType (com.github.javaparser.JavaParser.parseClassOrInterfaceType)1 JavaParser.parseName (com.github.javaparser.JavaParser.parseName)1 ArrayCreationLevel (com.github.javaparser.ast.ArrayCreationLevel)1 ImportDeclaration (com.github.javaparser.ast.ImportDeclaration)1 AnnotationDeclaration (com.github.javaparser.ast.body.AnnotationDeclaration)1 AnnotationMemberDeclaration (com.github.javaparser.ast.body.AnnotationMemberDeclaration)1 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)1 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)1 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)1 MarkerAnnotationExpr (com.github.javaparser.ast.expr.MarkerAnnotationExpr)1