org.aspectj.org.eclipse.jdt.internal.core
Class CreateElementInCUOperation

java.lang.Object
  extended by org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
      extended by org.aspectj.org.eclipse.jdt.internal.core.CreateElementInCUOperation
Direct Known Subclasses:
CreateImportOperation, CreatePackageDeclarationOperation, CreateTypeMemberOperation

public abstract class CreateElementInCUOperation
extends JavaModelOperation

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
protected  IJavaElement anchorElement
          The element that the newly created element is positioned relative to, as described by fInsertPosition, or null if the newly created element will be positioned last.
protected  boolean creationOccurred
          A flag indicating whether creation of a new element occurred.
protected  CompilationUnit cuAST
          The compilation unit AST used for this operation
protected static int INSERT_AFTER
          A constant meaning to position the new element after the element defined by fAnchorElement.
protected static int INSERT_BEFORE
          A constant meaning to position the new element before the element defined by fAnchorElement.
protected static int INSERT_LAST
          A constant meaning to position the new element as the last child of its parent element.
protected  int insertionPolicy
          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
 
Constructor Summary
CreateElementInCUOperation(IJavaElement parentElement)
          Constructs an operation that creates a Java Language Element with the specified parent, contained within a compilation unit.
 
Method Summary
protected  void checkCanceled()
          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 if null.
 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 if null.
protected  void executeOperation()
          Execute the operation - generate new source for the compilation unit and save the results.
protected abstract  ASTNode generateElementAST(ASTRewrite rewriter, ICompilationUnit cu)
           
protected  void generateNewCompilationUnitAST(ICompilationUnit cu)
           
protected abstract  IJavaElement generateResultHandle()
          Creates and returns the handle for the element this operation created.
protected  IJavaElement[] generateResultHandles()
          Creates and returns the handles for the elements this operation created.
protected abstract  StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent)
           
protected  ICompilationUnit getCompilationUnit()
          Returns the compilation unit in which the new element is being created.
protected  int getMainAmountOfWork()
          Returns the amount of work for the main task of this operation for progress reporting.
abstract  java.lang.String getMainTaskName()
          Returns the name of the main task of this operation for progress reporting.
protected  ISchedulingRule getSchedulingRule()
           
protected  void initializeDefaultPosition()
          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(java.lang.String newName)
          Sets the name of the DOMNode 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 if null.
 IJavaModelStatus verify()
          Possible failures: NO_ELEMENTS_TO_PROCESS - the compilation unit supplied to the operation is null.
 
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, 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
 

Field Detail

cuAST

protected CompilationUnit cuAST
The compilation unit AST used for this operation


INSERT_LAST

protected static final int INSERT_LAST
A 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_AFTER
A constant meaning to position the new element after the element defined by fAnchorElement.

See Also:
Constant Field Values

INSERT_BEFORE

protected static final int INSERT_BEFORE
A constant meaning to position the new element before the element defined by fAnchorElement.

See Also:
Constant Field Values

insertionPolicy

protected int insertionPolicy
One of the position constants, describing where to position the newly created element.


anchorElement

protected IJavaElement anchorElement
The element that the newly created element is positioned relative to, as described by fInsertPosition, or null if the newly created element will be positioned last.


creationOccurred

protected boolean creationOccurred
A flag indicating whether creation of a new element occurred. A request for creating a duplicate element would request in this flag being set to false. Ensures that no deltas are generated when creation does not occur.

Constructor Detail

CreateElementInCUOperation

public CreateElementInCUOperation(IJavaElement parentElement)
Constructs an operation that creates a Java Language Element with the specified parent, contained within a compilation unit.

Method Detail

checkCanceled

protected void checkCanceled()
Only allow cancelling if this operation is not nested.

Overrides:
checkCanceled in class JavaModelOperation
See Also:
IProgressMonitor#isCanceled

createAfter

public 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 if null.


createBefore

public 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 if null.


executeOperation

protected void executeOperation()
                         throws JavaModelException
Execute the operation - generate new source for the compilation unit and save the results.

Specified by:
executeOperation in class JavaModelOperation
Throws:
JavaModelException - if the operation is unable to complete

getChildPropertyDescriptor

protected abstract StructuralPropertyDescriptor getChildPropertyDescriptor(ASTNode parent)

generateElementAST

protected abstract ASTNode generateElementAST(ASTRewrite rewriter,
                                              ICompilationUnit cu)
                                       throws JavaModelException
Throws:
JavaModelException

generateNewCompilationUnitAST

protected void generateNewCompilationUnitAST(ICompilationUnit cu)
                                      throws JavaModelException
Throws:
JavaModelException

generateResultHandle

protected abstract IJavaElement generateResultHandle()
Creates and returns the handle for the element this operation created.


generateResultHandles

protected IJavaElement[] generateResultHandles()
Creates and returns the handles for the elements this operation created.


getCompilationUnit

protected ICompilationUnit 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

public abstract java.lang.String getMainTaskName()
Returns the name of the main task of this operation for progress reporting.


getSchedulingRule

protected ISchedulingRule getSchedulingRule()
Overrides:
getSchedulingRule in class JavaModelOperation

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 JavaModelException
Inserts the given child into the given AST, based on the position settings of this operation.

Throws:
JavaModelException
See Also:
createAfter(IJavaElement), createBefore(IJavaElement)

parse

protected CompilationUnit parse(ICompilationUnit cu)
                         throws JavaModelException
Throws:
JavaModelException

setAlteredName

protected void setAlteredName(java.lang.String newName)
Sets the name of the DOMNode that will be used to create this new element. Used by the CopyElementsOperation for renaming. Only used for CreateTypeMemberOperation


setRelativePosition

protected void setRelativePosition(IJavaElement sibling,
                                   int policy)
                            throws java.lang.IllegalArgumentException
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 if null. The position must be one of the position constants.

Throws:
java.lang.IllegalArgumentException

verify

public IJavaModelStatus verify()
Possible failures:

Overrides:
verify in class JavaModelOperation
See Also:
IJavaModelStatus, JavaConventions