Ejemplo n.º 1
0
  @Override
  public Boolean visit(final ImportDeclaration n1, final Node arg) {
    final ImportDeclaration n2 = (ImportDeclaration) arg;

    if (!nodeEquals(n1.getName(), n2.getName())) {
      return Boolean.FALSE;
    }

    return Boolean.TRUE;
  }
  @Override
  public String action() {
    List<String> importTails = new ArrayList<>();
    List<String> asteriskImports = new ArrayList<>();
    if (compilationUnit.getImports() != null) {
      for (ImportDeclaration importDeclaration : compilationUnit.getImports()) {
        ClassImport classImport =
            new ClassImport(
                importDeclaration.getName().toStringWithoutComments(),
                importDeclaration.isStatic(),
                importDeclaration.isAsterisk());
        if (classImport.isAsterisk()) {
          asteriskImports.add(classImport.getName());
        } else {
          importTails.add(classImport.getTail());
        }
      }
    }

    if (compilationUnit.getPackage() != null) {
      asteriskImports.add(compilationUnit.getPackage().getName().toStringWithoutComments());
    }

    StringBuilder result = new StringBuilder("[");
    for (String classname : classnames) {
      if (!importTails.contains(classname)) {
        GetClassPackagesAction getPackagesAction = new GetClassPackagesAction();
        String packages = getPackagesAction.perform(new String[] {classname});

        if (packages.startsWith("message:")) {
          return packages;
        } else if (packages.length() == 2) {
          continue;
        }

        String[] splitted = packages.substring(1, packages.length() - 1).split(",");
        boolean found = false;
        for (String foundPackage : splitted) {
          if (foundPackage.trim().isEmpty()) continue;
          foundPackage = foundPackage.trim().substring(1, foundPackage.length() - 1);
          foundPackage = foundPackage.substring(0, foundPackage.lastIndexOf("."));
          for (String asteriskImport : asteriskImports) {
            if (foundPackage.equals(asteriskImport)) {
              found = true;
              break;
            }
          }
        }
        if (!found) {
          result.append(packages).append(",");
        }
      }
    }
    return result.append("]").toString();
  }
 @Override
 public void visit(final CompilationUnit n, final A arg) {
   visitComment(n.getComment(), arg);
   if (n.getPackage() != null) {
     n.getPackage().accept(this, arg);
   }
   if (n.getImports() != null) {
     for (final ImportDeclaration i : n.getImports()) {
       i.accept(this, arg);
     }
   }
   if (n.getTypes() != null) {
     for (final TypeDeclaration<?> typeDeclaration : n.getTypes()) {
       typeDeclaration.accept(this, arg);
     }
   }
 }
 @Override
 public void visit(final ImportDeclaration n, final A arg) {
   visitComment(n.getComment(), arg);
   n.getName().accept(this, arg);
 }