The {@link ImportRewrite} helps updating imports following a import order and on-demand imports threshold as configured by a project.
The import rewrite is created on a compilation unit and collects references to types that are added or removed. When adding imports, e.g. using {@link #addImport(String)}, the import rewrite evaluates if the type can be imported and returns the a reference to the type that can be used in code. This reference is either unqualified if the import could be added, or fully qualified if the import failed due to a conflict with another element of the same name.
On {@link #rewriteImports(IProgressMonitor)} the rewrite translates these descriptions intotext edits that can then be applied to the original source. The rewrite infrastructure tries to generate minimal text changes and only works on the import statements. It is possible to combine the result of an import rewrite with the result of a {@link org.eclipse.jdt.core.dom.rewrite.ASTRewrite}as long as no import statements are modified by the AST rewrite.
The options controlling the import order and on-demand thresholds are:
- {@link #setImportOrder(String[])} specifies the import groups and their preferred order
- {@link #setOnDemandImportThreshold(int)} specifies the number of imports in a group needed for a on-demand import statement (star import)
- {@link #setStaticOnDemandImportThreshold(int)} specifies the number of static imports in a group needed for a on-demand import statement (star import)
This class is not intended to be subclassed.
@since 3.2