Class ImportStatements
java.lang.Object
com.google.errorprone.apply.ImportStatements
Represents a list of import statements. Supports adding and removing import statements and pretty
printing the result as source code. Sorts and organizes the imports using the given
importOrganizer
.- Author:
- eaftan@google.com (Eddie Aftandilian)
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Add an import to the list of imports.boolean
addAll
(Collection<String> importsToAdd) Add all imports in a collection to this list of imports.static ImportStatements
create
(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit) static ImportStatements
create
(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit, ImportOrganizer importOrganizer) int
Return the end position of the import statements.int
Return the start position of the import statements.boolean
boolean
Remove an import from the list of imports.boolean
removeAll
(Collection<String> importsToRemove) Removes all imports in a collection to this list of imports.toString()
Returns a string representation of the imports as Java code in correct order.
-
Method Details
-
create
public static ImportStatements create(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit) -
create
public static ImportStatements create(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit, ImportOrganizer importOrganizer) -
getStartPos
public int getStartPos()Return the start position of the import statements. -
getEndPos
public int getEndPos()Return the end position of the import statements. -
add
Add an import to the list of imports. If the import is already in the list, does nothing. The import should be of the form "import foo.bar".- Parameters:
importToAdd
- a string representation of the import to add- Returns:
- true if the import was added
-
addAll
Add all imports in a collection to this list of imports. Does not add any imports that are already in the list.- Parameters:
importsToAdd
- a collection of imports to add- Returns:
- true if any imports were added to the list
-
remove
Remove an import from the list of imports. If the import is not in the list, does nothing. The import should be of the form "import foo.bar".- Parameters:
importToRemove
- a string representation of the import to remove- Returns:
- true if the import was removed
-
removeAll
Removes all imports in a collection to this list of imports. Does not remove any imports that are not in the list.- Parameters:
importsToRemove
- a collection of imports to remove- Returns:
- true if any imports were removed from the list
-
importsHaveChanged
public boolean importsHaveChanged() -
toString
-