Class JavaModelOperation

java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
All Implemented Interfaces:
org.eclipse.core.resources.IWorkspaceRunnable, org.eclipse.core.runtime.ICoreRunnable, org.eclipse.core.runtime.IProgressMonitor
Direct Known Subclasses:
BatchOperation, BecomeWorkingCopyOperation, ChangeClasspathOperation, CommitWorkingCopyOperation, CopyPackageFragmentRootOperation, CreateCompilationUnitOperation, CreateElementInCUOperation, CreatePackageFragmentOperation, CreateTypeHierarchyOperation, DeletePackageFragmentRootOperation, DiscardWorkingCopyOperation, MultiOperation, ReconcileWorkingCopyOperation, SortElementsOperation

public abstract class JavaModelOperation extends Object implements org.eclipse.core.resources.IWorkspaceRunnable, org.eclipse.core.runtime.IProgressMonitor
Defines behavior common to all Java Model operations
  • Field Details

    • APPEND

      protected static final int APPEND
      See Also:
      Constant Field Values
    • REMOVEALL_APPEND

      protected static final int REMOVEALL_APPEND
      See Also:
      Constant Field Values
    • KEEP_EXISTING

      protected static final int KEEP_EXISTING
      See Also:
      Constant Field Values
    • POST_ACTION_VERBOSE

      protected static boolean POST_ACTION_VERBOSE
    • actions

      protected JavaModelOperation.IPostAction[] actions
    • actionsStart

      protected int actionsStart
    • actionsEnd

      protected int actionsEnd
    • attributes

      protected HashMap attributes
    • HAS_MODIFIED_RESOURCE_ATTR

      public static final String HAS_MODIFIED_RESOURCE_ATTR
      See Also:
      Constant Field Values
    • TRUE

      public static final String TRUE
      See Also:
      Constant Field Values
    • elementsToProcess

      protected IJavaElement[] elementsToProcess
      The elements this operation operates on, or null if this operation does not operate on specific elements.
    • parentElements

      protected IJavaElement[] parentElements
      The parent elements this operation operates with or null if this operation does not operate with specific parent elements.
    • NO_ELEMENTS

      protected static final IJavaElement[] NO_ELEMENTS
      An empty collection of IJavaElements - the common empty result if no elements are created, or if this operation is not actually executed.
    • resultElements

      protected IJavaElement[] resultElements
      The elements created by this operation - empty until the operation actually creates elements.
    • progressMonitor

      public org.eclipse.core.runtime.SubMonitor progressMonitor
      The progress monitor passed into this operation
    • isNested

      protected boolean isNested
      A flag indicating whether this operation is nested.
    • force

      protected boolean force
      Conflict resolution policy - by default do not force (fail on a conflict).
    • OPERATION_STACKS

      protected static final ThreadLocal OPERATION_STACKS
  • Constructor Details

    • JavaModelOperation

      protected JavaModelOperation()
    • JavaModelOperation

      protected JavaModelOperation(IJavaElement[] elements)
      A common constructor for all Java Model operations.
    • JavaModelOperation

      protected JavaModelOperation(IJavaElement[] elementsToProcess, IJavaElement[] parentElements)
      Common constructor for all Java Model operations.
    • JavaModelOperation

      protected JavaModelOperation(IJavaElement[] elementsToProcess, IJavaElement[] parentElements, boolean force)
      A common constructor for all Java Model operations.
    • JavaModelOperation

      protected JavaModelOperation(IJavaElement[] elements, boolean force)
      A common constructor for all Java Model operations.
    • JavaModelOperation

      protected JavaModelOperation(IJavaElement element)
      Common constructor for all Java Model operations.
  • Method Details

    • getLatestASTLevel

      protected int getLatestASTLevel()
    • addAction

      protected void addAction(JavaModelOperation.IPostAction action)
    • addDelta

      protected void addDelta(IJavaElementDelta delta)
    • addReconcileDelta

      protected void addReconcileDelta(ICompilationUnit workingCopy, IJavaElementDelta delta)
    • removeReconcileDelta

      protected void removeReconcileDelta(ICompilationUnit workingCopy)
    • applyTextEdit

      protected void applyTextEdit(ICompilationUnit cu, org.eclipse.text.edits.TextEdit edits) throws JavaModelException
      Throws:
      JavaModelException
    • beginTask

      public void beginTask(String name, int totalWork)
      Specified by:
      beginTask in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • canModifyRoots

      protected boolean canModifyRoots()
    • checkCanceled

      protected void checkCanceled()
      Checks with the progress monitor to see whether this operation should be canceled. An operation should regularly call this method during its operation so that the user can cancel it.
      Throws:
      org.eclipse.core.runtime.OperationCanceledException - if cancelling the operation has been requested
      See Also:
      IProgressMonitor.isCanceled()
    • commonVerify

      protected IJavaModelStatus commonVerify()
      Common code used to verify the elements this operation is processing.
      See Also:
      verify()
    • copyResources

      protected void copyResources(org.eclipse.core.resources.IResource[] resources, org.eclipse.core.runtime.IPath container) throws JavaModelException
      Convenience method to copy resources
      Throws:
      JavaModelException
    • createFile

      protected void createFile(org.eclipse.core.resources.IContainer folder, String name, InputStream contents, boolean forceFlag) throws JavaModelException
      Convenience method to create a file
      Throws:
      JavaModelException
    • createFolder

      protected void createFolder(org.eclipse.core.resources.IContainer parentFolder, String name, boolean forceFlag) throws JavaModelException
      Convenience method to create a folder
      Throws:
      JavaModelException
    • deleteEmptyPackageFragment

      protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, org.eclipse.core.resources.IResource rootResource) throws JavaModelException
      Convenience method to delete an empty package fragment
      Throws:
      JavaModelException
    • deleteResource

      protected void deleteResource(org.eclipse.core.resources.IResource resource, int flags) throws JavaModelException
      Convenience method to delete a resource
      Throws:
      JavaModelException
    • deleteResources

      protected void deleteResources(org.eclipse.core.resources.IResource[] resources, boolean forceFlag) throws JavaModelException
      Convenience method to delete resources
      Throws:
      JavaModelException
    • done

      public void done()
      Specified by:
      done in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • equalsOneOf

      protected boolean equalsOneOf(org.eclipse.core.runtime.IPath path, org.eclipse.core.runtime.IPath[] otherPaths)
    • executeNestedOperation

      public void executeNestedOperation(JavaModelOperation operation, int subWorkAmount) throws JavaModelException
      Convenience method to run an operation within this operation
      Throws:
      JavaModelException
    • executeOperation

      protected abstract void executeOperation() throws JavaModelException
      Performs the operation specific behavior. Subclasses must override.
      Throws:
      JavaModelException
    • getAttribute

      protected static Object getAttribute(Object key)
    • getCompilationUnitFor

      protected ICompilationUnit getCompilationUnitFor(IJavaElement element)
      Returns the compilation unit the given element is contained in, or the element itself (if it is a compilation unit), otherwise null.
    • getCurrentOperationStack

      protected static ArrayList getCurrentOperationStack()
    • getDocument

      protected org.eclipse.jface.text.IDocument getDocument(ICompilationUnit cu) throws JavaModelException
      Throws:
      JavaModelException
    • getElementToProcess

      protected IJavaElement getElementToProcess()
      Returns the element to which this operation applies, or null if not applicable.
    • getJavaModel

      public IJavaModel getJavaModel()
      Returns the Java Model this operation is operating in.
    • getNestedFolders

      protected org.eclipse.core.runtime.IPath[] getNestedFolders(IPackageFragmentRoot root) throws JavaModelException
      Throws:
      JavaModelException
    • getParentElement

      protected IJavaElement getParentElement()
      Returns the parent element to which this operation applies, or null if not applicable.
    • getParentElements

      protected IJavaElement[] getParentElements()
      Returns the parent elements to which this operation applies, or null if not applicable.
    • getResultElements

      public IJavaElement[] getResultElements()
      Returns the elements created by this operation.
    • getSchedulingRule

      protected org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()
    • getSubProgressMonitor

      protected org.eclipse.core.runtime.IProgressMonitor getSubProgressMonitor(int workAmount)
      Creates and returns a subprogress monitor if appropriate.
    • hasModifiedResource

      public boolean hasModifiedResource()
      Returns whether this operation has performed any resource modifications. Returns false if this operation has not been executed yet.
    • internalWorked

      public void internalWorked(double work)
      Specified by:
      internalWorked in interface org.eclipse.core.runtime.IProgressMonitor
    • isCanceled

      public boolean isCanceled()
      Specified by:
      isCanceled in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • isReadOnly

      public boolean isReadOnly()
      Returns true if this operation performs no resource modifications, otherwise false. Subclasses must override.
    • isTopLevelOperation

      protected boolean isTopLevelOperation()
    • firstActionWithID

      protected int firstActionWithID(String id, int start)
    • moveResources

      protected void moveResources(org.eclipse.core.resources.IResource[] resources, org.eclipse.core.runtime.IPath container) throws JavaModelException
      Convenience method to move resources
      Throws:
      JavaModelException
    • newJavaElementDelta

      public JavaElementDelta newJavaElementDelta()
      Creates and returns a new IJavaElementDelta on the Java Model.
    • popOperation

      protected JavaModelOperation popOperation()
    • postAction

      protected void postAction(JavaModelOperation.IPostAction action, int insertionMode)
    • prefixesOneOf

      protected boolean prefixesOneOf(org.eclipse.core.runtime.IPath path, org.eclipse.core.runtime.IPath[] otherPaths)
    • pushOperation

      protected void pushOperation(JavaModelOperation operation)
    • removeAllPostAction

      protected void removeAllPostAction(String actionID)
    • run

      public void run(org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
      Runs this operation and registers any deltas created.
      Specified by:
      run in interface org.eclipse.core.runtime.ICoreRunnable
      Specified by:
      run in interface org.eclipse.core.resources.IWorkspaceRunnable
      Throws:
      org.eclipse.core.runtime.CoreException - if the operation fails
      See Also:
      IWorkspaceRunnable
    • runOperation

      public void runOperation(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Main entry point for Java Model operations. Runs a Java Model Operation as an IWorkspaceRunnable if not read-only.
      Throws:
      JavaModelException
    • runPostActions

      protected void runPostActions() throws JavaModelException
      Throws:
      JavaModelException
    • setAttribute

      protected static void setAttribute(Object key, Object attribute)
    • setCanceled

      public void setCanceled(boolean b)
      Specified by:
      setCanceled in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • setNested

      protected void setNested(boolean nested)
      Sets whether this operation is nested or not.
      See Also:
      CreateElementInCUOperation.checkCanceled()
    • setTaskName

      public void setTaskName(String name)
      Specified by:
      setTaskName in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • subTask

      public void subTask(String name)
      Specified by:
      subTask in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor
    • verify

      protected IJavaModelStatus verify()
      Returns a status indicating if there is any known reason this operation will fail. Operations are verified before they are run. Subclasses must override if they have any conditions to verify before this operation executes.
      See Also:
      IJavaModelStatus
    • worked

      public void worked(int work)
      Specified by:
      worked in interface org.eclipse.core.runtime.IProgressMonitor
      See Also:
      IProgressMonitor