public static String imports(Node node, ImportList til) { final List<Declaration> unused = new ArrayList<Declaration>(); DetectUnusedImportsVisitor duiv = new DetectUnusedImportsVisitor(unused); til.visit(duiv); node.visit(duiv); return reorganizeImports(til, unused, Collections.<Declaration>emptyList()); }
public static Map<Declaration, String> getImports( Node node, final String packageName, final Tree.CompilationUnit ncu, final Set<String> packages) { final Map<Declaration, String> imports = new HashMap<Declaration, String>(); node.visit( new Visitor() { private void add(Declaration d, Tree.Identifier id) { if (d != null && id != null) { String pn = d.getUnit().getPackage().getNameAsString(); if (d.isToplevel() && !pn.equals(packageName) && !pn.equals(Module.LANGUAGE_MODULE_NAME) && (ncu == null || !isImported(d, ncu))) { imports.put(d, id.getText()); packages.add(pn); } } } @Override public void visit(Tree.BaseType that) { super.visit(that); add(that.getDeclarationModel(), that.getIdentifier()); } @Override public void visit(Tree.BaseMemberOrTypeExpression that) { super.visit(that); add(that.getDeclaration(), that.getIdentifier()); } @Override public void visit(Tree.MemberLiteral that) { add(that.getDeclaration(), that.getIdentifier()); } }); return imports; }