public class CreateImportOperation extends CreateElementInCUOperation
This operation adds an import declaration to an existing compilation unit.
If the compilation unit already includes the specified import declaration,
the import is not generated (it does not generate duplicates).
Note that it is valid to specify both a single-type import and an on-demand import
for the same package, for example "java.io.File" and
"java.io.*", in which case both are preserved since the semantics
of this are not the same as just importing "java.io.*".
Importing "java.lang.*", or the package in which the compilation unit
is defined, are not treated as special cases. If they are specified, they are
included in the result.
Required Attributes:
"java.io.File" or "java.awt.*"
JavaModelOperation.IPostAction| Modifier and Type | Field and Description |
|---|---|
protected int |
flags |
protected java.lang.String |
importName |
anchorElement, creationOccurred, cuAST, INSERT_AFTER, INSERT_BEFORE, INSERT_LAST, insertionPolicyactions, actionsEnd, actionsStart, APPEND, attributes, elementsToProcess, force, HAS_MODIFIED_RESOURCE_ATTR, isNested, KEEP_EXISTING, NO_ELEMENTS, OPERATION_STACKS, parentElements, POST_ACTION_VERBOSE, progressMonitor, REMOVEALL_APPEND, resultElements, TRUE| Constructor and Description |
|---|
CreateImportOperation(java.lang.String importName,
ICompilationUnit parentElement,
int flags)
When executed, this operation will add an import to the given compilation unit.
|
| Modifier and Type | Method and Description |
|---|---|
protected ASTNode |
generateElementAST(ASTRewrite rewriter,
ICompilationUnit cu) |
protected IJavaElement |
generateResultHandle()
Creates and returns the handle for the element this operation created.
|
protected StructuralPropertyDescriptor |
getChildPropertyDescriptor(ASTNode parent) |
java.lang.String |
getMainTaskName()
Returns the name of the main task of this operation for
progress reporting.
|
protected void |
initializeDefaultPosition()
Sets the correct position for the new import:
after the last import
if no imports, before the first type
if no type, after the package statement
and if no package statement - first thing in the CU
|
IJavaModelStatus |
verify()
Possible failures:
NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is
null. |
checkCanceled, createAfter, createBefore, executeOperation, generateNewCompilationUnitAST, generateResultHandles, getCompilationUnit, getMainAmountOfWork, getSchedulingRule, insertASTNode, parse, setAlteredName, setRelativePositionaddAction, addDelta, addReconcileDelta, applyTextEdit, beginTask, canModifyRoots, commonVerify, copyResources, createFile, createFolder, deleteEmptyPackageFragment, deleteResource, deleteResources, done, equalsOneOf, executeNestedOperation, firstActionWithID, getAttribute, getCompilationUnitFor, getCurrentOperationStack, getDocument, getElementToProcess, getJavaModel, getNestedFolders, getParentElement, getParentElements, getResultElements, getSubProgressMonitor, hasModifiedResource, internalWorked, isCanceled, isReadOnly, isTopLevelOperation, moveResources, newJavaElementDelta, popOperation, postAction, prefixesOneOf, pushOperation, removeAllPostAction, removeReconcileDelta, run, runOperation, runPostActions, setAttribute, setCanceled, setNested, setTaskName, subTask, workedpublic CreateImportOperation(java.lang.String importName,
ICompilationUnit parentElement,
int flags)
protected StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent)
getChildPropertyDescriptor in class CreateElementInCUOperationprotected ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException
generateElementAST in class CreateElementInCUOperationJavaModelExceptionprotected IJavaElement generateResultHandle()
CreateElementInCUOperationgenerateResultHandle in class CreateElementInCUOperationCreateElementInCUOperation.generateResultHandle()public java.lang.String getMainTaskName()
CreateElementInCUOperationgetMainTaskName in class CreateElementInCUOperationCreateElementInCUOperation.getMainTaskName()protected void initializeDefaultPosition()
initializeDefaultPosition in class CreateElementInCUOperationpublic IJavaModelStatus verify()
null.
verify in class CreateElementInCUOperationIJavaModelStatus,
JavaConventions