コード例 #1
0
 private CompilationUnit getCompilationUnit(SourceFile sourceFile) {
   CompilationUnit compilationUnit;
   if (Files.exists(sourceFile.getOutputPath())) {
     try {
       compilationUnit = JavaParser.parse(sourceFile.getOutputPath().toFile());
     } catch (Throwable t) {
       throw new RuntimeException(t);
     }
   } else {
     compilationUnit = new CompilationUnit();
     compilationUnit.setComment(
         new LineComment(" Generated by GraphWalker (http://www.graphwalker.org)"));
     if (!"".equals(sourceFile.getPackageName())) {
       compilationUnit.setPackage(createPackageDeclaration(sourceFile));
     }
     compilationUnit.setImports(
         Arrays.asList(
             new ImportDeclaration(
                 new NameExpr("org.graphwalker.java.annotation.Model"), false, false),
             new ImportDeclaration(
                 new NameExpr("org.graphwalker.java.annotation.Vertex"), false, false),
             new ImportDeclaration(
                 new NameExpr("org.graphwalker.java.annotation.Edge"), false, false)));
     ASTHelper.addTypeDeclaration(compilationUnit, getInterfaceName(sourceFile));
   }
   return compilationUnit;
 }
コード例 #2
0
  @Test
  public void tesCompilationUnitNotEqual() throws Exception {
    String source = Helper.readClass("DumperTestClass");
    CompilationUnit cu1 = Helper.parserString(source);
    CompilationUnit cu2 = Helper.parserString(source);

    cu2.setPackage(new PackageDeclaration(new NameExpr("diff_package")));
    assertNotEqualsAndHashCode(cu1, cu2);
  }
コード例 #3
0
 public CompilationUnitBuilder pakage(String pkgName) {
   NameExpr name = new NameExpr(pkgName);
   PackageDeclaration pakage = new PackageDeclaration(name);
   cu.setPackage(pakage);
   return this;
 }