Schnittstelle ICompilationUnit
- Alle Superschnittstellen:
org.eclipse.core.runtime.IAdaptable
,ICodeAssist
,IJavaElement
,IOpenable
,IParent
,ISourceManipulation
,ISourceReference
,ITypeRoot
,IWorkingCopy
- Alle bekannten Implementierungsklassen:
AssistCompilationUnit
,ClassFileWorkingCopy
,CompilationUnit
Java-like extensions
).
Compilation unit elements need to be opened before they can be navigated or manipulated.
The children are of type IPackageDeclaration
,
IImportContainer
, and IType
,
and appear in the order in which they are declared in the source.
If a source file cannot be parsed, its structure remains unknown.
Use IJavaElement.isStructureKnown()
to determine whether this is
the case.-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final int
Constant indicating that a reconcile operation should enable the bindings recoverystatic final int
Constant indicating that a reconcile operation should enable the statements recovery.static final int
Constant indicating that a reconcile operation should recompute the problems even if the source hasn't changed.static final int
Constant indicating that a reconcile operation could ignore to parse the method bodies.static final int
Constant indicating that a reconcile operation should not return an AST.Von Schnittstelle geerbte Felder org.aspectj.org.eclipse.jdt.core.IJavaElement
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_MODULE, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungorg.eclipse.text.edits.UndoEdit
applyTextEdit
(org.eclipse.text.edits.TextEdit edit, org.eclipse.core.runtime.IProgressMonitor monitor) Applies a text edit to the compilation unit's buffer.void
becomeWorkingCopy
(IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) Veraltet.void
becomeWorkingCopy
(org.eclipse.core.runtime.IProgressMonitor monitor) Changes this compilation unit handle into a working copy.void
commitWorkingCopy
(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) Commits the contents of this working copy to its underlying resource.createImport
(String name, IJavaElement sibling, int flags, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns an import declaration in this compilation unit with the given name.createImport
(String name, IJavaElement sibling, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns an non-static import declaration in this compilation unit with the given name.createPackageDeclaration
(String name, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns a package declaration in this compilation unit with the given package name.createType
(String contents, IJavaElement sibling, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns a type in this compilation unit with the given contents.void
Changes this compilation unit in working copy mode back to its original mode.findElements
(IJavaElement element) Finds the elements in this compilation unit that correspond to the given element.findWorkingCopy
(WorkingCopyOwner owner) Finds the working copy for this compilation unit, given aWorkingCopyOwner
.IType[]
Returns all types declared in this compilation unit in the order in which they appear in the source.Returns the table of the current custom options for this ICompilationUnit.Returns the first import declaration in this compilation unit with the given name.Returns the import container for this compilation unit.Returns the import declarations in this compilation unit in the order in which they appear in the source.getOptions
(boolean inheritJavaCoreOptions) Returns the table of the options for this ICompilationUnit, which includes its custom options and options inherited from its parent JavaProject.getOwner()
Returnsnull
if thisICompilationUnit
is the primary working copy, or thisICompilationUnit
is not a working copy, otherwise theWorkingCopyOwner
getPackageDeclaration
(String name) Returns the first package declaration in this compilation unit with the given package name (there normally is at most one package declaration).Returns the package declarations in this compilation unit in the order in which they appear in the source.Returns the primary compilation unit (whose owner is the primary owner) this working copy was created from, or this compilation unit if this a primary compilation unit.Returns the top-level type declared in this compilation unit with the given simple type name.IType[]
getTypes()
Returns the top-level types declared in this compilation unit in the order in which they appear in the source.getWorkingCopy
(WorkingCopyOwner owner, IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) Veraltet.getWorkingCopy
(org.eclipse.core.runtime.IProgressMonitor monitor) Returns a new working copy of this compilation unit if it is a primary compilation unit, or this compilation unit if it is already a non-primary working copy.boolean
Returns whether the resource of this working copy has changed since the inception of this working copy.boolean
Returns whether this element is a working copy.reconcile
(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.reconcile
(int astLevel, boolean forceProblemDetection, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.reconcile
(int astLevel, int reconcileFlags, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.void
restore()
Restores the contents of this working copy to the current contents of this working copy's original element.default void
setOptions
(Map<String, String> newOptions) Sets the ICompilationUnit custom options.Von Schnittstelle geerbte Methoden org.eclipse.core.runtime.IAdaptable
getAdapter
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.ICodeAssist
codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelect, codeSelect
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IJavaElement
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementName, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IOpenable
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IParent
getChildren, hasChildren
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.ISourceManipulation
copy, delete, move, rename
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.ISourceReference
exists, getNameRange, getSource, getSourceRange
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.ITypeRoot
findPrimaryType, getElementAt, getModule, getWorkingCopy
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IWorkingCopy
commit, destroy, findPrimaryType, findSharedWorkingCopy, getOriginal, getOriginalElement, getSharedWorkingCopy, getWorkingCopy, getWorkingCopy, isBasedOn, reconcile, reconcile
-
Felddetails
-
NO_AST
static final int NO_ASTConstant indicating that a reconcile operation should not return an AST.- Seit:
- 3.0
- Siehe auch:
-
FORCE_PROBLEM_DETECTION
static final int FORCE_PROBLEM_DETECTIONConstant indicating that a reconcile operation should recompute the problems even if the source hasn't changed.- Seit:
- 3.3
- Siehe auch:
-
ENABLE_STATEMENTS_RECOVERY
static final int ENABLE_STATEMENTS_RECOVERYConstant indicating that a reconcile operation should enable the statements recovery.- Seit:
- 3.3
- Siehe auch:
-
ENABLE_BINDINGS_RECOVERY
static final int ENABLE_BINDINGS_RECOVERYConstant indicating that a reconcile operation should enable the bindings recovery- Seit:
- 3.3
- Siehe auch:
-
IGNORE_METHOD_BODIES
static final int IGNORE_METHOD_BODIESConstant indicating that a reconcile operation could ignore to parse the method bodies.- Seit:
- 3.5.2
- Siehe auch:
-
-
Methodendetails
-
applyTextEdit
org.eclipse.text.edits.UndoEdit applyTextEdit(org.eclipse.text.edits.TextEdit edit, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Applies a text edit to the compilation unit's buffer.Note that the edit is simply applied to the compilation unit's buffer. In particular the undo edit is not grouped with previous undo edits if the buffer doesn't implement
IBuffer.ITextEditCapability
. If it does, the exact semantics for grouping undo edit depends on howIBuffer.ITextEditCapability.applyTextEdit(TextEdit, IProgressMonitor)
is implemented.- Parameter:
edit
- the edit to applymonitor
- the progress monitor to use ornull
if no progress should be reported- Gibt zurück:
- the undo edit
- Löst aus:
JavaModelException
- if this edit can not be applied to the compilation unit's buffer. Reasons include:- This compilation unit does not exist (
IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST
). - The provided edit can not be applied as there is a problem with the text edit locations (
IJavaModelStatusConstants.BAD_TEXT_EDIT_LOCATION
).
- This compilation unit does not exist (
- Seit:
- 3.4
-
becomeWorkingCopy
void becomeWorkingCopy(IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Veraltet.UsebecomeWorkingCopy(IProgressMonitor)
instead. Note that if this deprecated method is used, problems will be reported to the given problem requestor as well as the problem requestor returned by the working copy owner (if not null).Changes this compilation unit handle into a working copy. A newIBuffer
is created using this compilation unit handle's owner. Uses the primary owner if none was specified when this compilation unit handle was created.When switching to working copy mode, problems are reported to given
IProblemRequestor
. Note that once in working copy mode, the givenIProblemRequestor
is ignored. Only the originalIProblemRequestor
is used to report subsequent problems.Once in working copy mode, changes to this compilation unit or its children are done in memory. Only the new buffer is affected. Using
commitWorkingCopy(boolean, IProgressMonitor)
will bring the underlying resource in sync with this compilation unit.If this compilation unit was already in working copy mode, an internal counter is incremented and no other action is taken on this compilation unit. To bring this compilation unit back into the original mode (where it reflects the underlying resource),
discardWorkingCopy()
must be call as many times asbecomeWorkingCopy(IProblemRequestor, IProgressMonitor)
.- Parameter:
problemRequestor
- a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set tonull
indicating that the client is not interested in problems.monitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reported- Löst aus:
JavaModelException
- if this compilation unit could not become a working copy.- Seit:
- 3.0
- Siehe auch:
-
becomeWorkingCopy
Changes this compilation unit handle into a working copy. A newIBuffer
is created using this compilation unit handle's owner. Uses the primary owner if none was specified when this compilation unit handle was created.When switching to working copy mode, problems are reported to the
problem requestor
of theworking copy owner
.Once in working copy mode, changes to this compilation unit or its children are done in memory. Only the new buffer is affected. Using
commitWorkingCopy(boolean, IProgressMonitor)
will bring the underlying resource in sync with this compilation unit.If this compilation unit was already in working copy mode, an internal counter is incremented and no other action is taken on this compilation unit. To bring this compilation unit back into the original mode (where it reflects the underlying resource),
discardWorkingCopy()
must be call as many times asbecomeWorkingCopy(IProblemRequestor, IProgressMonitor)
.- Parameter:
monitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reported- Löst aus:
JavaModelException
- if this compilation unit could not become a working copy.- Seit:
- 3.3
- Siehe auch:
-
commitWorkingCopy
void commitWorkingCopy(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Commits the contents of this working copy to its underlying resource.It is possible that the contents of the original resource have changed since this working copy was created, in which case there is an update conflict. The value of the
force
parameter affects the resolution of such a conflict:-
true
- in this case the contents of this working copy are applied to the underlying resource even though this working copy was created before a subsequent change in the resource -
false
- in this case aJavaModelException
is thrown
Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Parameter:
force
- a flag to handle the cases when the contents of the original resource have changed since this working copy was createdmonitor
- the given progress monitor- Löst aus:
JavaModelException
- if this working copy could not commit. Reasons include:- A
CoreException
occurred while updating an underlying resource - This element is not a working copy (INVALID_ELEMENT_TYPES)
- A update conflict (described above) (UPDATE_CONFLICT)
- A
- Seit:
- 3.0
-
-
createImport
IImportDeclaration createImport(String name, IJavaElement sibling, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns an non-static import declaration in this compilation unit with the given name. This method is equivalent tocreateImport(name, Flags.AccDefault, sibling, monitor)
.- Parameter:
name
- the name of the import declaration to add as defined by JLS2 7.5. (For example:"java.io.File"
or"java.awt.*"
)sibling
- the existing element which the import declaration will be inserted immediately before (ifnull
, then this import will be inserted as the last import declaration.monitor
- the progress monitor to notify- Gibt zurück:
- the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
- Löst aus:
JavaModelException
- if the element could not be created. Reasons include:- This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException
occurred while updating an underlying resource - The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
- The name is not a valid import name (INVALID_NAME)
- Siehe auch:
-
createImport
IImportDeclaration createImport(String name, IJavaElement sibling, int flags, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns an import declaration in this compilation unit with the given name.Optionally, the new element can be positioned before the specified sibling. If no sibling is specified, the element will be inserted as the last import declaration in this compilation unit.
If the compilation unit already includes the specified import declaration, the import is not generated (it does not generate duplicates). Note that it is valid to specify both a single-type import and an on-demand import for the same package, for example
"java.io.File"
and"java.io.*"
, in which case both are preserved since the semantics of this are not the same as just importing"java.io.*"
. Importing"java.lang.*"
, or the package in which the compilation unit is defined, are not treated as special cases. If they are specified, they are included in the result.Note: This API element is only needed for dealing with Java code that uses new language features of J2SE 5.0.
- Parameter:
name
- the name of the import declaration to add as defined by JLS2 7.5. (For example:"java.io.File"
or"java.awt.*"
)sibling
- the existing element which the import declaration will be inserted immediately before (ifnull
, then this import will be inserted as the last import declaration.flags
-Flags.AccStatic
for static imports, orFlags.AccDefault
for regular imports; other modifier flags are ignoredmonitor
- the progress monitor to notify- Gibt zurück:
- the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
- Löst aus:
JavaModelException
- if the element could not be created. Reasons include:- This Java element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException
occurred while updating an underlying resource - The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
- The name is not a valid import name (INVALID_NAME)
- Seit:
- 3.0
- Siehe auch:
-
createPackageDeclaration
IPackageDeclaration createPackageDeclaration(String name, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns a package declaration in this compilation unit with the given package name.If the compilation unit already includes the specified package declaration, it is not generated (it does not generate duplicates).
- Parameter:
name
- the name of the package declaration to add as defined by JLS2 7.4. (For example,"java.lang"
)monitor
- the progress monitor to notify- Gibt zurück:
- the newly inserted package declaration (or the previously existing one in case attempting to create a duplicate)
- Löst aus:
JavaModelException
- if the element could not be created. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException
occurred while updating an underlying resource - The name is not a valid package name (INVALID_NAME)
-
createType
IType createType(String contents, IJavaElement sibling, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns a type in this compilation unit with the given contents. If this compilation unit does not exist, one will be created with an appropriate package declaration.Optionally, the new type can be positioned before the specified sibling. If
sibling
isnull
, the type will be appended to the end of this compilation unit.It is possible that a type with the same name already exists in this compilation unit. The value of the
force
parameter affects the resolution of such a conflict:-
true
- in this case the type is created with the new contents -
false
- in this case aJavaModelException
is thrown
- Parameter:
contents
- the source contents of the type declaration to add.sibling
- the existing element which the type will be inserted immediately before (ifnull
, then this type will be inserted as the last type declaration.force
- aboolean
flag indicating how to deal with duplicatesmonitor
- the progress monitor to notify- Gibt zurück:
- the newly inserted type
- Löst aus:
JavaModelException
- if the element could not be created. Reasons include:- The specified sibling element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException
occurred while updating an underlying resource - The specified sibling is not a child of this compilation unit (INVALID_SIBLING)
- The contents could not be recognized as a type declaration (INVALID_CONTENTS)
- There was a naming collision with an existing type (NAME_COLLISION)
-
-
discardWorkingCopy
Changes this compilation unit in working copy mode back to its original mode.This has no effect if this compilation unit was not in working copy mode.
If
becomeWorkingCopy(IProgressMonitor)
method was called several times on this compilation unit,discardWorkingCopy()
must be called as many times before it switches back to the original mode. Same as for methodgetWorkingCopy(IProgressMonitor)
.- Löst aus:
JavaModelException
- if this working copy could not return in its original mode.- Seit:
- 3.0
- Siehe auch:
-
findElements
Finds the elements in this compilation unit that correspond to the given element. An element A corresponds to an element B if:- A has the same element name as B.
- If A is a method, A must have the same number of arguments as B and the simple names of the argument types must be equals.
- The parent of A corresponds to the parent of B recursively up to their respective compilation units.
- A exists.
null
for the following cases:- if no such java elements can be found or if the given element is not included in this compilation unit
- the element is a lambda expression, i.e. calling
IType.isLambda()
returns true - the element is an
ILocalVariable
- Angegeben von:
findElements
in SchnittstelleIWorkingCopy
- Parameter:
element
- the given element- Gibt zurück:
- the found elements in this compilation unit that correspond to the given element
- Seit:
- 3.0
-
findWorkingCopy
Finds the working copy for this compilation unit, given aWorkingCopyOwner
. If no working copy has been created for this compilation unit associated with this working copy owner, returnsnull
.Users of this method must not destroy the resulting working copy.
- Parameter:
owner
- the givenWorkingCopyOwner
- Gibt zurück:
- the found working copy for this compilation unit,
null
if none - Seit:
- 3.0
- Siehe auch:
-
getAllTypes
Returns all types declared in this compilation unit in the order in which they appear in the source. This includes all top-level types and nested member types. It does NOT include local types (types defined in methods).- Gibt zurück:
- the array of top-level and member types defined in a compilation unit, in declaration order.
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
getImport
Returns the first import declaration in this compilation unit with the given name. This is a handle-only method. The import declaration may or may not exist. This is a convenience method - imports can also be accessed from a compilation unit's import container.- Parameter:
name
- the name of the import to find as defined by JLS2 7.5. (For example:"java.io.File"
or"java.awt.*"
)- Gibt zurück:
- a handle onto the corresponding import declaration. The import declaration may or may not exist.
-
getImportContainer
IImportContainer getImportContainer()Returns the import container for this compilation unit. This is a handle-only method. The import container may or may not exist. The import container can used to access the imports.- Gibt zurück:
- a handle onto the corresponding import container. The import contain may or may not exist.
-
getImports
Returns the import declarations in this compilation unit in the order in which they appear in the source. This is a convenience method - import declarations can also be accessed from a compilation unit's import container.- Gibt zurück:
- the import declarations in this compilation unit
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
getPrimary
ICompilationUnit getPrimary()Returns the primary compilation unit (whose owner is the primary owner) this working copy was created from, or this compilation unit if this a primary compilation unit.Note that the returned primary compilation unit can be in working copy mode.
- Gibt zurück:
- the primary compilation unit this working copy was created from, or this compilation unit if it is primary
- Seit:
- 3.0
-
getOwner
WorkingCopyOwner getOwner()Returnsnull
if thisICompilationUnit
is the primary working copy, or thisICompilationUnit
is not a working copy, otherwise theWorkingCopyOwner
- Gibt zurück:
null
if thisICompilationUnit
is the primary working copy, or thisICompilationUnit
is not a working copy, otherwise theWorkingCopyOwner
- Seit:
- 3.0
-
getPackageDeclaration
Returns the first package declaration in this compilation unit with the given package name (there normally is at most one package declaration). This is a handle-only method. The package declaration may or may not exist.- Parameter:
name
- the name of the package declaration as defined by JLS2 7.4. (For example,"java.lang"
)- Gibt zurück:
- the first package declaration in this compilation unit with the given package name
-
getPackageDeclarations
Returns the package declarations in this compilation unit in the order in which they appear in the source. There normally is at most one package declaration.- Gibt zurück:
- an array of package declaration (normally of size one)
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
getType
Returns the top-level type declared in this compilation unit with the given simple type name. The type name has to be a valid compilation unit name. This is a handle-only method. The type may or may not exist.- Parameter:
name
- the simple name of the requested type in the compilation unit- Gibt zurück:
- a handle onto the corresponding type. The type may or may not exist.
- Siehe auch:
-
getTypes
Returns the top-level types declared in this compilation unit in the order in which they appear in the source.- Gibt zurück:
- the top-level types declared in this compilation unit
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
getWorkingCopy
ICompilationUnit getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Returns a new working copy of this compilation unit if it is a primary compilation unit, or this compilation unit if it is already a non-primary working copy.Note: if intending to share a working copy amongst several clients, then
getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
should be used instead.When the working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.
Once done with the working copy, users of this method must discard it using
discardWorkingCopy()
.Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Parameter:
monitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reported- Gibt zurück:
- a new working copy of this element if this element is not a working copy, or this element if this element is already a working copy
- Löst aus:
JavaModelException
- if the contents of this element can not be determined.- Seit:
- 3.0
-
getWorkingCopy
ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Veraltet.UseITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
instead. Note that if this deprecated method is used, problems will be reported on the passed problem requester as well as on the problem requestor returned by the working copy owner (if not null).Returns a shared working copy on this compilation unit using the given working copy owner to create the buffer, or this compilation unit if it is already a non-primary working copy. This API can only answer an already existing working copy if it is based on the same original compilation unit AND was using the same working copy owner (that is, as defined byObject.equals(java.lang.Object)
).The life time of a shared working copy is as follows:
- The first call to
getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
creates a new working copy for this element - Subsequent calls increment an internal counter.
- A call to
discardWorkingCopy()
decrements the internal counter. - When this counter is 0, the working copy is discarded.
Note that the working copy owner will be used for the life time of this working copy, that is if the working copy is closed then reopened, this owner will be used. The buffer will be automatically initialized with the original's compilation unit content upon creation.
When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.
Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
- Parameter:
owner
- the working copy owner that creates a buffer that is used to get the content of the working copyproblemRequestor
- a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set tonull
indicating that the client is not interested in problems.monitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reported- Gibt zurück:
- a new working copy of this element using the given factory to create the buffer, or this element if this element is already a working copy
- Löst aus:
JavaModelException
- if the contents of this element can not be determined.- Seit:
- 3.0
- The first call to
-
hasResourceChanged
boolean hasResourceChanged()Returns whether the resource of this working copy has changed since the inception of this working copy. Returnsfalse
if this compilation unit is not in working copy mode.- Gibt zurück:
- whether the resource has changed
- Seit:
- 3.0
-
isWorkingCopy
boolean isWorkingCopy()Returns whether this element is a working copy.- Angegeben von:
isWorkingCopy
in SchnittstelleIWorkingCopy
- Gibt zurück:
- true if this element is a working copy, false otherwise
- Seit:
- 3.0
-
setOptions
Sets the ICompilationUnit custom options. All and only the options explicitly included in the given table are remembered; all previous option settings are forgotten, including ones not explicitly mentioned.For a complete description of the configurable options, see
JavaCore#getDefaultOptions
.- Parameter:
newOptions
- the new custom options for this compilation unit- Seit:
- 3.25
- Siehe auch:
-
getCustomOptions
Returns the table of the current custom options for this ICompilationUnit. If there is nosetOptions
called for the ICompliationUnit, then return an empty table.- Gibt zurück:
- the table of the current custom options for this ICompilationUnit
- Seit:
- 3.25
-
getOptions
Returns the table of the options for this ICompilationUnit, which includes its custom options and options inherited from its parent JavaProject. The boolean argumentinheritJavaCoreOptions
allows to directly merge the global ones fromJavaCore
.For a complete description of the configurable options, see
JavaCore#getDefaultOptions
.- Parameter:
inheritJavaCoreOptions
- - boolean indicating whether the JavaCore options should be inherited as well- Gibt zurück:
- table of current settings of all options
- Seit:
- 3.25
- Siehe auch:
-
reconcile
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.
The boolean argument allows to force problem detection even if the working copy is already consistent.
This functionality allows to specify a working copy owner which is used during problem detection. All references contained in the working copy are resolved against other units; for which corresponding owned working copies are going to take precedence over their original compilation units. If
null
is passed in, then the primary working copy owner is used.Compilation problems found in the new contents are notified through the
IProblemRequestor
interface which was passed at creation, and no longer as transient markers.Note: Since 3.0, added/removed/changed inner types generate change deltas.
If requested, a DOM AST representing the compilation unit is returned. Its bindings are computed only if the problem requestor is active. This method returns
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
This method doesn't perform statements recovery. To recover statements with syntax errors,
reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor)
must be use.- Parameter:
astLevel
- eitherNO_AST
if no AST is wanted, or the AST API level of the AST if one is wantedforceProblemDetection
- boolean indicating whether problem should be recomputed even if the source hasn't changedowner
- the owner of working copies that take precedence over the original compilation units, ornull
if the primary working copy owner should be usedmonitor
- a progress monitor- Gibt zurück:
- the compilation unit AST or
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
- Löst aus:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- Seit:
- 3.0
-
reconcile
CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.
The boolean argument allows to force problem detection even if the working copy is already consistent.
This functionality allows to specify a working copy owner which is used during problem detection. All references contained in the working copy are resolved against other units; for which corresponding owned working copies are going to take precedence over their original compilation units. If
null
is passed in, then the primary working copy owner is used.Compilation problems found in the new contents are notified through the
IProblemRequestor
interface which was passed at creation, and no longer as transient markers.Note: Since 3.0, added/removed/changed inner types generate change deltas.
If requested, a DOM AST representing the compilation unit is returned. Its bindings are computed only if the problem requestor is active. This method returns
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
If statements recovery is enabled then this method tries to rebuild statements with syntax error. Otherwise statements with syntax error won't be present in the returning DOM AST.
- Parameter:
astLevel
- eitherNO_AST
if no AST is wanted, or the AST API level of the AST if one is wantedforceProblemDetection
- boolean indicating whether problem should be recomputed even if the source hasn't changedenableStatementsRecovery
- iftrue
statements recovery is enabled.owner
- the owner of working copies that take precedence over the original compilation units, ornull
if the primary working copy owner should be usedmonitor
- a progress monitor- Gibt zurück:
- the compilation unit AST or
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
- Löst aus:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- Seit:
- 3.2
-
reconcile
CompilationUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Reconciles the contents of this working copy, sends out a Java delta notification indicating the nature of the change of the working copy since the last time it was either reconciled or made consistent (IOpenable.makeConsistent(IProgressMonitor)
), and returns a compilation unit AST if requested.If the problem detection is forced by passing the
FORCE_PROBLEM_DETECTION
bit in the given reconcile flag, problem detection is run even if the working copy is already consistent.It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.
This functionality allows to specify a working copy owner which is used during problem detection. All references contained in the working copy are resolved against other units; for which corresponding owned working copies are going to take precedence over their original compilation units. If
null
is passed in, then the primary working copy owner is used.Compilation problems found in the new contents are notified through the
IProblemRequestor
interface which was passed at creation, and no longer as transient markers.Note: Since 3.0, added/removed/changed inner types generate change deltas.
If requested, a DOM AST representing the compilation unit is returned. Its bindings are computed only if the problem requestor is active. This method returns
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
If statements recovery is enabled by passing the
ENABLE_STATEMENTS_RECOVERY
bit in the given reconcile flag then this method tries to rebuild statements with syntax error. Otherwise statements with syntax error won't be present in the returning DOM AST.If bindings recovery is enabled by passing the
ENABLE_BINDINGS_RECOVERY
bit in the given reconcile flag then this method tries to resolve bindings even if the type resolution contains errors.The given reconcile flags is a bit-mask of the different constants (
ENABLE_BINDINGS_RECOVERY
,ENABLE_STATEMENTS_RECOVERY
,FORCE_PROBLEM_DETECTION
). Unspecified values are left for future use.- Parameter:
astLevel
- eitherNO_AST
if no AST is wanted, or the AST API level of the AST if one is wantedreconcileFlags
- the given reconcile flagsowner
- the owner of working copies that take precedence over the original compilation units, ornull
if the primary working copy owner should be usedmonitor
- a progress monitor- Gibt zurück:
- the compilation unit AST or
null
if one of the following conditions is true:- the creation of the DOM AST is not requested
- the requested level of AST API is not supported
- the working copy was already consistent and problem detection is not forced
- Löst aus:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- Seit:
- 3.3
- Siehe auch:
-
restore
Restores the contents of this working copy to the current contents of this working copy's original element. Has no effect if this element is not a working copy.Note: This is the inverse of committing the content of the working copy to the original element with
commitWorkingCopy(boolean, IProgressMonitor)
.- Angegeben von:
restore
in SchnittstelleIWorkingCopy
- Löst aus:
JavaModelException
- if the contents of the original element cannot be accessed. Reasons include:- The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- Seit:
- 3.0
-
becomeWorkingCopy(IProgressMonitor)
instead.