Class OrganizeImportsOperation
java.lang.Object
org.eclipse.jdt.core.manipulation.OrganizeImportsOperation
- All Implemented Interfaces:
IWorkspaceRunnable, ICoreRunnable
- Since:
- 1.10
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionOrganizeImportsOperation(ICompilationUnit cu, CompilationUnit astRoot, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, OrganizeImportsOperation.IChooseImportQuery chooseImportQuery) Creates a new OrganizeImportsOperation operation.OrganizeImportsOperation(ICompilationUnit cu, CompilationUnit astRoot, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, OrganizeImportsOperation.IChooseImportQuery chooseImportQuery, boolean restoreExistingImports) Creates a new OrganizeImportsOperation operation. -
Method Summary
Modifier and TypeMethodDescriptioncreateTextEdit(IProgressMonitor m, Map<ICompilationUnit, Set<String>> requiredModules) Creates import edits.createTextEdits(IProgressMonitor monitor) Creates edits for the source file and its existing module descriptor.intintAfter executing the operation, returnsnullif the operation has been executed successfully or the range where parsing failed.voidrun(IProgressMonitor monitor) Runs the operation.
-
Constructor Details
-
OrganizeImportsOperation
public OrganizeImportsOperation(ICompilationUnit cu, CompilationUnit astRoot, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, OrganizeImportsOperation.IChooseImportQuery chooseImportQuery) Creates a new OrganizeImportsOperation operation.- Parameters:
cu- The compilation unitastRoot- the compilation unit AST nodeignoreLowerCaseNames- when true, type names starting with a lower case are ignoredsave- If set, the result will be savedallowSyntaxErrors- If set, the operation will only proceed when the compilation unit has no syntax errorschooseImportQuery- Query element to be used for UI interaction ornullto not select anything
-
OrganizeImportsOperation
public OrganizeImportsOperation(ICompilationUnit cu, CompilationUnit astRoot, boolean ignoreLowerCaseNames, boolean save, boolean allowSyntaxErrors, OrganizeImportsOperation.IChooseImportQuery chooseImportQuery, boolean restoreExistingImports) Creates a new OrganizeImportsOperation operation.- Parameters:
cu- The compilation unitastRoot- the compilation unit AST nodeignoreLowerCaseNames- when true, type names starting with a lower case are ignoredsave- If set, the result will be savedallowSyntaxErrors- If set, the operation will only proceed when the compilation unit has no syntax errorschooseImportQuery- Query element to be used for UI interaction ornullto not select anythingrestoreExistingImports- when true, the operation will restore existing imports- Since:
- 1.17
-
-
Method Details
-
run
Runs the operation.- Specified by:
runin interfaceICoreRunnable- Specified by:
runin interfaceIWorkspaceRunnable- Parameters:
monitor- the progress monitor- Throws:
CoreException- thrown when the operation failedOperationCanceledException- Runtime error thrown when operation is canceled.
-
createTextEdit
-
createTextEdit
public TextEdit createTextEdit(IProgressMonitor m, Map<ICompilationUnit, Set<String>> requiredModules) throws CoreException, OperationCanceledException Creates import edits. If supplied,requiredModulescollects missing dependencies by module descriptor so callers can combine them across source files.- Parameters:
m- the progress monitor, ornullrequiredModules- the dependency accumulator, ornullto calculate only imports- Returns:
- the import edits, or
nullif parsing prevents organizing imports - Throws:
CoreException- if calculating the edits failsOperationCanceledException- if the operation is canceled- Since:
- 1.26
-
createTextEdits
public Map<ICompilationUnit, TextEdit> createTextEdits(IProgressMonitor monitor) throws CoreException, OperationCanceledException Creates edits for the source file and its existing module descriptor. For several source files, usecreateTextEdit(IProgressMonitor, Map)to collect their dependencies before creating one change per descriptor.- Parameters:
monitor- the progress monitor, ornull- Returns:
- the edits, or an empty map if parsing prevents organizing imports
- Throws:
CoreException- if creating the edits failsOperationCanceledException- if the operation is canceled- Since:
- 1.26
-
getParseError
After executing the operation, returnsnullif the operation has been executed successfully or the range where parsing failed.- Returns:
- returns the parse error
-
getNumberOfImportsAdded
public int getNumberOfImportsAdded()- Returns:
- Returns the number of import statements added for this operation
-
getNumberOfImportsRemoved
public int getNumberOfImportsRemoved()- Returns:
- Returns the number of import statements removed for this operation
-
getScheduleRule
- Returns:
- Returns the scheduling rule for this operation
-