Class CompilationUnit

java.lang.Object
org.eclipse.core.runtime.PlatformObject
All Implemented Interfaces:
IBufferChangedListener, ICodeAssist, ICompilationUnit, IJavaElement, IOpenable, IParent, ISourceManipulation, ISourceReference, ITypeRoot, IWorkingCopy, ICompilationUnit, IDependent, SuffixConstants, org.eclipse.core.runtime.IAdaptable
Direct Known Subclasses:
AssistCompilationUnit, ClassFileWorkingCopy

public class CompilationUnit extends Openable implements ICompilationUnit, ICompilationUnit, SuffixConstants
See Also:
ICompilationUnit
  • Field Details

  • Constructor Details

    • CompilationUnit

      public CompilationUnit(PackageFragment parent, String name, WorkingCopyOwner owner)
      Constructs a handle to a compilation unit with the given name in the specified package for the specified owner
  • Method Details

    • applyTextEdit

      public org.eclipse.text.edits.UndoEdit applyTextEdit(org.eclipse.text.edits.TextEdit edit, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 how IBuffer.ITextEditCapability.applyTextEdit(TextEdit, IProgressMonitor) is implemented.

      Specified by:
      applyTextEdit in interface ICompilationUnit
      Parameters:
      edit - the edit to apply
      monitor - the progress monitor to use or null if no progress should be reported
      Returns:
      the undo edit
      Throws:
      JavaModelException - if this edit can not be applied to the compilation unit's buffer. Reasons include:
    • becomeWorkingCopy

      public void becomeWorkingCopy(IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      Changes this compilation unit handle into a working copy. A new IBuffer 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 given IProblemRequestor is ignored. Only the original IProblemRequestor 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 ICompilationUnit.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), ICompilationUnit.discardWorkingCopy() must be call as many times as ICompilationUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor).

      Specified by:
      becomeWorkingCopy in interface ICompilationUnit
      Parameters:
      problemRequestor - a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set to null indicating that the client is not interested in problems.
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      Throws:
      JavaModelException - if this compilation unit could not become a working copy.
      See Also:
      ICompilationUnit.discardWorkingCopy()
    • becomeWorkingCopy

      public void becomeWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      Changes this compilation unit handle into a working copy. A new IBuffer 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 the working 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 ICompilationUnit.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), ICompilationUnit.discardWorkingCopy() must be call as many times as ICompilationUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor).

      Specified by:
      becomeWorkingCopy in interface ICompilationUnit
      Parameters:
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      Throws:
      JavaModelException - if this compilation unit could not become a working copy.
      See Also:
      ICompilationUnit.discardWorkingCopy()
    • buildStructure

      protected boolean buildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map newElements, org.eclipse.core.resources.IResource underlyingResource) throws JavaModelException
      Description copied from class: Openable
      Builds this element's structure and properties in the given info object, based on this element's current contents (reuse buffer contents if this element has an open buffer, or resource contents if this element does not have an open buffer). Children are placed in the given newElements table (note, this element has already been placed in the newElements table). Returns true if successful, or false if an error is encountered while determining the structure of this element.
      Specified by:
      buildStructure in class Openable
      Throws:
      JavaModelException
    • cloneCachingContents

      public CompilationUnit cloneCachingContents()
    • canBeRemovedFromCache

      public boolean canBeRemovedFromCache()
      Overrides:
      canBeRemovedFromCache in class Openable
    • canBufferBeRemovedFromCache

      public boolean canBufferBeRemovedFromCache(IBuffer buffer)
      Overrides:
      canBufferBeRemovedFromCache in class Openable
    • close

      public void close() throws JavaModelException
      Description copied from interface: IOpenable
      Closes this element and its buffer (if any). Closing an element which is not open has no effect.

      Note: Although IOpenable.close() is exposed in the API, clients are not expected to open and close elements - the Java model does this automatically as elements are accessed.

      Specified by:
      close in interface IOpenable
      Overrides:
      close in class JavaElement
      Throws:
      JavaModelException - if an error occurs closing this element
      See Also:
      IOpenable
    • closing

      protected void closing(Object info)
      Description copied from class: Openable
      This element is being closed. Do any necessary cleanup.
      Overrides:
      closing in class Openable
    • codeComplete

      public void codeComplete(int offset, ICompletionRequestor requestor) throws JavaModelException
      Deprecated.
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit.
      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
      See Also:
      ICodeAssist.codeComplete(int, ICompletionRequestor)
    • codeComplete

      public void codeComplete(int offset, ICompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException
      Deprecated.
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

      Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      workingCopyOwner - the owner of working copies that take precedence over their original compilation units
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
      See Also:
      ICodeAssist.codeComplete(int, ICompletionRequestor, WorkingCopyOwner)
    • codeComplete

      public void codeComplete(int offset, ICodeCompletionRequestor requestor) throws JavaModelException
      Deprecated.
      - use codeComplete(int, ICompletionRequestor)
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit.
      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
      See Also:
      ICodeAssist.codeComplete(int, ICodeCompletionRequestor)
    • codeComplete

      public void codeComplete(int offset, CompletionRequestor requestor) throws JavaModelException
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit.

      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
    • codeComplete

      public void codeComplete(int offset, CompletionRequestor requestor, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit.

      If IProgressMonitor is not null then some proposals which can be very long to compute are proposed. To avoid that the code assist operation take too much time a IProgressMonitor which automatically cancel the code assist operation when a specified amount of time is reached could be used.

       new IProgressMonitor() {
           private final static int TIMEOUT = 500; //ms
           private long endTime;
           public void beginTask(String name, int totalWork) {
               fEndTime= System.currentTimeMillis() + TIMEOUT;
           }
           public boolean isCanceled() {
               return endTime <= System.currentTimeMillis();
           }
           ...
       };
       

      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      monitor - the progress monitor used to report progress
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
    • codeComplete

      public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner) throws JavaModelException
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

      Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      workingCopyOwner - the owner of working copies that take precedence over their original compilation units
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
    • codeComplete

      public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner workingCopyOwner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICodeAssist
      Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. The offset is the 0-based index of the character, after which code assist is desired. An offset of -1 indicates to code assist at the beginning of this compilation unit. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

      Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

      If IProgressMonitor is not null then some proposals which can be very long to compute are proposed. To avoid that the code assist operation take too much time a IProgressMonitor which automatically cancel the code assist operation when a specified amount of time is reached could be used.

       new IProgressMonitor() {
           private final static int TIMEOUT = 500; //ms
           private long endTime;
           public void beginTask(String name, int totalWork) {
               fEndTime= System.currentTimeMillis() + TIMEOUT;
           }
           public boolean isCanceled() {
               return endTime <= System.currentTimeMillis();
           }
           ...
       };
       

      Specified by:
      codeComplete in interface ICodeAssist
      Parameters:
      offset - the given offset position
      requestor - the given completion requestor
      workingCopyOwner - the owner of working copies that take precedence over their original compilation units
      monitor - the progress monitor used to report progress
      Throws:
      JavaModelException - if code assist could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
    • codeSelect

      public IJavaElement[] codeSelect(int offset, int length) throws JavaModelException
      Description copied from interface: ICodeAssist
      Returns the Java elements corresponding to the given selected text in this compilation unit. The offset is the 0-based index of the first selected character. The length is the number of selected characters.

      Note that if the length is 0 and the offset is inside an identifier or the index just after an identifier then this identifier is considered as the selection.

      Specified by:
      codeSelect in interface ICodeAssist
      Parameters:
      offset - the given offset position
      length - the number of selected characters
      Returns:
      the Java elements corresponding to the given selected text
      Throws:
      JavaModelException - if code resolve could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The range specified is not within this element's source range (INDEX_OUT_OF_BOUNDS)
      See Also:
      ICodeAssist.codeSelect(int, int)
    • codeSelect

      public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner workingCopyOwner) throws JavaModelException
      Description copied from interface: ICodeAssist
      Returns the Java elements corresponding to the given selected text in this compilation unit. The offset is the 0-based index of the first selected character. The length is the number of selected characters. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.

      Note that if the length is 0 and the offset is inside an identifier or the index just after an identifier then this identifier is considered as the selection.

      Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.

      Specified by:
      codeSelect in interface ICodeAssist
      Parameters:
      offset - the given offset position
      length - the number of selected characters
      workingCopyOwner - the owner of working copies that take precedence over their original compilation units
      Returns:
      the Java elements corresponding to the given selected text
      Throws:
      JavaModelException - if code resolve could not be performed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • The range specified is not within this element's source range (INDEX_OUT_OF_BOUNDS)
      See Also:
      ICodeAssist.codeSelect(int, int, WorkingCopyOwner)
    • commit

      public void commit(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Deprecated.
      Description copied from interface: IWorkingCopy
      Commits the contents of this working copy to its original element and underlying resource, bringing the Java model up-to-date with the current contents of the working copy.

      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 a JavaModelException 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.

      Specified by:
      commit in interface IWorkingCopy
      Parameters:
      force - a flag to handle the cases when the contents of the original resource have changed since this working copy was created
      monitor - the given progress monitor
      Throws:
      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)
      See Also:
      IWorkingCopy.commit(boolean, IProgressMonitor)
    • commitWorkingCopy

      public void commitWorkingCopy(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 a JavaModelException 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.

      Specified by:
      commitWorkingCopy in interface ICompilationUnit
      Parameters:
      force - a flag to handle the cases when the contents of the original resource have changed since this working copy was created
      monitor - the given progress monitor
      Throws:
      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)
      See Also:
      ICompilationUnit.commitWorkingCopy(boolean, IProgressMonitor)
    • copy

      public void copy(IJavaElement container, IJavaElement sibling, String rename, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ISourceManipulation
      Copies this element to the given container.
      Specified by:
      copy in interface ISourceManipulation
      Parameters:
      container - the container
      sibling - the sibling element before which the copy should be inserted, or null if the copy should be inserted as the last child of the container
      rename - the new name for the element, or null if the copy retains the name of this element
      force - true if any existing child in the container with the target name should be replaced, and false to throw an exception in the event of a name collision
      monitor - a progress monitor
      Throws:
      JavaModelException - if this element could not be copied. Reasons include:
      • This Java element, container element, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
      • A CoreException occurred while updating an underlying resource
      • The container is of an incompatible type (INVALID_DESTINATION)
      • The sibling is not a child of the given container (INVALID_SIBLING)
      • The new name is invalid (INVALID_NAME)
      • A child in the container already exists with the same name (NAME_COLLISION) and replace has been specified as false
      • The container or this element is read-only (READ_ONLY)
      See Also:
      ISourceManipulation.copy(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
    • createElementInfo

      protected Object createElementInfo()
      Returns a new element info for this element.
      Overrides:
      createElementInfo in class Openable
    • createImport

      public IImportDeclaration createImport(String importName, IJavaElement sibling, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      Creates and returns an non-static import declaration in this compilation unit with the given name. This method is equivalent to createImport(name, Flags.AccDefault, sibling, monitor).
      Specified by:
      createImport in interface ICompilationUnit
      Parameters:
      importName - 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 (if null , then this import will be inserted as the last import declaration.
      monitor - the progress monitor to notify
      Returns:
      the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
      Throws:
      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)
      See Also:
      ICompilationUnit.createImport(String, IJavaElement, IProgressMonitor)
    • createImport

      public IImportDeclaration createImport(String importName, IJavaElement sibling, int flags, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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.

      Specified by:
      createImport in interface ICompilationUnit
      Parameters:
      importName - 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 (if null , then this import will be inserted as the last import declaration.
      flags - Flags.AccStatic for static imports, or Flags.AccDefault for regular imports; other modifier flags are ignored
      monitor - the progress monitor to notify
      Returns:
      the newly inserted import declaration (or the previously existing one in case attempting to create a duplicate)
      Throws:
      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)
      Since:
      3.0
      See Also:
      ICompilationUnit.createImport(String, IJavaElement, int, IProgressMonitor)
    • createPackageDeclaration

      public IPackageDeclaration createPackageDeclaration(String pkg, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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).

      Specified by:
      createPackageDeclaration in interface ICompilationUnit
      Parameters:
      pkg - the name of the package declaration to add as defined by JLS2 7.4. (For example, "java.lang")
      monitor - the progress monitor to notify
      Returns:
      the newly inserted package declaration (or the previously existing one in case attempting to create a duplicate)
      Throws:
      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)
      See Also:
      ICompilationUnit.createPackageDeclaration(String, IProgressMonitor)
    • createType

      public IType createType(String content, IJavaElement sibling, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 is null, 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 a JavaModelException is thrown
      Specified by:
      createType in interface ICompilationUnit
      Parameters:
      content - the source contents of the type declaration to add.
      sibling - the existing element which the type will be inserted immediately before (if null, then this type will be inserted as the last type declaration.
      force - a boolean flag indicating how to deal with duplicates
      monitor - the progress monitor to notify
      Returns:
      the newly inserted type
      Throws:
      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)
      See Also:
      ICompilationUnit.createType(String, IJavaElement, boolean, IProgressMonitor)
    • delete

      public void delete(boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ISourceManipulation
      Deletes this element, forcing if specified and necessary.
      Specified by:
      delete in interface ISourceManipulation
      Parameters:
      force - a flag controlling whether underlying resources that are not in sync with the local file system will be tolerated (same as the force flag in IResource operations).
      monitor - a progress monitor
      Throws:
      JavaModelException - if this element could not be deleted. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • A CoreException occurred while updating an underlying resource (CORE_EXCEPTION)
      • This element is read-only (READ_ONLY)
      See Also:
      ISourceManipulation.delete(boolean, IProgressMonitor)
    • destroy

      public void destroy()
      Deprecated.
      Description copied from interface: IWorkingCopy
      Destroys this working copy, closing its buffer and discarding its structure. Subsequent attempts to access non-handle information for this working copy will result in IJavaModelExceptions. Has no effect if this element is not a working copy.

      If this working copy is shared, it is destroyed only when the number of calls to destroy() is the same as the number of calls to getSharedWorkingCopy(IProgressMonitor, IBufferFactory).

      When it is destroyed, a REMOVED IJavaElementDelta is reported on this working copy.

      Specified by:
      destroy in interface IWorkingCopy
      See Also:
      IWorkingCopy.destroy()
    • discardWorkingCopy

      public void discardWorkingCopy() throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 ICompilationUnit.becomeWorkingCopy(IProgressMonitor) method was called several times on this compilation unit, ICompilationUnit.discardWorkingCopy() must be called as many times before it switches back to the original mode. Same as for method ICompilationUnit.getWorkingCopy(IProgressMonitor).

      Specified by:
      discardWorkingCopy in interface ICompilationUnit
      Throws:
      JavaModelException - if this working copy could not return in its original mode.
      See Also:
      ICompilationUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor)
    • equals

      public boolean equals(Object obj)
      Returns true if this handle represents the same Java element as the given handle.
      Overrides:
      equals in class JavaElement
      See Also:
      Object.equals(java.lang.Object)
    • findElements

      public IJavaElement[] findElements(IJavaElement element)
      Description copied from interface: ICompilationUnit
      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.
      Returns 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
      Specified by:
      findElements in interface ICompilationUnit
      Specified by:
      findElements in interface IWorkingCopy
      Parameters:
      element - the given element
      Returns:
      the found elements in this compilation unit that correspond to the given element
      See Also:
      ICompilationUnit.findElements(IJavaElement)
    • findPrimaryType

      public IType findPrimaryType()
      Description copied from interface: ITypeRoot
      Finds the primary type of this Java type root (that is, the type with the same name as the compilation unit, or the type of a class file), or null if no such a type exists.
      Specified by:
      findPrimaryType in interface ITypeRoot
      Specified by:
      findPrimaryType in interface IWorkingCopy
      Returns:
      the found primary type of this Java type root, or null if no such a type exists
      See Also:
      ITypeRoot.findPrimaryType()
    • findSharedWorkingCopy

      public IJavaElement findSharedWorkingCopy(IBufferFactory factory)
      Deprecated.
      Description copied from interface: IWorkingCopy
      Finds the shared working copy for this element, given a IBuffer factory. If no working copy has been created for this element associated with this buffer factory, returns null.

      Users of this method must not destroy the resulting working copy.

      Specified by:
      findSharedWorkingCopy in interface IWorkingCopy
      Parameters:
      factory - the given IBuffer factory
      Returns:
      the found shared working copy for this element, null if none
      See Also:
      IWorkingCopy.findSharedWorkingCopy(IBufferFactory)
    • findWorkingCopy

      public ICompilationUnit findWorkingCopy(WorkingCopyOwner workingCopyOwner)
      Description copied from interface: ICompilationUnit
      Finds the working copy for this compilation unit, given a WorkingCopyOwner. If no working copy has been created for this compilation unit associated with this working copy owner, returns null.

      Users of this method must not destroy the resulting working copy.

      Specified by:
      findWorkingCopy in interface ICompilationUnit
      Parameters:
      workingCopyOwner - the given WorkingCopyOwner
      Returns:
      the found working copy for this compilation unit, null if none
      See Also:
      ICompilationUnit.findWorkingCopy(WorkingCopyOwner)
    • getAllTypes

      public IType[] getAllTypes() throws JavaModelException
      Description copied from interface: ICompilationUnit
      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).
      Specified by:
      getAllTypes in interface ICompilationUnit
      Returns:
      the array of top-level and member types defined in a compilation unit, in declaration order.
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      ICompilationUnit.getAllTypes()
    • getCompilationUnit

      public ICompilationUnit getCompilationUnit()
      Overrides:
      getCompilationUnit in class JavaElement
      See Also:
      IMember.getCompilationUnit()
    • getContents

      public char[] getContents()
      Description copied from interface: ICompilationUnit
      Answer the contents of the compilation unit. In normal use, the contents are requested twice. Once during the initial lite parsing step, then again for the more detailed parsing step. Implementors must never return null - return an empty char[] instead, CharOperation.NO_CHAR being the candidate of choice.
      Specified by:
      getContents in interface ICompilationUnit
      See Also:
      ICompilationUnit.getContents()
    • getCorrespondingResource

      public org.eclipse.core.resources.IResource getCorrespondingResource() throws JavaModelException
      A compilation unit has a corresponding resource unless it is contained in a jar.
      Specified by:
      getCorrespondingResource in interface IJavaElement
      Overrides:
      getCorrespondingResource in class Openable
      Returns:
      the corresponding resource, or null if none
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      IJavaElement.getCorrespondingResource()
    • getElementAt

      public IJavaElement getElementAt(int position) throws JavaModelException
      Description copied from interface: ITypeRoot
      Returns the smallest element within this Java type root that includes the given source position (that is, a method, field, etc.), or null if there is no element other than the Java type root itself at the given position, or if the given position is not within the source range of the source of this Java type root.
      Specified by:
      getElementAt in interface ITypeRoot
      Parameters:
      position - a source position inside the Java type root
      Returns:
      the innermost Java element enclosing a given source position or null if none (excluding the Java type root).
      Throws:
      JavaModelException - if the Java type root does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      ITypeRoot.getElementAt(int)
    • getElementName

      public String getElementName()
      Description copied from interface: IJavaElement
      Returns the name of this element. This is a handle-only method.
      Specified by:
      getElementName in interface IJavaElement
      Overrides:
      getElementName in class JavaElement
      Returns:
      the element name
      See Also:
      IAdaptable
    • getElementType

      public int getElementType()
      Description copied from interface: IJavaElement
      Returns this element's kind encoded as an integer. This is a handle-only method.
      Specified by:
      getElementType in interface IJavaElement
      Returns:
      the kind of element; one of the constants declared in IJavaElement
      See Also:
      IJavaElement
    • getFileName

      public char[] getFileName()
      Description copied from interface: IDependent
      Answer the file name which defines the type. The path part (optional) must be separated from the actual file proper name by a separator suitable for the type (java.io.File.separator for example), e.g. "c:\\source\\com\\p\\X.java" or "/com/p/Y.java". The path to the zip or jar file (optional) must be separated from the actual path part by JAR_FILE_ENTRY_SEPARATOR, e.g. "c:\\lib\\some.jar|/com/p/X.class" or "/lib/some.zip|/com/q/Y.class". The proper file name includes the suffix extension (e.g. ".java") e.g. "c:/org/aspectj/org/eclipse/jdt/internal/compileri/env/IDependent.java" Return null if no file defines the type.
      Specified by:
      getFileName in interface IDependent
      See Also:
      IDependent.getFileName()
    • getHandleFromMemento

      public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner workingCopyOwner)
      Specified by:
      getHandleFromMemento in class JavaElement
    • getHandleMementoDelimiter

      protected char getHandleMementoDelimiter()
      Description copied from class: JavaElement
      Returns the char that marks the start of this handles contribution to a memento.
      Specified by:
      getHandleMementoDelimiter in class JavaElement
      See Also:
      JavaElement.getHandleMementoDelimiter()
    • getImport

      public IImportDeclaration getImport(String importName)
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getImport in interface ICompilationUnit
      Parameters:
      importName - the name of the import to find as defined by JLS2 7.5. (For example: "java.io.File" or "java.awt.*")
      Returns:
      a handle onto the corresponding import declaration. The import declaration may or may not exist.
      See Also:
      ICompilationUnit.getImport(String)
    • getImportContainer

      public IImportContainer getImportContainer()
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getImportContainer in interface ICompilationUnit
      Returns:
      a handle onto the corresponding import container. The import contain may or may not exist.
      See Also:
      ICompilationUnit.getImportContainer()
    • getImports

      public IImportDeclaration[] getImports() throws JavaModelException
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getImports in interface ICompilationUnit
      Returns:
      the import declarations in this compilation unit
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      ICompilationUnit.getImports()
    • getTypeRoot

      public ITypeRoot getTypeRoot()
      See Also:
      IMember.getTypeRoot()
    • getMainTypeName

      public char[] getMainTypeName()
      Description copied from interface: ICompilationUnit
      Answer the name of the top level public type. For example, {Hashtable}.
      Specified by:
      getMainTypeName in interface ICompilationUnit
      See Also:
      ICompilationUnit.getMainTypeName()
    • getOriginal

      public IJavaElement getOriginal(IJavaElement workingCopyElement)
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns the original element the specified working copy element was created from, or null if this is not a working copy element. This is a handle only method, the returned element may or may not exist.
      Specified by:
      getOriginal in interface IWorkingCopy
      Parameters:
      workingCopyElement - the specified working copy element
      Returns:
      the original element the specified working copy element was created from, or null if this is not a working copy element
      See Also:
      IWorkingCopy.getOriginal(IJavaElement)
    • getOriginalElement

      public IJavaElement getOriginalElement()
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns the original element this working copy was created from, or null if this is not a working copy.
      Specified by:
      getOriginalElement in interface IWorkingCopy
      Returns:
      the original element this working copy was created from, or null if this is not a working copy
      See Also:
      IWorkingCopy.getOriginalElement()
    • getOwner

      public WorkingCopyOwner getOwner()
      Description copied from interface: ICompilationUnit
      Returns null if this ICompilationUnit is the primary working copy, or this ICompilationUnit is not a working copy, otherwise the WorkingCopyOwner
      Specified by:
      getOwner in interface ICompilationUnit
      Returns:
      null if this ICompilationUnit is the primary working copy, or this ICompilationUnit is not a working copy, otherwise the WorkingCopyOwner
    • getPackageDeclaration

      public IPackageDeclaration getPackageDeclaration(String pkg)
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getPackageDeclaration in interface ICompilationUnit
      Parameters:
      pkg - the name of the package declaration as defined by JLS2 7.4. (For example, "java.lang")
      Returns:
      the first package declaration in this compilation unit with the given package name
      See Also:
      ICompilationUnit.getPackageDeclaration(String)
    • getPackageDeclarations

      public IPackageDeclaration[] getPackageDeclarations() throws JavaModelException
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getPackageDeclarations in interface ICompilationUnit
      Returns:
      an array of package declaration (normally of size one)
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      ICompilationUnit.getPackageDeclarations()
    • getPackageName

      public char[][] getPackageName()
      Description copied from interface: ICompilationUnit
      Answer the name of the package according to the directory structure or null if package consistency checks should be ignored. For example, {java, lang}.
      Specified by:
      getPackageName in interface ICompilationUnit
      See Also:
      ICompilationUnit.getPackageName()
    • getPath

      public org.eclipse.core.runtime.IPath getPath()
      Description copied from interface: IJavaElement
      Returns the path to the innermost resource enclosing this element. If this element is not included in an external library, the path returned is the full, absolute path to the underlying resource, relative to the workbench. If this element is included in an external library, the path returned is the absolute path to the archive or to the folder in the file system. This is a handle-only method.
      Specified by:
      getPath in interface IJavaElement
      Returns:
      the path to the innermost resource enclosing this element
      See Also:
      IJavaElement.getPath()
    • getPerWorkingCopyInfo

      public JavaModelManager.PerWorkingCopyInfo getPerWorkingCopyInfo()
    • getPrimary

      public ICompilationUnit getPrimary()
      Description copied from interface: ICompilationUnit
      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.

      Specified by:
      getPrimary in interface ICompilationUnit
      Returns:
      the primary compilation unit this working copy was created from, or this compilation unit if it is primary
    • getPrimaryElement

      public IJavaElement getPrimaryElement(boolean checkOwner)
      Overrides:
      getPrimaryElement in class JavaElement
    • resource

      public org.eclipse.core.resources.IResource resource(PackageFragmentRoot root)
      Specified by:
      resource in class Openable
    • getSource

      public String getSource() throws JavaModelException
      Description copied from interface: ISourceReference
      Returns the source code associated with this element. This extracts the substring from the source buffer containing this source element. This corresponds to the source range that would be returned by getSourceRange.

      For class files, this returns the source of the entire compilation unit associated with the class file (if there is one).

      Specified by:
      getSource in interface ISourceReference
      Returns:
      the source code, or null if this element has no associated source code
      Throws:
      JavaModelException - if an exception occurs while accessing its corresponding resource
      See Also:
      ISourceReference.getSource()
    • getSourceRange

      public ISourceRange getSourceRange() throws JavaModelException
      Description copied from interface: ISourceReference
      Returns the source range associated with this element.

      For class files, this returns the range of the entire compilation unit associated with the class file (if there is one).

      If this element has no associated source code, either null is returned, or a source range with a -1 offset and a 0 length. SourceRange.isAvailable(ISourceRange) can be used to detect that case.

      Specified by:
      getSourceRange in interface ISourceReference
      Returns:
      the source range, or either null or [-1, 0] if this element has no associated source code
      Throws:
      JavaModelException - if an exception occurs while accessing its corresponding resource
      See Also:
      ISourceReference.getSourceRange()
    • getType

      public IType getType(String typeName)
      Description copied from interface: ICompilationUnit
      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.
      Specified by:
      getType in interface ICompilationUnit
      Parameters:
      typeName - the simple name of the requested type in the compilation unit
      Returns:
      a handle onto the corresponding type. The type may or may not exist.
      See Also:
      ICompilationUnit.getType(String)
    • getTypes

      public IType[] getTypes() throws JavaModelException
      Description copied from interface: ICompilationUnit
      Returns the top-level types declared in this compilation unit in the order in which they appear in the source.
      Specified by:
      getTypes in interface ICompilationUnit
      Returns:
      the top-level types declared in this compilation unit
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource
      See Also:
      ICompilationUnit.getTypes()
    • getUnderlyingResource

      public org.eclipse.core.resources.IResource getUnderlyingResource() throws JavaModelException
      Description copied from interface: IJavaElement
      Returns the smallest underlying resource that contains this element, or null if this element is not contained in a resource.
      Specified by:
      getUnderlyingResource in interface IJavaElement
      Overrides:
      getUnderlyingResource in class Openable
      Returns:
      the underlying resource, or null if none
      Throws:
      JavaModelException - if this element does not exist or if an exception occurs while accessing its underlying resource
      See Also:
      IJavaElement
    • getSharedWorkingCopy

      public IJavaElement getSharedWorkingCopy(org.eclipse.core.runtime.IProgressMonitor pm, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns a shared working copy on this element using the given factory to create the buffer, or this element if this element is already a 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 buffer factory (that is, as defined by Object.equals).

      The life time of a shared working copy is as follows:

      • The first call to getSharedWorkingCopy(...) creates a new working copy for this element
      • Subsequent calls increment an internal counter.
      • A call to destroy() decrements the internal counter.
      • When this counter is 0, the working copy is destroyed.
      So users of this method must destroy exactly once the working copy.

      Note that the buffer factory will be used for the life time of this working copy, that is if the working copy is closed then reopened, this factory 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.

      Specified by:
      getSharedWorkingCopy in interface IWorkingCopy
      Parameters:
      pm - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      factory - the factory that creates a buffer that is used to get the content of the working copy or null if the internal factory should be used
      problemRequestor - a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set to null indicating that the client is not interested in problems.
      Returns:
      a shared working copy on this element using the given factory to create the buffer, or this element if this element is already a working copy
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      IWorkingCopy.getSharedWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
    • getWorkingCopy

      public IJavaElement getWorkingCopy() throws JavaModelException
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns 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.

      Note: if intending to share a working copy amongst several clients, then #getSharedWorkingCopy should be used instead.

      When the 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.

      Specified by:
      getWorkingCopy in interface IWorkingCopy
      Returns:
      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
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      IWorkingCopy.getWorkingCopy()
    • getWorkingCopy

      public ICompilationUnit getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 ICompilationUnit.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 ICompilationUnit.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.

      Specified by:
      getWorkingCopy in interface ICompilationUnit
      Parameters:
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      Returns:
      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
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      ICompilationUnit.getWorkingCopy(IProgressMonitor)
    • getWorkingCopy

      public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ITypeRoot
      Returns a shared working copy on this compilation unit or class file using the given working copy owner to create the buffer. If this is already a working copy of the given owner, the element itself is returned. This API can only answer an already existing working copy if it is based on the same original Java type root AND was using the same working copy owner (that is, as defined by Object.equals(java.lang.Object)).

      The life time of a shared working copy is as follows:

      So users of this method must discard exactly once the working copy.

      Note that the working copy owner will be used for the life time of the shared 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 Java type root content upon creation.

      When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.

      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.

      Note that possible problems of this working copy are reported using this method only if the given working copy owner returns a problem requestor for this working copy (see WorkingCopyOwner.getProblemRequestor(ICompilationUnit)).

      Specified by:
      getWorkingCopy in interface ITypeRoot
      Parameters:
      workingCopyOwner - the working copy owner that creates a buffer that is used to get the content of the working copy
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      Returns:
      a new working copy of this Java type root using the given owner to create the buffer, or this Java type root if it is already a working copy
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
    • getWorkingCopy

      public IJavaElement getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory, IProblemRequestor problemRequestor) throws JavaModelException
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns 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. Note that this factory will be used for the life time of this working copy, that is if the working copy is closed then reopened, this factory will be reused. The buffer will be automatically initialized with the original's compilation unit content upon creation.

      Note: if intending to share a working copy amongst several clients, then #getSharedWorkingCopy should be used instead.

      When the 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.

      Specified by:
      getWorkingCopy in interface IWorkingCopy
      Parameters:
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      factory - the factory that creates a buffer that is used to get the content of the working copy or null if the internal factory should be used
      problemRequestor - a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set to null indicating that the client is not interested in problems.
      Returns:
      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
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      IWorkingCopy.getWorkingCopy(IProgressMonitor, IBufferFactory, IProblemRequestor)
    • getWorkingCopy

      public ICompilationUnit getWorkingCopy(WorkingCopyOwner workingCopyOwner, IProblemRequestor problemRequestor, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Deprecated.
      Description copied from interface: ICompilationUnit
      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 by Object.equals(java.lang.Object)).

      The life time of a shared working copy is as follows:

      So users of this method must discard exactly once the working copy.

      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.

      Specified by:
      getWorkingCopy in interface ICompilationUnit
      Parameters:
      workingCopyOwner - the working copy owner that creates a buffer that is used to get the content of the working copy
      problemRequestor - a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set to null indicating that the client is not interested in problems.
      monitor - a progress monitor used to report progress while opening this compilation unit or null if no progress should be reported
      Returns:
      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
      Throws:
      JavaModelException - if the contents of this element can not be determined.
      See Also:
      ICompilationUnit.getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor)
    • hasBuffer

      protected boolean hasBuffer()
      Description copied from class: Openable
      Returns true if this element may have an associated source buffer, otherwise false. Subclasses must override as required.
      Overrides:
      hasBuffer in class Openable
      See Also:
      Openable.hasBuffer()
    • hasResourceChanged

      public boolean hasResourceChanged()
      Description copied from interface: ICompilationUnit
      Returns whether the resource of this working copy has changed since the inception of this working copy. Returns false if this compilation unit is not in working copy mode.
      Specified by:
      hasResourceChanged in interface ICompilationUnit
      Returns:
      whether the resource has changed
    • ignoreOptionalProblems

      public boolean ignoreOptionalProblems()
      Description copied from interface: ICompilationUnit
      Answer if optional problems should be ignored for this compilation unit. Implementors should return false if there is no preference.
      Specified by:
      ignoreOptionalProblems in interface ICompilationUnit
    • isBasedOn

      public boolean isBasedOn(org.eclipse.core.resources.IResource resource)
      Deprecated.
      Description copied from interface: IWorkingCopy
      Returns whether this working copy's original element's content has not changed since the inception of this working copy.
      Specified by:
      isBasedOn in interface IWorkingCopy
      Parameters:
      resource - this working copy's resource
      Returns:
      true if this working copy's original element's content has not changed since the inception of this working copy, false otherwise
      See Also:
      IWorkingCopy.isBasedOn(IResource)
    • isConsistent

      public boolean isConsistent()
      Description copied from class: Openable
      Subclasses must override as required.
      Specified by:
      isConsistent in interface IOpenable
      Overrides:
      isConsistent in class Openable
      Returns:
      true if the element is consistent with its underlying resource or buffer, false otherwise.
      See Also:
      IOpenable.isConsistent()
    • isPrimary

      public boolean isPrimary()
    • isSourceElement

      protected boolean isSourceElement()
      Description copied from class: Openable
      Returns true if this represents a source element. Openable source elements have an associated buffer created when they are opened.
      Overrides:
      isSourceElement in class Openable
      See Also:
      Openable.isSourceElement()
    • validateCompilationUnit

      protected org.eclipse.core.runtime.IStatus validateCompilationUnit(org.eclipse.core.resources.IResource resource)
    • isWorkingCopy

      public boolean isWorkingCopy()
      Description copied from interface: ICompilationUnit
      Returns whether this element is a working copy.
      Specified by:
      isWorkingCopy in interface ICompilationUnit
      Specified by:
      isWorkingCopy in interface IWorkingCopy
      Returns:
      true if this element is a working copy, false otherwise
    • makeConsistent

      public void makeConsistent(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: IOpenable
      Makes this element consistent with its underlying resource or buffer by updating the element's structure and properties as necessary.

      Note: Using this functionality on a working copy will interfere with any subsequent reconciling operation. Indeed, the next ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor) or ICompilationUnit.reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor) operation will not account for changes which occurred before an explicit use of IOpenable.makeConsistent(IProgressMonitor)

      Specified by:
      makeConsistent in interface IOpenable
      Overrides:
      makeConsistent in class Openable
      Parameters:
      monitor - the given progress monitor
      Throws:
      JavaModelException - if the element is unable to access the contents of its underlying resource. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      See Also:
      IOpenable.makeConsistent(IProgressMonitor)
    • makeConsistent

      public CompilationUnit makeConsistent(int astLevel, boolean resolveBindings, int reconcileFlags, HashMap problems, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Throws:
      JavaModelException
    • move

      public void move(IJavaElement container, IJavaElement sibling, String rename, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ISourceManipulation
      Moves this element to the given container.
      Specified by:
      move in interface ISourceManipulation
      Parameters:
      container - the container
      sibling - the sibling element before which the element should be inserted, or null if the element should be inserted as the last child of the container
      rename - the new name for the element, or null if the element retains its name
      force - true if any existing child in the container with the target name should be replaced, and false to throw an exception in the event of a name collision
      monitor - a progress monitor
      Throws:
      JavaModelException - if this element could not be moved. Reasons include:
      • This Java element, container element, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
      • A CoreException occurred while updating an underlying resource
      • The container is of an incompatible type (INVALID_DESTINATION)
      • The sibling is not a child of the given container (INVALID_SIBLING)
      • The new name is invalid (INVALID_NAME)
      • A child in the container already exists with the same name (NAME_COLLISION) and replace has been specified as false
      • The container or this element is read-only (READ_ONLY)
      See Also:
      ISourceManipulation.move(IJavaElement, IJavaElement, String, boolean, IProgressMonitor)
    • openBuffer

      protected IBuffer openBuffer(org.eclipse.core.runtime.IProgressMonitor pm, Object info) throws JavaModelException
      Description copied from class: Openable
      Opens a buffer on the contents of this element, and returns the buffer, or returns null if opening fails. By default, do nothing - subclasses that have buffers must override as required.
      Overrides:
      openBuffer in class Openable
      Throws:
      JavaModelException
      See Also:
      Openable.openBuffer(IProgressMonitor, Object)
    • openAncestors

      protected void openAncestors(HashMap newElements, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Overrides:
      openAncestors in class Openable
      Throws:
      JavaModelException
    • originalFromClone

      public CompilationUnit originalFromClone()
    • reconcile

      public org.eclipse.core.resources.IMarker[] reconcile() throws JavaModelException
      Deprecated.
      Description copied from interface: IWorkingCopy
      Reconciles the contents of this working copy. 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.

      If the working copy hasn't changed, then no problem will be detected, this is equivalent to IWorkingCopy#reconcile(false, null).

      Compilation problems found in the new contents are notified through the IProblemRequestor interface which was passed at creation, and no longer as transient markers. Therefore this API will return null.

      Note: Since 3.0 added/removed/changed inner types generate change deltas.

      Specified by:
      reconcile in interface IWorkingCopy
      Returns:
      null
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      See Also:
      IWorkingCopy.reconcile()
    • reconcile

      public void reconcile(boolean forceProblemDetection, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: IWorkingCopy
      Reconciles the contents of this working copy. 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.

      Compilation problems found in the new contents are notified through the IProblemRequestor interface which was passed at creation, and no longer as transient markers. Therefore this API answers nothing.

      Note: Since 3.0 added/removed/changed inner types generate change deltas.

      Specified by:
      reconcile in interface IWorkingCopy
      Parameters:
      forceProblemDetection - boolean indicating whether problem should be recomputed even if the source hasn't changed.
      monitor - a progress monitor
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      See Also:
      ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
    • reconcile

      public CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner workingCopyOwner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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, ICompilationUnit.reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor) must be use.

      Specified by:
      reconcile in interface ICompilationUnit
      Parameters:
      astLevel - either ICompilationUnit.NO_AST if no AST is wanted, or the AST API level of the AST if one is wanted
      forceProblemDetection - boolean indicating whether problem should be recomputed even if the source hasn't changed
      workingCopyOwner - the owner of working copies that take precedence over the original compilation units, or null if the primary working copy owner should be used
      monitor - a progress monitor
      Returns:
      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
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      Since:
      3.0
      See Also:
      ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
    • reconcile

      public CompilationUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner workingCopyOwner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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.

      Specified by:
      reconcile in interface ICompilationUnit
      Parameters:
      astLevel - either ICompilationUnit.NO_AST if no AST is wanted, or the AST API level of the AST if one is wanted
      forceProblemDetection - boolean indicating whether problem should be recomputed even if the source hasn't changed
      enableStatementsRecovery - if true statements recovery is enabled.
      workingCopyOwner - the owner of working copies that take precedence over the original compilation units, or null if the primary working copy owner should be used
      monitor - a progress monitor
      Returns:
      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
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      Since:
      3.0
      See Also:
      ICompilationUnit.reconcile(int, boolean, WorkingCopyOwner, IProgressMonitor)
    • reconcile

      public CompilationUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 ICompilationUnit.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 ICompilationUnit.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 ICompilationUnit.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 (ICompilationUnit.ENABLE_BINDINGS_RECOVERY, ICompilationUnit.ENABLE_STATEMENTS_RECOVERY, ICompilationUnit.FORCE_PROBLEM_DETECTION). Unspecified values are left for future use.

      Specified by:
      reconcile in interface ICompilationUnit
      Parameters:
      astLevel - either ICompilationUnit.NO_AST if no AST is wanted, or the AST API level of the AST if one is wanted
      reconcileFlags - the given reconcile flags
      workingCopyOwner - the owner of working copies that take precedence over the original compilation units, or null if the primary working copy owner should be used
      monitor - a progress monitor
      Returns:
      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
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      See Also:
      ICompilationUnit.FORCE_PROBLEM_DETECTION, ICompilationUnit.ENABLE_BINDINGS_RECOVERY, ICompilationUnit.ENABLE_STATEMENTS_RECOVERY
    • rename

      public void rename(String newName, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException
      Description copied from interface: ISourceManipulation
      Renames this element to the given name.
      Specified by:
      rename in interface ISourceManipulation
      Parameters:
      newName - the new name for the element
      force - true if any existing element with the target name should be replaced, and false to throw an exception in the event of a name collision
      monitor - a progress monitor
      Throws:
      JavaModelException - if this element could not be renamed. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • A CoreException occurred while updating an underlying resource
      • The new name is invalid (INVALID_NAME)
      • A child in the container already exists with the same name (NAME_COLLISION) and replace has been specified as false
      • This element is read-only (READ_ONLY)
      See Also:
      ISourceManipulation.rename(String, boolean, IProgressMonitor)
    • restore

      public void restore() throws JavaModelException
      Description copied from interface: ICompilationUnit
      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 ICompilationUnit.commitWorkingCopy(boolean, IProgressMonitor).

      Specified by:
      restore in interface ICompilationUnit
      Specified by:
      restore in interface IWorkingCopy
      Throws:
      JavaModelException - if the contents of the original element cannot be accessed. Reasons include:
      • The original Java element does not exist (ELEMENT_DOES_NOT_EXIST)
    • save

      public void save(org.eclipse.core.runtime.IProgressMonitor pm, boolean force) throws JavaModelException
      Description copied from interface: IOpenable
      Saves any changes in this element's buffer to its underlying resource via a workspace resource operation. This has no effect if the element has no underlying buffer, or if there are no unsaved changed in the buffer.

      The force parameter controls how this method deals with cases where the workbench is not completely in sync with the local file system. If false is specified, this method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workbench. This option ensures there is no unintended data loss; it is the recommended setting. However, if true is specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).

      As a result of this operation, the element is consistent with its underlying resource or buffer.

      Specified by:
      save in interface IOpenable
      Overrides:
      save in class Openable
      Parameters:
      pm - the given progress monitor
      force - it controls how this method deals with cases where the workbench is not completely in sync with the local file system
      Throws:
      JavaModelException - if an error occurs accessing the contents of its underlying resource. Reasons include:
      • This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
      • This Java element is read-only (READ_ONLY)
      See Also:
      IOpenable
    • toStringInfo

      protected void toStringInfo(int tab, StringBuffer buffer, Object info, boolean showResolvedInfo)
      Debugging purposes
      Overrides:
      toStringInfo in class JavaElement
      showResolvedInfo - TODO
    • updateTimeStamp

      protected void updateTimeStamp(CompilationUnit original) throws JavaModelException
      Throws:
      JavaModelException
    • validateExistence

      protected org.eclipse.core.runtime.IStatus validateExistence(org.eclipse.core.resources.IResource underlyingResource)
      Specified by:
      validateExistence in class Openable
    • getNameRange

      public ISourceRange getNameRange()
      Description copied from interface: ISourceReference
      Returns the name range associated with this element.

      If the element is an IMember, it returns the source range of this member's simple name, or null if this member does not have a name (for example, an initializer), or if this member does not have associated source code (for example, a binary type).

      If this element is an IImportDeclaration, the source range of this import declaration's name, or null if this import declaration does not have associated source code (for example, a binary type).
      The source range for the name includes the trailing '*' if the call to IImportDeclaration.isOnDemand() returns true.

      If this element is an IPackageDeclaration, the source range of this package declaration's name, or null if this package declaration does not have associated source code (for example, a binary type).

      If this element is an IAnnotation, the source range of this annotation's name, or null if this annotation does not have associated source code (for example, in a binary type).

      If this element is an ITypeParameter, the source range of this type parameter's name, or null if this type parameter does not have associated source code (for example, in a binary type).

      If this element is an ITypeRoot or IImportContainer, it returns null.

      Specified by:
      getNameRange in interface ISourceReference
      Returns:
      the name range associated with this element, or null if not available
    • getModule

      public IModuleDescription getModule() throws JavaModelException
      Description copied from interface: ITypeRoot
      Returns the module description contained in this type root or null if there is no module in this type root.

      Only subtype IModularClassFile promises to return non-null.

      Specified by:
      getModule in interface ITypeRoot
      Returns:
      the module description contained in the type root or null.
      Throws:
      JavaModelException
    • getModuleName

      public char[] getModuleName()
      Description copied from interface: ICompilationUnit
      Returns the name of the module to which this compilation unit is associated. A return value of null signals the unnamed module.
      Specified by:
      getModuleName in interface ICompilationUnit
      Returns:
      module name or null for the unnamed module.
    • setOptions

      public void setOptions(Map<String,​String> newOptions)
      Description copied from interface: ICompilationUnit
      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.

      Specified by:
      setOptions in interface ICompilationUnit
      Parameters:
      newOptions - the new custom options for this compilation unit
      See Also:
      JavaCore.setOptions(java.util.Hashtable)
    • getCustomOptions

      public Map<String,​String> getCustomOptions()
      Description copied from interface: ICompilationUnit
      Returns the table of the current custom options for this ICompilationUnit. If there is no setOptions called for the ICompliationUnit, then return an empty table.
      Specified by:
      getCustomOptions in interface ICompilationUnit
      Returns:
      the table of the current custom options for this ICompilationUnit