Class CreateElementInCUOperation
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
org.aspectj.org.eclipse.jdt.internal.core.CreateElementInCUOperation
- All Implemented Interfaces:
org.eclipse.core.resources.IWorkspaceRunnable
,org.eclipse.core.runtime.ICoreRunnable
,org.eclipse.core.runtime.IProgressMonitor
- Direct Known Subclasses:
CreateImportOperation
,CreatePackageDeclarationOperation
,CreateTypeMemberOperation
This abstract class implements behavior common to CreateElementInCUOperations
.
To create a compilation unit, or an element contained in a compilation unit, the
source code for the entire compilation unit is updated and saved.
The element being created can be positioned relative to an existing
element in the compilation unit via the methods #createAfter
and #createBefore
. By default, the new element is positioned
as the last child of its parent element.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
JavaModelOperation.IPostAction
-
Field Summary
Modifier and TypeFieldDescriptionprotected IJavaElement
The element that the newly created element is positioned relative to, as described byfInsertPosition
, ornull
if the newly created element will be positioned last.protected boolean
A flag indicating whether creation of a new element occurred.protected CompilationUnit
The compilation unit AST used for this operationprotected static int
A constant meaning to position the new element after the element defined byfAnchorElement
.protected static int
A constant meaning to position the new element before the element defined byfAnchorElement
.protected static int
A constant meaning to position the new element as the last child of its parent element.protected int
One of the position constants, describing where to position the newly created element.Fields inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
actions, 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
Fields inherited from interface org.eclipse.core.runtime.IProgressMonitor
UNKNOWN
-
Constructor Summary
ConstructorDescriptionCreateElementInCUOperation(IJavaElement parentElement)
Constructs an operation that creates a Java Language Element with the specified parent, contained within a compilation unit. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Only allow cancelling if this operation is not nested.void
createAfter(IJavaElement sibling)
Instructs this operation to position the new element after the given sibling, or to add the new element as the last child of its parent ifnull
.void
createBefore(IJavaElement sibling)
Instructs this operation to position the new element before the given sibling, or to add the new element as the last child of its parent ifnull
.protected void
Execute the operation - generate new source for the compilation unit and save the results.protected abstract ASTNode
generateElementAST(ASTRewrite rewriter, ICompilationUnit cu)
protected void
protected abstract IJavaElement
Creates and returns the handle for the element this operation created.protected IJavaElement[]
Creates and returns the handles for the elements this operation created.protected abstract StructuralPropertyDescriptor
getChildPropertyDescriptor(ASTNode parent)
protected ICompilationUnit
Returns the compilation unit in which the new element is being created.protected int
Returns the amount of work for the main task of this operation for progress reporting.abstract String
Returns the name of the main task of this operation for progress reporting.protected org.eclipse.core.runtime.jobs.ISchedulingRule
protected void
Sets the default position in which to create the new type member.protected void
insertASTNode(ASTRewrite rewriter, ASTNode parent, ASTNode child)
Inserts the given child into the given AST, based on the position settings of this operation.protected CompilationUnit
parse(ICompilationUnit cu)
protected void
setAlteredName(String newName)
Sets the name of theDOMNode
that will be used to create this new element.protected void
setRelativePosition(IJavaElement sibling, int policy)
Instructs this operation to position the new element relative to the given sibling, or to add the new element as the last child of its parent ifnull
.verify()
Possible failures: NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation isnull
.Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
addAction, addDelta, addReconcileDelta, applyTextEdit, beginTask, canModifyRoots, commonVerify, copyResources, createFile, createFolder, deleteEmptyPackageFragment, deleteResource, deleteResources, done, equalsOneOf, executeNestedOperation, firstActionWithID, getAttribute, getCompilationUnitFor, getCurrentOperationStack, getDocument, getElementToProcess, getJavaModel, getLatestASTLevel, 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, worked
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.core.runtime.IProgressMonitor
clearBlocked, setBlocked, slice
-
Field Details
-
cuAST
The compilation unit AST used for this operation -
INSERT_LAST
protected static final int INSERT_LASTA constant meaning to position the new element as the last child of its parent element.- See Also:
- Constant Field Values
-
INSERT_AFTER
protected static final int INSERT_AFTERA constant meaning to position the new element after the element defined byfAnchorElement
.- See Also:
- Constant Field Values
-
INSERT_BEFORE
protected static final int INSERT_BEFOREA constant meaning to position the new element before the element defined byfAnchorElement
.- See Also:
- Constant Field Values
-
insertionPolicy
protected int insertionPolicyOne of the position constants, describing where to position the newly created element. -
anchorElement
The element that the newly created element is positioned relative to, as described byfInsertPosition
, ornull
if the newly created element will be positioned last. -
creationOccurred
protected boolean creationOccurredA flag indicating whether creation of a new element occurred. A request for creating a duplicate element would request in this flag being set tofalse
. Ensures that no deltas are generated when creation does not occur.
-
-
Constructor Details
-
CreateElementInCUOperation
Constructs an operation that creates a Java Language Element with the specified parent, contained within a compilation unit.
-
-
Method Details
-
checkCanceled
protected void checkCanceled()Only allow cancelling if this operation is not nested.- Overrides:
checkCanceled
in classJavaModelOperation
- See Also:
IProgressMonitor.isCanceled()
-
createAfter
Instructs this operation to position the new element after the given sibling, or to add the new element as the last child of its parent ifnull
. -
createBefore
Instructs this operation to position the new element before the given sibling, or to add the new element as the last child of its parent ifnull
. -
executeOperation
Execute the operation - generate new source for the compilation unit and save the results.- Specified by:
executeOperation
in classJavaModelOperation
- Throws:
JavaModelException
- if the operation is unable to complete
-
getChildPropertyDescriptor
-
generateElementAST
protected abstract ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu) throws JavaModelException- Throws:
JavaModelException
-
generateNewCompilationUnitAST
- Throws:
JavaModelException
-
generateResultHandle
Creates and returns the handle for the element this operation created. -
generateResultHandles
Creates and returns the handles for the elements this operation created. -
getCompilationUnit
Returns the compilation unit in which the new element is being created. -
getMainAmountOfWork
protected int getMainAmountOfWork()Returns the amount of work for the main task of this operation for progress reporting. -
getMainTaskName
Returns the name of the main task of this operation for progress reporting. -
getSchedulingRule
protected org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()- Overrides:
getSchedulingRule
in classJavaModelOperation
-
initializeDefaultPosition
protected void initializeDefaultPosition()Sets the default position in which to create the new type member. Operations that require a different default position must override this method. -
insertASTNode
protected void insertASTNode(ASTRewrite rewriter, ASTNode parent, ASTNode child) throws JavaModelExceptionInserts the given child into the given AST, based on the position settings of this operation.- Throws:
JavaModelException
- See Also:
createAfter(IJavaElement)
,createBefore(IJavaElement)
-
parse
- Throws:
JavaModelException
-
setAlteredName
Sets the name of theDOMNode
that will be used to create this new element. Used by theCopyElementsOperation
for renaming. Only used forCreateTypeMemberOperation
-
setRelativePosition
protected void setRelativePosition(IJavaElement sibling, int policy) throws IllegalArgumentExceptionInstructs this operation to position the new element relative to the given sibling, or to add the new element as the last child of its parent ifnull
. Theposition
must be one of the position constants.- Throws:
IllegalArgumentException
-
verify
Possible failures:- NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is
null
. - INVALID_NAME - no name, a name was null or not a valid import declaration name.
- INVALID_SIBLING - the sibling provided for positioning is not valid.
- Overrides:
verify
in classJavaModelOperation
- See Also:
IJavaModelStatus
,JavaConventions
- NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is
-