Java Code Examples for com.sun.source.tree.ModuleTree#getDirectives()

The following examples show how to use com.sun.source.tree.ModuleTree#getDirectives() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementScanningTask.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
@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;
}