1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import java.io.InputStream;
14 import java.util.ArrayList;
15 import java.util.HashMap;
17 import net.sourceforge.phpdt.core.ICompilationUnit;
18 import net.sourceforge.phpdt.core.IJavaElement;
19 import net.sourceforge.phpdt.core.IJavaElementDelta;
20 import net.sourceforge.phpdt.core.IJavaModel;
21 import net.sourceforge.phpdt.core.IJavaModelStatus;
22 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
23 import net.sourceforge.phpdt.core.IPackageFragment;
24 import net.sourceforge.phpdt.core.IWorkingCopy;
25 import net.sourceforge.phpdt.core.JavaModelException;
26 import net.sourceforge.phpdt.internal.core.util.PerThreadObject;
27 import net.sourceforge.phpdt.internal.core.util.Util;
29 import org.eclipse.core.resources.IContainer;
30 import org.eclipse.core.resources.IFile;
31 import org.eclipse.core.resources.IFolder;
32 import org.eclipse.core.resources.IResource;
33 import org.eclipse.core.resources.IResourceStatus;
34 import org.eclipse.core.resources.IWorkspace;
35 import org.eclipse.core.resources.IWorkspaceRunnable;
36 import org.eclipse.core.resources.ResourcesPlugin;
37 import org.eclipse.core.runtime.CoreException;
38 import org.eclipse.core.runtime.IPath;
39 import org.eclipse.core.runtime.IProgressMonitor;
40 import org.eclipse.core.runtime.OperationCanceledException;
41 import org.eclipse.core.runtime.Path;
42 import org.eclipse.core.runtime.SubProgressMonitor;
43 import org.eclipse.core.runtime.jobs.ISchedulingRule;
47 * Defines behavior common to all Java Model operations
49 public abstract class JavaModelOperation implements IWorkspaceRunnable, IProgressMonitor {
50 protected interface IPostAction {
52 * Returns the id of this action.
53 * @see JavaModelOperation#postAction
59 void run() throws JavaModelException;
62 * Constants controlling the insertion mode of an action.
63 * @see JavaModelOperation#postAction
65 protected static final int APPEND = 1; // insert at the end
66 protected static final int REMOVEALL_APPEND = 2; // remove all existing ones with same ID, and add new one at the end
67 protected static final int KEEP_EXISTING = 3; // do not insert if already existing with same ID
70 * Whether tracing post actions is enabled.
72 protected static boolean POST_ACTION_VERBOSE;
75 * A list of IPostActions.
77 protected IPostAction[] actions;
78 protected int actionsStart = 0;
79 protected int actionsEnd = -1;
81 * A HashMap of attributes that can be used by operations
83 protected HashMap attributes;
85 public static final String HAS_MODIFIED_RESOURCE_ATTR = "hasModifiedResource"; //$NON-NLS-1$
86 public static final String TRUE = "true"; //$NON-NLS-1$
87 //public static final String FALSE = "false"; //$NON-NLS-1$
90 * The elements this operation operates on,
91 * or <code>null</code> if this operation
92 * does not operate on specific elements.
94 protected IJavaElement[] fElementsToProcess;
96 * The parent elements this operation operates with
97 * or <code>null</code> if this operation
98 * does not operate with specific parent elements.
100 protected IJavaElement[] fParentElements;
102 * An empty collection of <code>IJavaElement</code>s - the common
103 * empty result if no elements are created, or if this
104 * operation is not actually executed.
106 protected static IJavaElement[] NO_ELEMENTS= new IJavaElement[] {};
110 * The elements created by this operation - empty
111 * until the operation actually creates elements.
113 protected IJavaElement[] resultElements= NO_ELEMENTS;
116 * The progress monitor passed into this operation
118 protected IProgressMonitor progressMonitor= null;
120 * A flag indicating whether this operation is nested.
122 protected boolean isNested = false;
124 * Conflict resolution policy - by default do not force (fail on a conflict).
126 protected boolean force= false;
129 * A per thread stack of java model operations (PerThreadObject of ArrayList).
131 protected static PerThreadObject operationStacks = new PerThreadObject();
132 protected JavaModelOperation() {
135 * A common constructor for all Java Model operations.
137 protected JavaModelOperation(IJavaElement[] elements) {
138 fElementsToProcess = elements;
141 * Common constructor for all Java Model operations.
143 protected JavaModelOperation(IJavaElement[] elementsToProcess, IJavaElement[] parentElements) {
144 fElementsToProcess = elementsToProcess;
145 fParentElements= parentElements;
148 * A common constructor for all Java Model operations.
150 protected JavaModelOperation(IJavaElement[] elementsToProcess, IJavaElement[] parentElements, boolean force) {
151 fElementsToProcess = elementsToProcess;
152 fParentElements= parentElements;
156 * A common constructor for all Java Model operations.
158 protected JavaModelOperation(IJavaElement[] elements, boolean force) {
159 fElementsToProcess = elements;
164 * Common constructor for all Java Model operations.
166 protected JavaModelOperation(IJavaElement element) {
167 fElementsToProcess = new IJavaElement[]{element};
170 * A common constructor for all Java Model operations.
172 protected JavaModelOperation(IJavaElement element, boolean force) {
173 fElementsToProcess = new IJavaElement[]{element};
178 * Registers the given action at the end of the list of actions to run.
180 protected void addAction(IPostAction action) {
181 int length = this.actions.length;
182 if (length == ++this.actionsEnd) {
183 System.arraycopy(this.actions, 0, this.actions = new IPostAction[length*2], 0, length);
185 this.actions[this.actionsEnd] = action;
188 * Registers the given delta with the Java Model Manager.
190 protected void addDelta(IJavaElementDelta delta) {
191 JavaModelManager.getJavaModelManager().registerJavaModelDelta(delta);
194 * Registers the given reconcile delta with the Java Model Manager.
196 protected void addReconcileDelta(IWorkingCopy workingCopy, IJavaElementDelta delta) {
197 HashMap reconcileDeltas = JavaModelManager.getJavaModelManager().reconcileDeltas;
198 JavaElementDelta previousDelta = (JavaElementDelta)reconcileDeltas.get(workingCopy);
199 if (previousDelta != null) {
200 IJavaElementDelta[] children = delta.getAffectedChildren();
201 for (int i = 0, length = children.length; i < length; i++) {
202 JavaElementDelta child = (JavaElementDelta)children[i];
203 previousDelta.insertDeltaTree(child.getElement(), child);
206 reconcileDeltas.put(workingCopy, delta);
210 * Deregister the reconcile delta for the given working copy
212 protected void removeReconcileDelta(IWorkingCopy workingCopy) {
213 JavaModelManager.getJavaModelManager().reconcileDeltas.remove(workingCopy);
216 * @see IProgressMonitor
218 public void beginTask(String name, int totalWork) {
219 if (progressMonitor != null) {
220 progressMonitor.beginTask(name, totalWork);
224 * Checks with the progress monitor to see whether this operation
225 * should be canceled. An operation should regularly call this method
226 * during its operation so that the user can cancel it.
228 * @exception OperationCanceledException if cancelling the operation has been requested
229 * @see IProgressMonitor#isCanceled
231 protected void checkCanceled() {
233 throw new OperationCanceledException(Util.bind("operation.cancelled")); //$NON-NLS-1$
237 * Common code used to verify the elements this operation is processing.
238 * @see JavaModelOperation#verify()
240 protected IJavaModelStatus commonVerify() {
241 if (fElementsToProcess == null || fElementsToProcess.length == 0) {
242 return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
244 for (int i = 0; i < fElementsToProcess.length; i++) {
245 if (fElementsToProcess[i] == null) {
246 return new JavaModelStatus(IJavaModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
249 return JavaModelStatus.VERIFIED_OK;
252 * Convenience method to copy resources
254 protected void copyResources(IResource[] resources, IPath destinationPath) throws JavaModelException {
255 IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length);
256 IWorkspace workspace = resources[0].getWorkspace();
258 workspace.copy(resources, destinationPath, false, subProgressMonitor);
259 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
260 } catch (CoreException e) {
261 throw new JavaModelException(e);
265 * Convenience method to create a file
267 protected void createFile(IContainer folder, String name, InputStream contents, boolean force) throws JavaModelException {
268 IFile file= folder.getFile(new Path(name));
272 force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
273 getSubProgressMonitor(1));
274 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
275 } catch (CoreException e) {
276 throw new JavaModelException(e);
280 * Convenience method to create a folder
282 protected void createFolder(IContainer parentFolder, String name, boolean force) throws JavaModelException {
283 IFolder folder= parentFolder.getFolder(new Path(name));
285 // we should use true to create the file locally. Only VCM should use tru/false
287 force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
289 getSubProgressMonitor(1));
290 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
291 } catch (CoreException e) {
292 throw new JavaModelException(e);
296 * Convenience method to delete an empty package fragment
298 protected void deleteEmptyPackageFragment(
299 IPackageFragment fragment,
301 IResource rootResource)
302 throws JavaModelException {
304 IContainer resource = (IContainer) fragment.getResource();
308 force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
309 getSubProgressMonitor(1));
310 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
311 while (resource instanceof IFolder) {
312 // deleting a package: delete the parent if it is empty (eg. deleting x.y where folder x doesn't have resources but y)
313 // without deleting the package fragment root
314 resource = resource.getParent();
315 if (!resource.equals(rootResource) && resource.members().length == 0) {
317 force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
318 getSubProgressMonitor(1));
319 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
322 } catch (CoreException e) {
323 throw new JavaModelException(e);
327 * Convenience method to delete a resource
329 protected void deleteResource(IResource resource,int flags) throws JavaModelException {
331 resource.delete(flags, getSubProgressMonitor(1));
332 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
333 } catch (CoreException e) {
334 throw new JavaModelException(e);
338 * Convenience method to delete resources
340 protected void deleteResources(IResource[] resources, boolean force) throws JavaModelException {
341 if (resources == null || resources.length == 0) return;
342 IProgressMonitor subProgressMonitor = getSubProgressMonitor(resources.length);
343 IWorkspace workspace = resources[0].getWorkspace();
347 force ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY,
349 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
350 } catch (CoreException e) {
351 throw new JavaModelException(e);
355 * @see IProgressMonitor
358 if (progressMonitor != null) {
359 progressMonitor.done();
363 * Returns whether the given path is equals to one of the given other paths.
365 protected boolean equalsOneOf(IPath path, IPath[] otherPaths) {
366 for (int i = 0, length = otherPaths.length; i < length; i++) {
367 if (path.equals(otherPaths[i])) {
374 * Verifies the operation can proceed and executes the operation.
375 * Subclasses should override <code>#verify</code> and
376 * <code>executeOperation</code> to implement the specific operation behavior.
378 * @exception JavaModelException The operation has failed.
380 // protected void execute() throws JavaModelException {
381 // IJavaModelStatus status= verify();
382 // if (status.isOK()) {
383 // // if first time here, computes the root infos before executing the operation
384 // DeltaProcessor deltaProcessor = JavaModelManager.getJavaModelManager().deltaProcessor;
385 // if (deltaProcessor.roots == null) {
386 //// TODO khartlage temp-del
387 // deltaProcessor.initializeRoots();
389 // executeOperation();
391 // throw new JavaModelException(status);
396 * Convenience method to run an operation within this operation
398 public void executeNestedOperation(JavaModelOperation operation, int subWorkAmount) throws JavaModelException {
399 IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount);
400 // fix for 1FW7IKC, part (1)
402 operation.setNested(true);
403 operation.run(subProgressMonitor);
404 } catch (CoreException ce) {
405 if (ce instanceof JavaModelException) {
406 throw (JavaModelException)ce;
408 // translate the core exception to a java model exception
409 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
410 Throwable e = ce.getStatus().getException();
411 if (e instanceof JavaModelException) {
412 throw (JavaModelException) e;
415 throw new JavaModelException(ce);
420 * Performs the operation specific behavior. Subclasses must override.
422 protected abstract void executeOperation() throws JavaModelException;
424 * Returns the attribute registered at the given key with the top level operation.
425 * Returns null if no such attribute is found.
427 protected Object getAttribute(Object key) {
428 ArrayList stack = this.getCurrentOperationStack();
429 if (stack.size() == 0) return null;
430 JavaModelOperation topLevelOp = (JavaModelOperation)stack.get(0);
431 if (topLevelOp.attributes == null) {
434 return topLevelOp.attributes.get(key);
438 * Returns the compilation unit the given element is contained in,
439 * or the element itself (if it is a compilation unit),
440 * otherwise <code>null</code>.
442 protected ICompilationUnit getCompilationUnitFor(IJavaElement element) {
444 return ((JavaElement)element).getCompilationUnit();
447 * Returns the stack of operations running in the current thread.
448 * Returns an empty stack if no operations are currently running in this thread.
450 protected ArrayList getCurrentOperationStack() {
451 ArrayList stack = (ArrayList)operationStacks.getCurrent();
453 stack = new ArrayList();
454 operationStacks.setCurrent(stack);
459 * Returns the elements to which this operation applies,
460 * or <code>null</code> if not applicable.
462 protected IJavaElement[] getElementsToProcess() {
463 return fElementsToProcess;
466 * Returns the element to which this operation applies,
467 * or <code>null</code> if not applicable.
469 protected IJavaElement getElementToProcess() {
470 if (fElementsToProcess == null || fElementsToProcess.length == 0) {
473 return fElementsToProcess[0];
476 * Returns the Java Model this operation is operating in.
478 public IJavaModel getJavaModel() {
479 if (fElementsToProcess == null || fElementsToProcess.length == 0) {
480 return getParentElement().getJavaModel();
482 return fElementsToProcess[0].getJavaModel();
485 // protected IPath[] getNestedFolders(IPackageFragmentRoot root) throws JavaModelException {
486 // IPath rootPath = root.getPath();
487 // IClasspathEntry[] classpath = root.getJavaProject().getRawClasspath();
488 // int length = classpath.length;
489 // IPath[] result = new IPath[length];
491 // for (int i = 0; i < length; i++) {
492 // IPath path = classpath[i].getPath();
493 // if (rootPath.isPrefixOf(path) && !rootPath.equals(path)) {
494 // result[index++] = path;
497 // if (index < length) {
498 // System.arraycopy(result, 0, result = new IPath[index], 0, index);
503 * Returns the parent element to which this operation applies,
504 * or <code>null</code> if not applicable.
506 protected IJavaElement getParentElement() {
507 if (fParentElements == null || fParentElements.length == 0) {
510 return fParentElements[0];
513 * Returns the parent elements to which this operation applies,
514 * or <code>null</code> if not applicable.
516 protected IJavaElement[] getParentElements() {
517 return fParentElements;
520 * Returns the elements created by this operation.
522 public IJavaElement[] getResultElements() {
523 return resultElements;
526 * Returns the scheduling rule for this operation (i.e. the resource that needs to be locked
527 * while this operation is running.
528 * Subclasses can override.
530 protected ISchedulingRule getSchedulingRule() {
531 return ResourcesPlugin.getWorkspace().getRoot();
534 * Creates and returns a subprogress monitor if appropriate.
536 protected IProgressMonitor getSubProgressMonitor(int workAmount) {
537 IProgressMonitor sub = null;
538 if (progressMonitor != null) {
539 sub = new SubProgressMonitor(progressMonitor, workAmount, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
545 * Returns whether this operation has performed any resource modifications.
546 * Returns false if this operation has not been executed yet.
548 public boolean hasModifiedResource() {
549 return !this.isReadOnly() && this.getAttribute(HAS_MODIFIED_RESOURCE_ATTR) == TRUE;
551 public void internalWorked(double work) {
552 if (progressMonitor != null) {
553 progressMonitor.internalWorked(work);
557 * @see IProgressMonitor
559 public boolean isCanceled() {
560 if (progressMonitor != null) {
561 return progressMonitor.isCanceled();
566 * Returns <code>true</code> if this operation performs no resource modifications,
567 * otherwise <code>false</code>. Subclasses must override.
569 public boolean isReadOnly() {
573 * Returns whether this operation is the first operation to run in the current thread.
575 protected boolean isTopLevelOperation() {
578 (stack = this.getCurrentOperationStack()).size() > 0
579 && stack.get(0) == this;
582 * Returns the index of the first registered action with the given id, starting from a given position.
583 * Returns -1 if not found.
585 protected int firstActionWithID(String id, int start) {
586 for (int i = start; i <= this.actionsEnd; i++) {
587 if (this.actions[i].getID().equals(id)) {
595 * Convenience method to move resources
597 protected void moveResources(IResource[] resources, IPath destinationPath) throws JavaModelException {
598 IProgressMonitor subProgressMonitor = null;
599 if (progressMonitor != null) {
600 subProgressMonitor = new SubProgressMonitor(progressMonitor, resources.length, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
602 IWorkspace workspace = resources[0].getWorkspace();
604 workspace.move(resources, destinationPath, false, subProgressMonitor);
605 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
606 } catch (CoreException e) {
607 throw new JavaModelException(e);
611 * Creates and returns a new <code>IJavaElementDelta</code>
614 public JavaElementDelta newJavaElementDelta() {
615 return new JavaElementDelta(getJavaModel());
618 * Removes the last pushed operation from the stack of running operations.
619 * Returns the poped operation or null if the stack was empty.
621 protected JavaModelOperation popOperation() {
622 ArrayList stack = getCurrentOperationStack();
623 int size = stack.size();
625 if (size == 1) { // top level operation
626 operationStacks.setCurrent(null); // release reference (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=33927)
628 return (JavaModelOperation)stack.remove(size-1);
634 * Registers the given action to be run when the outer most java model operation has finished.
635 * The insertion mode controls whether:
636 * - the action should discard all existing actions with the same id, and be queued at the end (REMOVEALL_APPEND),
637 * - the action should be ignored if there is already an action with the same id (KEEP_EXISTING),
638 * - the action should be queued at the end without looking at existing actions (APPEND)
640 protected void postAction(IPostAction action, int insertionMode) {
641 if (POST_ACTION_VERBOSE) {
642 System.out.print("(" + Thread.currentThread() + ") [JavaModelOperation.postAction(IPostAction, int)] Posting action " + action.getID()); //$NON-NLS-1$ //$NON-NLS-2$
643 switch(insertionMode) {
644 case REMOVEALL_APPEND:
645 System.out.println(" (REMOVEALL_APPEND)"); //$NON-NLS-1$
648 System.out.println(" (KEEP_EXISTING)"); //$NON-NLS-1$
651 System.out.println(" (APPEND)"); //$NON-NLS-1$
656 JavaModelOperation topLevelOp = (JavaModelOperation)getCurrentOperationStack().get(0);
657 IPostAction[] postActions = topLevelOp.actions;
658 if (postActions == null) {
659 topLevelOp.actions = postActions = new IPostAction[1];
660 postActions[0] = action;
661 topLevelOp.actionsEnd = 0;
663 String id = action.getID();
664 switch (insertionMode) {
665 case REMOVEALL_APPEND :
666 int index = this.actionsStart-1;
667 while ((index = topLevelOp.firstActionWithID(id, index+1)) >= 0) {
668 // remove action[index]
669 System.arraycopy(postActions, index+1, postActions, index, topLevelOp.actionsEnd - index);
670 postActions[topLevelOp.actionsEnd--] = null;
672 topLevelOp.addAction(action);
675 if (topLevelOp.firstActionWithID(id, 0) < 0) {
676 topLevelOp.addAction(action);
680 topLevelOp.addAction(action);
686 * Returns whether the given path is the prefix of one of the given other paths.
688 protected boolean prefixesOneOf(IPath path, IPath[] otherPaths) {
689 for (int i = 0, length = otherPaths.length; i < length; i++) {
690 if (path.isPrefixOf(otherPaths[i])) {
697 * Pushes the given operation on the stack of operations currently running in this thread.
699 protected void pushOperation(JavaModelOperation operation) {
700 getCurrentOperationStack().add(operation);
704 * Main entry point for Java Model operations. Executes this operation
705 * and registers any deltas created.
707 * @see IWorkspaceRunnable
708 * @exception CoreException if the operation fails
710 public void run(IProgressMonitor monitor) throws CoreException {
711 JavaModelManager manager = JavaModelManager.getJavaModelManager();
712 DeltaProcessor deltaProcessor = manager.getDeltaProcessor();
713 int previousDeltaCount = deltaProcessor.javaModelDeltas.size();
715 progressMonitor = monitor;
718 // computes the root infos before executing the operation
719 // noop if aready initialized
720 JavaModelManager.getJavaModelManager().deltaState.initializeRoots();
724 if (this.isTopLevelOperation()) {
725 this.runPostActions();
731 // TODO jsurfer temp-del
732 // update JavaModel using deltas that were recorded during this operation
733 // for (int i = previousDeltaCount, size = manager.javaModelDeltas.size(); i < size; i++) {
734 // manager.updateJavaModel((IJavaElementDelta)manager.javaModelDeltas.get(i));
738 // - the operation is a top level operation
739 // - the operation did produce some delta(s)
740 // - but the operation has not modified any resource
741 if (this.isTopLevelOperation()) {
742 if ((manager.javaModelDeltas.size() > previousDeltaCount || !manager.reconcileDeltas.isEmpty())
743 && !this.hasModifiedResource()) {
744 manager.fire(null, JavaModelManager.DEFAULT_CHANGE_EVENT);
745 } // else deltas are fired while processing the resource delta
753 * Main entry point for Java Model operations. Runs a Java Model Operation as an IWorkspaceRunnable
756 public void runOperation(IProgressMonitor monitor) throws JavaModelException {
757 IJavaModelStatus status= verify();
758 if (!status.isOK()) {
759 throw new JavaModelException(status);
765 // Use IWorkspace.run(...) to ensure that a build will be done in autobuild mode.
766 // Note that if the tree is locked, this will throw a CoreException, but this is ok
767 // as this operation is modifying the tree (not read-only) and a CoreException will be thrown anyway.
768 ResourcesPlugin.getWorkspace().run(this, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
770 } catch (CoreException ce) {
771 if (ce instanceof JavaModelException) {
772 throw (JavaModelException)ce;
774 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
775 Throwable e= ce.getStatus().getException();
776 if (e instanceof JavaModelException) {
777 throw (JavaModelException) e;
780 throw new JavaModelException(ce);
784 protected void runPostActions() throws JavaModelException {
785 while (this.actionsStart <= this.actionsEnd) {
786 IPostAction postAction = this.actions[this.actionsStart++];
787 if (POST_ACTION_VERBOSE) {
788 System.out.println("(" + Thread.currentThread() + ") [JavaModelOperation.runPostActions()] Running action " + postAction.getID()); //$NON-NLS-1$ //$NON-NLS-2$
794 * Registers the given attribute at the given key with the top level operation.
796 protected void setAttribute(Object key, Object attribute) {
797 JavaModelOperation topLevelOp = (JavaModelOperation)this.getCurrentOperationStack().get(0);
798 if (topLevelOp.attributes == null) {
799 topLevelOp.attributes = new HashMap();
801 topLevelOp.attributes.put(key, attribute);
804 * @see IProgressMonitor
806 public void setCanceled(boolean b) {
807 if (progressMonitor != null) {
808 progressMonitor.setCanceled(b);
812 * Sets whether this operation is nested or not.
813 * @see CreateElementInCUOperation#checkCanceled
815 protected void setNested(boolean nested) {
819 * @see IProgressMonitor
821 public void setTaskName(String name) {
822 if (progressMonitor != null) {
823 progressMonitor.setTaskName(name);
827 * @see IProgressMonitor
829 public void subTask(String name) {
830 if (progressMonitor != null) {
831 progressMonitor.subTask(name);
835 * Returns a status indicating if there is any known reason
836 * this operation will fail. Operations are verified before they
839 * Subclasses must override if they have any conditions to verify
840 * before this operation executes.
842 * @see IJavaModelStatus
844 protected IJavaModelStatus verify() {
845 return commonVerify();
849 * @see IProgressMonitor
851 public void worked(int work) {
852 if (progressMonitor != null) {
853 progressMonitor.worked(work);