コード例 #1
0
  private void printImports(PrintWriter out, ClassNode classNode) {
    List<String> imports = new ArrayList<String>();

    ModuleNode moduleNode = classNode.getModule();
    for (ImportNode importNode : moduleNode.getStarImports()) {
      imports.add(importNode.getPackageName());
    }

    for (ImportNode imp : moduleNode.getImports()) {
      if (imp.getAlias() == null) imports.add(imp.getType().getName());
    }

    imports.addAll(Arrays.asList(ResolveVisitor.DEFAULT_IMPORTS));

    for (String imp : imports) {
      String s =
          new StringBuilder()
              .append("import ")
              .append(imp)
              .append((imp.charAt(imp.length() - 1) == '.') ? "*;" : ";")
              .toString()
              .replace('$', '.');
      out.println(s);
    }
    out.println();
  }
コード例 #2
0
  public List<ImportNode> getAllImportNodes() {
    if (sortedImports == null) {
      sortedImports = new ArrayList<ImportNode>();

      sortedImports.addAll(module.getImports());
      sortedImports.addAll(module.getStarImports());
      sortedImports.addAll(module.getStaticImports().values());
      sortedImports.addAll(module.getStaticStarImports().values());

      Collections.sort(sortedImports, new ImportNodeComparator());
      sortedImports = Collections.unmodifiableList(sortedImports);
    }
    return sortedImports;
  }
コード例 #3
0
 public void visitImports(ModuleNode node) {
   if (node != null) {
     for (ImportNode importNode : node.getImports()) {
       visitAnnotations(importNode);
       importNode.visit(this);
     }
     for (ImportNode importStarNode : node.getStarImports()) {
       visitAnnotations(importStarNode);
       importStarNode.visit(this);
     }
     for (ImportNode importStaticNode : node.getStaticImports().values()) {
       visitAnnotations(importStaticNode);
       importStaticNode.visit(this);
     }
     for (ImportNode importStaticStarNode : node.getStaticStarImports().values()) {
       visitAnnotations(importStaticStarNode);
       importStaticStarNode.visit(this);
     }
   }
 }
コード例 #4
0
 // not available in 1.6 stream
 public static List<ImportNode> getStarImports(ModuleNode node) {
   return node.getStarImports();
 }