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
FieldsModifier and TypeFieldDescriptionprotected StringThe name of the compilation unit being created.protected StringThe 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, TRUEFields inherited from interface org.eclipse.core.runtime.IProgressMonitor
UNKNOWN -
Constructor Summary
ConstructorsConstructorDescriptionCreateCompilationUnitOperation(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 voidCreates a compilation unit.protected ICompilationUnitprotected org.eclipse.core.runtime.jobs.ISchedulingRuleverify()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, workedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
executeOperationin classJavaModelOperation- Throws:
JavaModelException- if unable to create the compilation unit.
-
getCompilationUnit
- See Also:
-
getSchedulingRule
protected org.eclipse.core.runtime.jobs.ISchedulingRule getSchedulingRule()- Overrides:
getSchedulingRulein 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
nullor has an invalid syntax - INVALID_CONTENTS - the source specified for the compiliation unit is null
- Overrides:
verifyin classJavaModelOperation- See Also:
- NO_ELEMENTS_TO_PROCESS - the package fragment supplied to the operation is
-