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 TypeMethodDescriptionbooleanAdd an import to the list of imports.booleanaddAll(Collection<String> importsToAdd) Add all imports in a collection to this list of imports.static ImportStatementscreate(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit) static ImportStatementscreate(com.sun.tools.javac.tree.JCTree.JCCompilationUnit compilationUnit, ImportOrganizer importOrganizer) intReturn the end position of the import statements.intReturn the start position of the import statements.booleanbooleanRemove an import from the list of imports.booleanremoveAll(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
-