Package com.google.googlejavaformat.java
Class RemoveUnusedImports
java.lang.Object
com.google.googlejavaformat.java.RemoveUnusedImports
Removes unused imports from a source file. Imports that are only used in javadoc are also
removed, and the references in javadoc are replaced with fully qualified names.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringapplyReplacements(String source, com.google.common.collect.RangeMap<Integer, String> replacements) Applies the replacements to the given source, and re-format any edited javadoc.buildReplacements(String contents, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, Set<String> usedNames, com.google.common.collect.Multimap<String, com.google.common.collect.Range<Integer>> usedInJavadoc) Construct replacements to fix unused imports.private static com.sun.tools.javac.tree.JCTree.JCFieldAccessgetQualifiedIdentifier(com.sun.tools.javac.tree.JCTree importTree) private static StringgetSimpleName(com.sun.tools.javac.tree.JCTree importTree) private static booleanisUnused(com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, Set<String> usedNames, com.google.common.collect.Multimap<String, com.google.common.collect.Range<Integer>> usedInJavadoc, com.sun.tools.javac.tree.JCTree importTree, String simpleName) private static com.sun.tools.javac.tree.JCTree.JCCompilationUnitstatic StringremoveUnusedImports(String contents)
-
Constructor Details
-
RemoveUnusedImports
public RemoveUnusedImports()
-
-
Method Details
-
removeUnusedImports
- Throws:
FormatterException
-
parse
private static com.sun.tools.javac.tree.JCTree.JCCompilationUnit parse(com.sun.tools.javac.util.Context context, String javaInput) throws FormatterException - Throws:
FormatterException
-
buildReplacements
private static com.google.common.collect.RangeMap<Integer,String> buildReplacements(String contents, com.sun.tools.javac.tree.JCTree.JCCompilationUnit unit, Set<String> usedNames, com.google.common.collect.Multimap<String, com.google.common.collect.Range<Integer>> usedInJavadoc) Construct replacements to fix unused imports. -
getSimpleName
-
isUnused
-
getQualifiedIdentifier
private static com.sun.tools.javac.tree.JCTree.JCFieldAccess getQualifiedIdentifier(com.sun.tools.javac.tree.JCTree importTree) -
applyReplacements
private static String applyReplacements(String source, com.google.common.collect.RangeMap<Integer, String> replacements) Applies the replacements to the given source, and re-format any edited javadoc.
-