Class CreateCompilationUnitOperation
java.lang.Object
org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
org.aspectj.org.eclipse.jdt.internal.core.CreateCompilationUnitOperation
- All Implemented Interfaces:
org.eclipse.core.resources.IWorkspaceRunnable
,org.eclipse.core.runtime.ICoreRunnable
,org.eclipse.core.runtime.IProgressMonitor
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:
- The package fragment in which to create the compilation unit.
- The name of the compilation unit.
Do not include the
".java"
suffix (ex."Object"
- the".java"
will be added for the name of the compilation unit.)
-
Nested Class Summary
Nested classes/interfaces inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
JavaModelOperation.IPostAction
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
The name of the compilation unit being created.protected String
The source code to use when creating the 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
Fields inherited from interface org.eclipse.core.runtime.IProgressMonitor
UNKNOWN
-
Constructor Summary
ConstructorDescriptionCreateCompilationUnitOperation(IPackageFragment parentElement, String name, String source, boolean force)
When executed, this operation will create a compilation unit with the given name. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Creates a compilation unit.protected ICompilationUnit
protected org.eclipse.core.runtime.jobs.ISchedulingRule
verify()
Possible failures: NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation isnull
.Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaModelOperation
addAction, addDelta, addReconcileDelta, applyTextEdit, beginTask, canModifyRoots, checkCanceled, commonVerify, copyResources, createFile, createFolder, deleteEmptyPackageFragment, deleteResource, deleteResources, done, equalsOneOf, executeNestedOperation, firstActionWithID, getAttribute, getCompilationUnitFor, getCurrentOperationStack, getDocument, getElementToProcess, getJavaModel, getLatestASTLevel, 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
Methods inherited from interface org.eclipse.core.runtime.IProgressMonitor
clearBlocked, setBlocked, slice
-
Field Details
-
name
The name of the compilation unit being created. -
source
The source code to use when creating the element.
-
-
Constructor Details
-
CreateCompilationUnitOperation
public CreateCompilationUnitOperation(IPackageFragment parentElement, String name, String source, boolean force)When executed, this operation will create a compilation unit with the given name. The name should have the ".java" suffix.
-
-
Method Details
-
executeOperation
Creates a compilation unit.- Specified by:
executeOperation
in classJavaModelOperation
- Throws:
JavaModelException
- if unable to create the compilation unit.
-
getCompilationUnit
-
getSchedulingRule
protected org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()- Overrides:
getSchedulingRule
in classJavaModelOperation
-
verify
Possible failures:- NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
null
. - INVALID_NAME - the compilation unit name provided to the operation
is
null
or has an invalid syntax - INVALID_CONTENTS - the source specified for the compiliation unit is null
- Overrides:
verify
in classJavaModelOperation
- See Also:
IJavaModelStatus
- NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
-