public class CreateCompilationUnitOperation extends JavaModelOperation
This operation creates a compilation unit (CU). If the CU doesn't exist yet, a new compilation unit will be created with the content provided. Otherwise the operation will override the contents of an existing CU with the new content.
Note: It is possible to create a CU automatically when creating a class or interface. Thus, the preferred method of creating a CU is to perform a create type operation rather than first creating a CU and secondly creating a type inside the CU.
Required Attributes:
".java" suffix (ex. "Object" -
the ".java" will be added for the name of the compilation unit.)
JavaModelOperation.IPostAction| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
name
The name of the compilation unit being created.
|
protected java.lang.String |
source
The source code to use when creating the element.
|
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 and Description |
|---|
CreateCompilationUnitOperation(IPackageFragment parentElement,
java.lang.String name,
java.lang.String source,
boolean force)
When executed, this operation will create a compilation unit with the given name.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
executeOperation()
Creates a compilation unit.
|
protected ICompilationUnit |
getCompilationUnit() |
protected ISchedulingRule |
getSchedulingRule() |
IJavaModelStatus |
verify()
Possible failures:
NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
null. |
addAction, addDelta, addReconcileDelta, applyTextEdit, beginTask, canModifyRoots, checkCanceled, 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, workedprotected java.lang.String name
protected java.lang.String source
public CreateCompilationUnitOperation(IPackageFragment parentElement, java.lang.String name, java.lang.String source, boolean force)
protected void executeOperation()
throws JavaModelException
executeOperation in class JavaModelOperationJavaModelException - if unable to create the compilation unit.protected ICompilationUnit getCompilationUnit()
protected ISchedulingRule getSchedulingRule()
getSchedulingRule in class JavaModelOperationpublic IJavaModelStatus verify()
null.
null or has an invalid syntax
verify in class JavaModelOperationIJavaModelStatus