コード例 #1
0
  private void printImports(CompilationUnit node) {
    ImplementationImportCollector collector = new ImplementationImportCollector();
    collector.collect(node, getSourceFileName());
    Set<Import> imports = collector.getImports();

    if (!imports.isEmpty()) {
      Set<String> includeStmts = Sets.newTreeSet();
      for (Import imp : imports) {
        includeStmts.add(String.format("#include \"%s.h\"", imp.getImportFileName()));
      }
      for (String stmt : includeStmts) {
        println(stmt);
      }

      // Print native includes.
      int endOfImportText =
          node.types().isEmpty()
              ? node.getLength()
              : ((ASTNode) node.types().get(0)).getStartPosition();
      for (Comment c : ASTUtil.getCommentList(node)) {
        int start = c.getStartPosition();
        if (start >= endOfImportText) {
          break;
        }
        if (c instanceof BlockComment) {
          String nativeImport = extractNativeCode(start, c.getLength(), true);
          if (nativeImport != null) { // if it has a JSNI section
            println(nativeImport.trim());
          }
        }
      }

      newline();
    }
  }
コード例 #2
0
 /** Finds all block comments and associates them with their containing type. */
 private void findBlockComments(CompilationUnit unit, List<AbstractTypeDeclaration> types) {
   List<Comment> comments = ASTUtil.getCommentList(unit);
   for (Comment comment : comments) {
     if (!comment.isBlockComment()) {
       continue;
     }
     int commentPos = comment.getStartPosition();
     AbstractTypeDeclaration containingType = null;
     int containingTypePos = -1;
     for (AbstractTypeDeclaration type : types) {
       int typePos = type.getStartPosition();
       if (typePos < 0) {
         continue;
       }
       int typeEnd = typePos + type.getLength();
       if (commentPos > typePos && commentPos < typeEnd && typePos > containingTypePos) {
         containingType = type;
         containingTypePos = typePos;
       }
     }
     if (containingType != null) {
       blockComments.put(containingType, comment);
     }
   }
 }