Class CopyElementsOperation
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
org.aspectj.org.eclipse.jdt.internal.core.MultiOperation
org.aspectj.org.eclipse.jdt.internal.core.CopyElementsOperation
- All Implemented Interfaces:
SuffixConstants, org.eclipse.core.resources.IWorkspaceRunnable, org.eclipse.core.runtime.ICoreRunnable, org.eclipse.core.runtime.IProgressMonitor
- Direct Known Subclasses:
MoveElementsOperation
This operation copies/moves a collection of elements from their current
container to a new container, optionally renaming the
elements.
Notes:
- If there is already an element with the same name in the new container, the operation either overwrites or aborts, depending on the collision policy setting. The default setting is abort.
- When constructors are copied to a type, the constructors are automatically renamed to the name of the destination type.
- When main types are renamed (move within the same parent), the compilation unit and constructors are automatically renamed
- The collection of elements being copied must all share the same type of container (for example, must all be type members).
- The elements are inserted in the new container in the order given.
- The elements can be positioned in the new container - see #setInsertBefore. By default, the elements are inserted based on the default positions as specified in the creation operation for that element type.
- This operation can be used to copy and rename elements within the same container.
- This operation only copies elements contained within compilation units.
-
Nested Class Summary
Nested classes/interfaces inherited from class JavaModelOperation
JavaModelOperation.IPostAction -
Field Summary
Fields inherited from class MultiOperation
insertBeforeElements, newParents, renamings, renamingsListModifier and TypeFieldDescriptionprotected MapTable specifying insertion positions for elements being copied/moved/renamed.protected MapTable specifying the new parent for elements being copied/moved/renamed.protected MapThis table presents the data infRenamingListin a more convenient way.protected String[]The list of renamings supplied to the operationFields inherited from class 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, TRUEModifier and TypeFieldDescriptionprotected JavaModelOperation.IPostAction[]protected intprotected intprotected static final intprotected HashMapprotected IJavaElement[]The elements this operation operates on, ornullif this operation does not operate on specific elements.protected booleanConflict resolution policy - by default do not force (fail on a conflict).static final Stringprotected booleanA flag indicating whether this operation is nested.protected static final intprotected static final IJavaElement[]An empty collection ofIJavaElements - the common empty result if no elements are created, or if this operation is not actually executed.protected static final ThreadLocalprotected IJavaElement[]The parent elements this operation operates with ornullif this operation does not operate with specific parent elements.protected static booleanorg.eclipse.core.runtime.SubMonitorThe progress monitor passed into this operationprotected static final intprotected IJavaElement[]The elements created by this operation - empty until the operation actually creates elements.static final StringFields inherited from interface org.eclipse.core.runtime.IProgressMonitor
UNKNOWNFields inherited from interface SuffixConstants
EXTENSION_aj, EXTENSION_AJ, EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, EXTENSION_jmod, EXTENSION_JMOD, SUFFIX_aj, SUFFIX_AJ, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_aj, SUFFIX_STRING_AJ, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVAModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final char[]static final char[]static final char[]static final char[]static final char[]static final char[]static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionCopyElementsOperation(IJavaElement[] elementsToCopy, IJavaElement[] destContainers, boolean force) When executed, this operation will copy the given elements to the given containers.CopyElementsOperation(IJavaElement[] elementsToCopy, IJavaElement destContainer, boolean force) When executed, this operation will copy the given elements to the given container. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns theStringto use as the main task name for progress monitoring.protected JavaModelOperationgetNestedOperation(IJavaElement element) Returns the nested operation to use for processing this elementprotected booleanisRenamingMainType(IJavaElement element, IJavaElement dest) Returnstrueif this element is the main type of its compilation unit.protected voidprocessElement(IJavaElement element) Copy/move the element from the source to destination, renaming the elements as specified, honoring the collision policy.protected IJavaModelStatusverify()Possible failures: NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation does not match the number of elements that were supplied.protected voidverify(IJavaElement element) This method is called for eachIJavaElementbeforeprocessElement.Methods inherited from class MultiOperation
error, executeOperation, getDestinationParent, getNewNameFor, isMove, isRename, processElements, setInsertBefore, setRenamings, verifyDestination, verifyRenaming, verifySiblingModifier and TypeMethodDescriptionprotected voiderror(int code, IJavaElement element) Convenience method to create aJavaModelExceptionembending aJavaModelStatus.protected voidExecutes the operation.protected IJavaElementgetDestinationParent(IJavaElement child) Returns the parent of the element being copied/moved/renamed.protected StringgetNewNameFor(IJavaElement element) Returns the new name forelement, ornullif there are no renamings specified.protected booleanisMove()Returnstrueif this operation represents a move or rename,falseif this operation represents a copy.
Note: a rename is just a move within the same parent with a name change.protected booleanisRename()Returnstrueif this operation represents a rename,falseif this operation represents a copy or move.protected voidProcesses all theIJavaElements in turn, collecting errors and updating the progress monitor.voidsetInsertBefore(IJavaElement modifiedElement, IJavaElement newSibling) Sets the insertion position in the new container for the modified element.voidsetRenamings(String[] renamingsList) Sets the new names to use for each element being copied.protected voidverifyDestination(IJavaElement element, IJavaElement destination) Verifies that thedestinationspecified for theelementis valid for the types of theelementanddestination.protected voidverifyRenaming(IJavaElement element) Verify that the new name specified forelementis valid for that type of Java element.protected voidverifySibling(IJavaElement element, IJavaElement destination) Verifies that the positioning sibling specified for theelementis exists and its parent is the destination container of thiselement.Methods inherited from class JavaModelOperation
addAction, addDelta, addReconcileDelta, applyTextEdit, beginTask, canModifyRoots, checkCanceled, commonVerify, copyResources, createFile, createFolder, deleteEmptyPackageFragment, deleteResource, deleteResources, done, equalsOneOf, executeNestedOperation, firstActionWithID, getAttribute, getCompilationUnitFor, getCurrentOperationStack, getDocument, getElementToProcess, getJavaModel, getLatestASTLevel, getNestedFolders, getParentElement, getParentElements, getResultElements, getSchedulingRule, getSubProgressMonitor, hasModifiedResource, internalWorked, isCanceled, isReadOnly, isTopLevelOperation, moveResources, newJavaElementDelta, popOperation, postAction, prefixesOneOf, pushOperation, removeAllPostAction, removeReconcileDelta, run, runOperation, runPostActions, setAttribute, setCanceled, setNested, setTaskName, subTask, workedModifier and TypeMethodDescriptionprotected voidprotected voidaddDelta(IJavaElementDelta delta) protected voidaddReconcileDelta(ICompilationUnit workingCopy, IJavaElementDelta delta) protected voidapplyTextEdit(ICompilationUnit cu, org.eclipse.text.edits.TextEdit edits) voidprotected booleanprotected voidChecks with the progress monitor to see whether this operation should be canceled.protected IJavaModelStatusCommon code used to verify the elements this operation is processing.protected voidcopyResources(org.eclipse.core.resources.IResource[] resources, org.eclipse.core.runtime.IPath container) Convenience method to copy resourcesprotected voidcreateFile(org.eclipse.core.resources.IContainer folder, String name, byte[] contents, boolean forceFlag) Convenience method to create a fileprotected voidcreateFolder(org.eclipse.core.resources.IContainer parentFolder, String name, boolean forceFlag) Convenience method to create a folderprotected voiddeleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, org.eclipse.core.resources.IResource rootResource) Convenience method to delete an empty package fragmentprotected voiddeleteResource(org.eclipse.core.resources.IResource resource, int flags) Convenience method to delete a resourceprotected voiddeleteResources(org.eclipse.core.resources.IResource[] resources, boolean forceFlag) Convenience method to delete resourcesvoiddone()protected booleanequalsOneOf(org.eclipse.core.runtime.IPath path, org.eclipse.core.runtime.IPath[] otherPaths) voidexecuteNestedOperation(JavaModelOperation operation, int subWorkAmount) Convenience method to run an operation within this operationprotected intfirstActionWithID(String id, int start) protected static ObjectgetAttribute(Object key) protected ICompilationUnitgetCompilationUnitFor(IJavaElement element) Returns the compilation unit the given element is contained in, or the element itself (if it is a compilation unit), otherwisenull.protected static ArrayListprotected org.eclipse.jface.text.IDocumentprotected IJavaElementReturns the element to which this operation applies, ornullif not applicable.Returns the Java Model this operation is operating in.protected intprotected org.eclipse.core.runtime.IPath[]protected IJavaElementReturns the parent element to which this operation applies, ornullif not applicable.protected IJavaElement[]Returns the parent elements to which this operation applies, ornullif not applicable.Returns the elements created by this operation.protected org.eclipse.core.runtime.jobs.ISchedulingRuleprotected org.eclipse.core.runtime.IProgressMonitorgetSubProgressMonitor(int workAmount) Creates and returns a subprogress monitor if appropriate.booleanReturns whether this operation has performed any resource modifications.voidinternalWorked(double work) booleanbooleanReturnstrueif this operation performs no resource modifications, otherwisefalse.protected booleanprotected voidmoveResources(org.eclipse.core.resources.IResource[] resources, org.eclipse.core.runtime.IPath container) Convenience method to move resourcesCreates and returns a newIJavaElementDeltaon the Java Model.protected JavaModelOperationprotected voidpostAction(JavaModelOperation.IPostAction action, int insertionMode) protected booleanprefixesOneOf(org.eclipse.core.runtime.IPath path, org.eclipse.core.runtime.IPath[] otherPaths) protected voidpushOperation(JavaModelOperation operation) protected voidremoveAllPostAction(String actionID) protected voidremoveReconcileDelta(ICompilationUnit workingCopy) voidrun(org.eclipse.core.runtime.IProgressMonitor monitor) Runs this operation and registers any deltas created.voidrunOperation(org.eclipse.core.runtime.IProgressMonitor monitor) Main entry point for Java Model operations.protected voidprotected static voidsetAttribute(Object key, Object attribute) voidsetCanceled(boolean b) protected voidsetNested(boolean nested) Sets whether this operation is nested or not.voidsetTaskName(String name) voidvoidworked(int work) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.core.runtime.IProgressMonitor
clearBlocked, setBlocked, slice
-
Constructor Details
-
CopyElementsOperation
public CopyElementsOperation(IJavaElement[] elementsToCopy, IJavaElement[] destContainers, boolean force) When executed, this operation will copy the given elements to the given containers. The elements and destination containers must be in the correct order. If there is > 1 destination, the number of destinations must be the same as the number of elements being copied/moved/renamed. -
CopyElementsOperation
public CopyElementsOperation(IJavaElement[] elementsToCopy, IJavaElement destContainer, boolean force) When executed, this operation will copy the given elements to the given container.
-
-
Method Details
-
getMainTaskName
Returns theStringto use as the main task name for progress monitoring.- Specified by:
getMainTaskNamein classMultiOperation
-
getNestedOperation
Returns the nested operation to use for processing this element -
isRenamingMainType
protected boolean isRenamingMainType(IJavaElement element, IJavaElement dest) throws JavaModelException Returnstrueif this element is the main type of its compilation unit.- Throws:
JavaModelException
-
processElement
Copy/move the element from the source to destination, renaming the elements as specified, honoring the collision policy.- Specified by:
processElementin classMultiOperation- Throws:
JavaModelException- if the operation is unable to be completed
-
verify
Possible failures:- NO_ELEMENTS_TO_PROCESS - no elements supplied to the operation
- INDEX_OUT_OF_BOUNDS - the number of renamings supplied to the operation does not match the number of elements that were supplied.
- Overrides:
verifyin classJavaModelOperation- See Also:
-
verify
Description copied from class:MultiOperationThis method is called for eachIJavaElementbeforeprocessElement. It should check that thiselementcan be processed.- Specified by:
verifyin classMultiOperation- Throws:
JavaModelException- See Also:
-