private void compactImports() { for (Iterator<String> i = imports.iterator(); i.hasNext(); ) { String importName = i.next(); if (!getShortName(importName).equals("*") && importedPackages.contains(getPackageName(importName))) { i.remove(); } } }
/** * Returns the sorted, formatted import declarations that should be added to the compilation unit. * Each statement appears on its own line, with an additional {@link #getLineDelimiter() line delimiter} before the * first import and between imports from different packages. * @see #getLineDelimiter() */ public String computeSortedImports() { String NL = getLineDelimiter(); String previousPackageName = null; StringBuffer result = new StringBuffer(); for (String importName : getImports()) { String packageName = getPackageName(importName); if (previousPackageName != null && !previousPackageName.equals(packageName)) { result.append(NL); } previousPackageName = packageName; result.append(NL + "import " + importName + ";"); } return result.toString(); }
/** * Registers a pseudo-import for the given qualified name. * A psuedo-import reserves the mapping from short name to qualified name, just like an ordinary import, but does not * actually include the import declarations among those returned by {@link #computeSortedImports()} or emitted by * {@link #emitSortedImports()}. * Note that all pseudo-imports must be added before any other ordinary imports. * @param qualifiedName the qualified name of the type to import, which may end with <code>".*"</code> for a wildcard import. * @see #computeSortedImports() * @see #emitSortedImports() */ public void addPseudoImport(String qualifiedName) { String importName = getImportName(qualifiedName); String shortName = getShortName(importName); if (shortName.equals("*")) { String packageName = getPackageName(importName); importedPackages.add(packageName); } else { String oldImportName = shortNameToImportMap.put(shortName, importName); if (oldImportName != null) { imports.remove(oldImportName); } } }
/** * Registers an import for the given qualified name. * @param qualifiedName the qualified name of the type to import, which may end with <code>".*"</code> for a wildcard import. */ public void addImport(String qualifiedName) { String importName = getImportName(qualifiedName); basicAddImport(getPackageName(importName), getShortName(importName), importName); }
else if (importedPackages.contains(getPackageName(importName)) && (javaLangImports == null || !javaLangImports.contains(baseName)))