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 // deltaProcessor.initializeRoots();
388 // executeOperation();
390 // throw new JavaModelException(status);
395 * Convenience method to run an operation within this operation
397 public void executeNestedOperation(JavaModelOperation operation, int subWorkAmount) throws JavaModelException {
398 IProgressMonitor subProgressMonitor = getSubProgressMonitor(subWorkAmount);
399 // fix for 1FW7IKC, part (1)
401 operation.setNested(true);
402 operation.run(subProgressMonitor);
403 } catch (CoreException ce) {
404 if (ce instanceof JavaModelException) {
405 throw (JavaModelException)ce;
407 // translate the core exception to a java model exception
408 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
409 Throwable e = ce.getStatus().getException();
410 if (e instanceof JavaModelException) {
411 throw (JavaModelException) e;
414 throw new JavaModelException(ce);
419 * Performs the operation specific behavior. Subclasses must override.
421 protected abstract void executeOperation() throws JavaModelException;
423 * Returns the attribute registered at the given key with the top level operation.
424 * Returns null if no such attribute is found.
426 protected Object getAttribute(Object key) {
427 ArrayList stack = this.getCurrentOperationStack();
428 if (stack.size() == 0) return null;
429 JavaModelOperation topLevelOp = (JavaModelOperation)stack.get(0);
430 if (topLevelOp.attributes == null) {
433 return topLevelOp.attributes.get(key);
437 * Returns the compilation unit the given element is contained in,
438 * or the element itself (if it is a compilation unit),
439 * otherwise <code>null</code>.
441 protected ICompilationUnit getCompilationUnitFor(IJavaElement element) {
443 return ((JavaElement)element).getCompilationUnit();
446 * Returns the stack of operations running in the current thread.
447 * Returns an empty stack if no operations are currently running in this thread.
449 protected ArrayList getCurrentOperationStack() {
450 ArrayList stack = (ArrayList)operationStacks.getCurrent();
452 stack = new ArrayList();
453 operationStacks.setCurrent(stack);
458 * Returns the elements to which this operation applies,
459 * or <code>null</code> if not applicable.
461 protected IJavaElement[] getElementsToProcess() {
462 return fElementsToProcess;
465 * Returns the element to which this operation applies,
466 * or <code>null</code> if not applicable.
468 protected IJavaElement getElementToProcess() {
469 if (fElementsToProcess == null || fElementsToProcess.length == 0) {
472 return fElementsToProcess[0];
475 * Returns the Java Model this operation is operating in.
477 public IJavaModel getJavaModel() {
478 if (fElementsToProcess == null || fElementsToProcess.length == 0) {
479 return getParentElement().getJavaModel();
481 return fElementsToProcess[0].getJavaModel();
484 // protected IPath[] getNestedFolders(IPackageFragmentRoot root) throws JavaModelException {
485 // IPath rootPath = root.getPath();
486 // IClasspathEntry[] classpath = root.getJavaProject().getRawClasspath();
487 // int length = classpath.length;
488 // IPath[] result = new IPath[length];
490 // for (int i = 0; i < length; i++) {
491 // IPath path = classpath[i].getPath();
492 // if (rootPath.isPrefixOf(path) && !rootPath.equals(path)) {
493 // result[index++] = path;
496 // if (index < length) {
497 // System.arraycopy(result, 0, result = new IPath[index], 0, index);
502 * Returns the parent element to which this operation applies,
503 * or <code>null</code> if not applicable.
505 protected IJavaElement getParentElement() {
506 if (fParentElements == null || fParentElements.length == 0) {
509 return fParentElements[0];
512 * Returns the parent elements to which this operation applies,
513 * or <code>null</code> if not applicable.
515 protected IJavaElement[] getParentElements() {
516 return fParentElements;
519 * Returns the elements created by this operation.
521 public IJavaElement[] getResultElements() {
522 return resultElements;
525 * Returns the scheduling rule for this operation (i.e. the resource that needs to be locked
526 * while this operation is running.
527 * Subclasses can override.
529 protected ISchedulingRule getSchedulingRule() {
530 return ResourcesPlugin.getWorkspace().getRoot();
533 * Creates and returns a subprogress monitor if appropriate.
535 protected IProgressMonitor getSubProgressMonitor(int workAmount) {
536 IProgressMonitor sub = null;
537 if (progressMonitor != null) {
538 sub = new SubProgressMonitor(progressMonitor, workAmount, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
544 * Returns whether this operation has performed any resource modifications.
545 * Returns false if this operation has not been executed yet.
547 public boolean hasModifiedResource() {
548 return !this.isReadOnly() && this.getAttribute(HAS_MODIFIED_RESOURCE_ATTR) == TRUE;
550 public void internalWorked(double work) {
551 if (progressMonitor != null) {
552 progressMonitor.internalWorked(work);
556 * @see IProgressMonitor
558 public boolean isCanceled() {
559 if (progressMonitor != null) {
560 return progressMonitor.isCanceled();
565 * Returns <code>true</code> if this operation performs no resource modifications,
566 * otherwise <code>false</code>. Subclasses must override.
568 public boolean isReadOnly() {
572 * Returns whether this operation is the first operation to run in the current thread.
574 protected boolean isTopLevelOperation() {
577 (stack = this.getCurrentOperationStack()).size() > 0
578 && stack.get(0) == this;
581 * Returns the index of the first registered action with the given id, starting from a given position.
582 * Returns -1 if not found.
584 protected int firstActionWithID(String id, int start) {
585 for (int i = start; i <= this.actionsEnd; i++) {
586 if (this.actions[i].getID().equals(id)) {
594 * Convenience method to move resources
596 protected void moveResources(IResource[] resources, IPath destinationPath) throws JavaModelException {
597 IProgressMonitor subProgressMonitor = null;
598 if (progressMonitor != null) {
599 subProgressMonitor = new SubProgressMonitor(progressMonitor, resources.length, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
601 IWorkspace workspace = resources[0].getWorkspace();
603 workspace.move(resources, destinationPath, false, subProgressMonitor);
604 this.setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
605 } catch (CoreException e) {
606 throw new JavaModelException(e);
610 * Creates and returns a new <code>IJavaElementDelta</code>
613 public JavaElementDelta newJavaElementDelta() {
614 return new JavaElementDelta(getJavaModel());
617 * Removes the last pushed operation from the stack of running operations.
618 * Returns the poped operation or null if the stack was empty.
620 protected JavaModelOperation popOperation() {
621 ArrayList stack = getCurrentOperationStack();
622 int size = stack.size();
624 if (size == 1) { // top level operation
625 operationStacks.setCurrent(null); // release reference (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=33927)
627 return (JavaModelOperation)stack.remove(size-1);
633 * Registers the given action to be run when the outer most java model operation has finished.
634 * The insertion mode controls whether:
635 * - the action should discard all existing actions with the same id, and be queued at the end (REMOVEALL_APPEND),
636 * - the action should be ignored if there is already an action with the same id (KEEP_EXISTING),
637 * - the action should be queued at the end without looking at existing actions (APPEND)
639 protected void postAction(IPostAction action, int insertionMode) {
640 if (POST_ACTION_VERBOSE) {
641 System.out.print("(" + Thread.currentThread() + ") [JavaModelOperation.postAction(IPostAction, int)] Posting action " + action.getID()); //$NON-NLS-1$ //$NON-NLS-2$
642 switch(insertionMode) {
643 case REMOVEALL_APPEND:
644 System.out.println(" (REMOVEALL_APPEND)"); //$NON-NLS-1$
647 System.out.println(" (KEEP_EXISTING)"); //$NON-NLS-1$
650 System.out.println(" (APPEND)"); //$NON-NLS-1$
655 JavaModelOperation topLevelOp = (JavaModelOperation)getCurrentOperationStack().get(0);
656 IPostAction[] postActions = topLevelOp.actions;
657 if (postActions == null) {
658 topLevelOp.actions = postActions = new IPostAction[1];
659 postActions[0] = action;
660 topLevelOp.actionsEnd = 0;
662 String id = action.getID();
663 switch (insertionMode) {
664 case REMOVEALL_APPEND :
665 int index = this.actionsStart-1;
666 while ((index = topLevelOp.firstActionWithID(id, index+1)) >= 0) {
667 // remove action[index]
668 System.arraycopy(postActions, index+1, postActions, index, topLevelOp.actionsEnd - index);
669 postActions[topLevelOp.actionsEnd--] = null;
671 topLevelOp.addAction(action);
674 if (topLevelOp.firstActionWithID(id, 0) < 0) {
675 topLevelOp.addAction(action);
679 topLevelOp.addAction(action);
685 * Returns whether the given path is the prefix of one of the given other paths.
687 protected boolean prefixesOneOf(IPath path, IPath[] otherPaths) {
688 for (int i = 0, length = otherPaths.length; i < length; i++) {
689 if (path.isPrefixOf(otherPaths[i])) {
696 * Pushes the given operation on the stack of operations currently running in this thread.
698 protected void pushOperation(JavaModelOperation operation) {
699 getCurrentOperationStack().add(operation);
703 * Main entry point for Java Model operations. Executes this operation
704 * and registers any deltas created.
706 * @see IWorkspaceRunnable
707 * @exception CoreException if the operation fails
709 public void run(IProgressMonitor monitor) throws CoreException {
710 JavaModelManager manager = JavaModelManager.getJavaModelManager();
711 DeltaProcessor deltaProcessor = manager.getDeltaProcessor();
712 int previousDeltaCount = deltaProcessor.javaModelDeltas.size();
714 progressMonitor = monitor;
717 // computes the root infos before executing the operation
718 // noop if aready initialized
719 JavaModelManager.getJavaModelManager().deltaState.initializeRoots();
723 if (this.isTopLevelOperation()) {
724 this.runPostActions();
730 // TODO jsurfer temp-del
731 // update JavaModel using deltas that were recorded during this operation
732 // for (int i = previousDeltaCount, size = manager.javaModelDeltas.size(); i < size; i++) {
733 // manager.updateJavaModel((IJavaElementDelta)manager.javaModelDeltas.get(i));
737 // - the operation is a top level operation
738 // - the operation did produce some delta(s)
739 // - but the operation has not modified any resource
740 if (this.isTopLevelOperation()) {
741 if ((manager.javaModelDeltas.size() > previousDeltaCount || !manager.reconcileDeltas.isEmpty())
742 && !this.hasModifiedResource()) {
743 manager.fire(null, JavaModelManager.DEFAULT_CHANGE_EVENT);
744 } // else deltas are fired while processing the resource delta
752 * Main entry point for Java Model operations. Runs a Java Model Operation as an IWorkspaceRunnable
755 public void runOperation(IProgressMonitor monitor) throws JavaModelException {
756 IJavaModelStatus status= verify();
757 if (!status.isOK()) {
758 throw new JavaModelException(status);
764 // Use IWorkspace.run(...) to ensure that a build will be done in autobuild mode.
765 // Note that if the tree is locked, this will throw a CoreException, but this is ok
766 // as this operation is modifying the tree (not read-only) and a CoreException will be thrown anyway.
767 ResourcesPlugin.getWorkspace().run(this, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
769 } catch (CoreException ce) {
770 if (ce instanceof JavaModelException) {
771 throw (JavaModelException)ce;
773 if (ce.getStatus().getCode() == IResourceStatus.OPERATION_FAILED) {
774 Throwable e= ce.getStatus().getException();
775 if (e instanceof JavaModelException) {
776 throw (JavaModelException) e;
779 throw new JavaModelException(ce);
783 protected void runPostActions() throws JavaModelException {
784 while (this.actionsStart <= this.actionsEnd) {
785 IPostAction postAction = this.actions[this.actionsStart++];
786 if (POST_ACTION_VERBOSE) {
787 System.out.println("(" + Thread.currentThread() + ") [JavaModelOperation.runPostActions()] Running action " + postAction.getID()); //$NON-NLS-1$ //$NON-NLS-2$
793 * Registers the given attribute at the given key with the top level operation.
795 protected void setAttribute(Object key, Object attribute) {
796 JavaModelOperation topLevelOp = (JavaModelOperation)this.getCurrentOperationStack().get(0);
797 if (topLevelOp.attributes == null) {
798 topLevelOp.attributes = new HashMap();
800 topLevelOp.attributes.put(key, attribute);
803 * @see IProgressMonitor
805 public void setCanceled(boolean b) {
806 if (progressMonitor != null) {
807 progressMonitor.setCanceled(b);
811 * Sets whether this operation is nested or not.
812 * @see CreateElementInCUOperation#checkCanceled
814 protected void setNested(boolean nested) {
818 * @see IProgressMonitor
820 public void setTaskName(String name) {
821 if (progressMonitor != null) {
822 progressMonitor.setTaskName(name);
826 * @see IProgressMonitor
828 public void subTask(String name) {
829 if (progressMonitor != null) {
830 progressMonitor.subTask(name);
834 * Returns a status indicating if there is any known reason
835 * this operation will fail. Operations are verified before they
838 * Subclasses must override if they have any conditions to verify
839 * before this operation executes.
841 * @see IJavaModelStatus
843 protected IJavaModelStatus verify() {
844 return commonVerify();
848 * @see IProgressMonitor
850 public void worked(int work) {
851 if (progressMonitor != null) {
852 progressMonitor.worked(work);