com.sun.source.tree.ModuleTree#getDirectives ( )源码实例Demo

下面列出了com.sun.source.tree.ModuleTree#getDirectives ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: ElementScanningTask.java
@Override
public Context visitModule(ModuleTree node, Void p) {
    final ModuleElement module = (ModuleElement) trees.getElement(getCurrentPath());
    if (module != null) {
        ctx.pos.put(module, this.sourcePositions.getStartPosition(cu, node));
        final List<? extends ModuleElement.Directive> de = module.getDirectives();
        final List<? extends DirectiveTree> dt = node.getDirectives();
        for (int i = 0, j = 0; i < de.size() ; i++) {
            if (isImportant(de.get(i))) {
                ctx.directives.put(de.get(i), dt.get(j));
                ctx.pos.put(de.get(i), this.sourcePositions.getStartPosition(cu, dt.get(j)));
                j += 1;
            }
        }
    }
    return super.visitModule(node, p);
}
 
源代码2 项目: google-java-format   文件: JavaInputAstVisitor.java
@Override
public Void visitModule(ModuleTree node, Void unused) {
  for (AnnotationTree annotation : node.getAnnotations()) {
    scan(annotation, null);
    builder.forcedBreak();
  }
  if (node.getModuleType() == ModuleTree.ModuleKind.OPEN) {
    token("open");
    builder.space();
  }
  token("module");
  builder.space();
  scan(node.getName(), null);
  builder.space();
  if (node.getDirectives().isEmpty()) {
    tokenBreakTrailingComment("{", plusTwo);
    builder.blankLineWanted(BlankLineWanted.NO);
    token("}", plusTwo);
  } else {
    builder.open(plusTwo);
    token("{");
    builder.forcedBreak();
    Optional<Tree.Kind> previousDirective = Optional.empty();
    for (DirectiveTree directiveTree : node.getDirectives()) {
      markForPartialFormat();
      builder.blankLineWanted(
          previousDirective.map(k -> !k.equals(directiveTree.getKind())).orElse(false)
              ? BlankLineWanted.YES
              : BlankLineWanted.NO);
      builder.forcedBreak();
      scan(directiveTree, null);
      previousDirective = Optional.of(directiveTree.getKind());
    }
    builder.close();
    builder.forcedBreak();
    token("}");
  }
  return null;
}
 
 同类方法