org.eclipse.wst.jsdt.core
Interface IJavaScriptUnit

All Superinterfaces:
ICodeAssist, IFunctionContainer, IJavaScriptElement, ILookupScope, IOpenable, IParent, ISourceManipulation, ISourceReference, ITypeRoot, IWorkingCopy

public interface IJavaScriptUnit
extends ITypeRoot, IWorkingCopy, ISourceManipulation

Represents an entire JavaScript file (source file with one of the JavaScript-like extensions). JavaScriptUnit elements need to be opened before they can be navigated or manipulated. The children are of type IPackageDeclaration, IImportContainer,IFunction,IField, and IType, and appear in the order in which they are declared in the source. If a source file cannot be parsed, its structure remains unknown. Use IJavaScriptElement.isStructureKnown() to determine whether this is the case.

This interface is not intended to be implemented by clients.

Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Field Summary
static int ENABLE_BINDINGS_RECOVERY
          Constant indicating that a reconcile operation should enable the bindings recovery
static int ENABLE_STATEMENTS_RECOVERY
          Constant indicating that a reconcile operation should enable the statements recovery.
static int FORCE_PROBLEM_DETECTION
          Constant indicating that a reconcile operation should recompute the problems even if the source hasn't changed.
static int NO_AST
          Constant indicating that a reconcile operation should not return an AST.
 
Fields inherited from interface org.eclipse.wst.jsdt.core.IJavaScriptElement
CLASS_FILE, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVASCRIPT_MODEL, JAVASCRIPT_PROJECT, JAVASCRIPT_UNIT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER
 
Method Summary
 void becomeWorkingCopy(IProblemRequestor problemRequestor, IProgressMonitor monitor)
          Deprecated. Use becomeWorkingCopy(IProgressMonitor) instead. Note that if this deprecated method is used, problems will be reported to the given problem requestor as well as the problem requestor returned by the working copy owner (if not null).
 void becomeWorkingCopy(IProgressMonitor monitor)
          Changes this javaScript file handle into a working copy.
 void commitWorkingCopy(boolean force, IProgressMonitor monitor)
          Commits the contents of this working copy to its underlying resource.
 IField createField(java.lang.String contents, IJavaScriptElement sibling, boolean force, IProgressMonitor monitor)
          Creates and returns a var in this javaScript file with the given contents.
 IImportDeclaration createImport(java.lang.String name, IJavaScriptElement sibling, int flags, IProgressMonitor monitor)
          Creates and returns an import declaration in this javaScript file with the given name.
 IImportDeclaration createImport(java.lang.String name, IJavaScriptElement sibling, IProgressMonitor monitor)
          Creates and returns an non-static import declaration in this javaScript file with the given name.
 IFunction createMethod(java.lang.String contents, IJavaScriptElement sibling, boolean force, IProgressMonitor monitor)
          Creates and returns a function in this javaScript file with the given contents.
 IPackageDeclaration createPackageDeclaration(java.lang.String name, IProgressMonitor monitor)
          Creates and returns a package declaration in this javaScript file with the given package name.
 IType createType(java.lang.String contents, IJavaScriptElement sibling, boolean force, IProgressMonitor monitor)
          Creates and returns a type in this javaScript file with the given contents.
 void discardWorkingCopy()
          Changes this javaScript file in working copy mode back to its original mode.
 IJavaScriptElement[] findElements(IJavaScriptElement element)
          Finds the elements in this javaScript file that correspond to the given element.
 IFunction[] findFunctions(IFunction function)
          Finds the function in this javaScript file that correspond to the given function.
 IJavaScriptUnit findWorkingCopy(WorkingCopyOwner owner)
          Finds the working copy for this javaScript file, given a WorkingCopyOwner.
 IType[] getAllTypes()
          Returns all types declared in this javaScript file in the order in which they appear in the source.
 IImportDeclaration getImport(java.lang.String name)
          Returns the first import declaration in this javaScript file with the given name.
 IImportContainer getImportContainer()
          Returns the import container for this javaScript file.
 IImportDeclaration[] getImports()
          Returns the import declarations in this javaScript file in the order in which they appear in the source.
 WorkingCopyOwner getOwner()
          Returns the working copy owner of this working copy.
 IPackageDeclaration getPackageDeclaration(java.lang.String name)
          Returns the first package declaration in this javaScript file with the given package name (there normally is at most one package declaration).
 IPackageDeclaration[] getPackageDeclarations()
          Returns the package declarations in this javaScript file in the order in which they appear in the source.
 IJavaScriptUnit getPrimary()
          Returns the primary javaScript file (whose owner is the primary owner) this working copy was created from, or this javaScript file if this a primary javaScript file.
 IType[] getTypes()
          Returns the top-level types declared in this javaScript file in the order in which they appear in the source.
 IJavaScriptUnit getWorkingCopy(IProgressMonitor monitor)
          Returns a new working copy of this javaScript file if it is a primary javaScript file, or this javaScript file if it is already a non-primary working copy.
 IJavaScriptUnit getWorkingCopy(WorkingCopyOwner owner, IProblemRequestor problemRequestor, IProgressMonitor monitor)
          Deprecated. Use ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor) instead. Note that if this deprecated method is used, problems will be reported on the passed problem requester as well as on the problem requestor returned by the working copy owner (if not null).
 boolean hasResourceChanged()
          Returns whether the resource of this working copy has changed since the inception of this working copy.
 boolean isWorkingCopy()
          Returns whether this element is a working copy.
 JavaScriptUnit reconcile(int astLevel, boolean forceProblemDetection, boolean enableStatementsRecovery, WorkingCopyOwner owner, IProgressMonitor monitor)
          Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file AST if requested.
 JavaScriptUnit reconcile(int astLevel, boolean forceProblemDetection, WorkingCopyOwner owner, IProgressMonitor monitor)
          Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file AST if requested.
 JavaScriptUnit reconcile(int astLevel, int reconcileFlags, WorkingCopyOwner owner, IProgressMonitor monitor)
          Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file AST if requested.
 void restore()
          Restores the contents of this working copy to the current contents of this working copy's original element.
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ITypeRoot
findPrimaryType, getElementAt, getWorkingCopy
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IJavaScriptElement
exists, getAncestor, getAttachedJavadoc, getCommonSuperType, getCorrespondingResource, getDisplayName, getElementName, getElementType, getHandleIdentifier, getHostPath, getJavaScriptModel, getJavaScriptProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown, isVirtual
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ILookupScope
newNameLookup, newNameLookup, newSearchableNameEnvironment, newSearchableNameEnvironment
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IParent
getChildren, hasChildren
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IOpenable
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ISourceReference
exists, getSource, getSourceRange
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ICodeAssist
codeComplete, codeComplete, codeSelect, codeSelect
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IFunctionContainer
getField, getFields, getFunction, getFunctions, getMethods, getType
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IWorkingCopy
commit, destroy, findPrimaryType, findSharedWorkingCopy, getOriginal, getOriginalElement, getSharedWorkingCopy, getWorkingCopy, getWorkingCopy, isBasedOn, reconcile, reconcile
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ISourceManipulation
copy, delete, move, rename
 

Field Detail

NO_AST

static final int NO_AST
Constant indicating that a reconcile operation should not return an AST.

See Also:
Constant Field Values

FORCE_PROBLEM_DETECTION

static final int FORCE_PROBLEM_DETECTION
Constant indicating that a reconcile operation should recompute the problems even if the source hasn't changed.

See Also:
Constant Field Values

ENABLE_STATEMENTS_RECOVERY

static final int ENABLE_STATEMENTS_RECOVERY
Constant indicating that a reconcile operation should enable the statements recovery.

See Also:
ASTParser.setStatementsRecovery(boolean), Constant Field Values

ENABLE_BINDINGS_RECOVERY

static final int ENABLE_BINDINGS_RECOVERY
Constant indicating that a reconcile operation should enable the bindings recovery

See Also:
ASTParser.setBindingsRecovery(boolean), IBinding.isRecovered(), Constant Field Values
Method Detail

becomeWorkingCopy

void becomeWorkingCopy(IProblemRequestor problemRequestor,
                       IProgressMonitor monitor)
                       throws JavaScriptModelException
Deprecated. Use becomeWorkingCopy(IProgressMonitor) instead. Note that if this deprecated method is used, problems will be reported to the given problem requestor as well as the problem requestor returned by the working copy owner (if not null).

Changes this javaScript file handle into a working copy. A new IBuffer is created using this javaScript file handle's owner. Uses the primary owner is none was specified when this javaScript file 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 javaScript file or its children are done in memory. Only the new buffer is affected. Using commitWorkingCopy(boolean, IProgressMonitor) will bring the underlying resource in sync with this javaScript file.

If this javaScript file was already in working copy mode, an internal counter is incremented and no other action is taken on this javaScript file. To bring this javaScript file back into the original mode (where it reflects the underlying resource), discardWorkingCopy() must be call as many times as becomeWorkingCopy(IProblemRequestor, IProgressMonitor).

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 javaScript file or null if no progress should be reported
Throws:
JavaScriptModelException - if this javaScript file could not become a working copy.
See Also:
discardWorkingCopy()

becomeWorkingCopy

void becomeWorkingCopy(IProgressMonitor monitor)
                       throws JavaScriptModelException
Changes this javaScript file handle into a working copy. A new IBuffer is created using this javaScript file handle's owner. Uses the primary owner if none was specified when this javaScript file 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 javaScript file or its children are done in memory. Only the new buffer is affected. Using commitWorkingCopy(boolean, IProgressMonitor) will bring the underlying resource in sync with this javaScript file.

If this javaScript file was already in working copy mode, an internal counter is incremented and no other action is taken on this javaScript file. To bring this javaScript file back into the original mode (where it reflects the underlying resource), discardWorkingCopy() must be call as many times as becomeWorkingCopy(IProblemRequestor, IProgressMonitor).

Parameters:
monitor - a progress monitor used to report progress while opening this javaScript file or null if no progress should be reported
Throws:
JavaScriptModelException - if this javaScript file could not become a working copy.
See Also:
discardWorkingCopy()

commitWorkingCopy

void commitWorkingCopy(boolean force,
                       IProgressMonitor monitor)
                       throws JavaScriptModelException
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 effects the resolution of such a conflict:

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:
JavaScriptModelException - if this working copy could not commit. Reasons include:
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • This element is not a working copy (INVALID_ELEMENT_TYPES)
  • A update conflict (described above) (UPDATE_CONFLICT)

createImport

IImportDeclaration createImport(java.lang.String name,
                                IJavaScriptElement sibling,
                                IProgressMonitor monitor)
                                throws JavaScriptModelException
Creates and returns an non-static import declaration in this javaScript file with the given name. This method is equivalent to createImport(name, Flags.AccDefault, sibling, monitor).

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
name - the name of the import declaration to add
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:
JavaScriptModelException - if the element could not be created. Reasons include:
  • This JavaScript element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The specified sibling is not a child of this javaScript file (INVALID_SIBLING)
  • The name is not a valid import name (INVALID_NAME)
See Also:
createImport(String, IJavaScriptElement, int, IProgressMonitor)

createImport

IImportDeclaration createImport(java.lang.String name,
                                IJavaScriptElement sibling,
                                int flags,
                                IProgressMonitor monitor)
                                throws JavaScriptModelException
Creates and returns an import declaration in this javaScript file 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 javaScript file.

If the javaScript file already includes the specified import declaration, the import is not generated (it does not generate duplicates).

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
name - the name of the import declaration
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:
JavaScriptModelException - if the element could not be created. Reasons include:
  • This JavaScript element does not exist or the specified sibling does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The specified sibling is not a child of this javaScript file (INVALID_SIBLING)
  • The name is not a valid import name (INVALID_NAME)
See Also:
Flags

createPackageDeclaration

IPackageDeclaration createPackageDeclaration(java.lang.String name,
                                             IProgressMonitor monitor)
                                             throws JavaScriptModelException
Creates and returns a package declaration in this javaScript file with the given package name.

If the javaScript file already includes the specified package declaration, it is not generated (it does not generate duplicates).

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
name - the name of the package declaration to add
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:
JavaScriptModelException - if the element could not be created. Reasons include:
  • This JavaScript element does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The name is not a valid package name (INVALID_NAME)

createType

IType createType(java.lang.String contents,
                 IJavaScriptElement sibling,
                 boolean force,
                 IProgressMonitor monitor)
                 throws JavaScriptModelException
Creates and returns a type in this javaScript file with the given contents. If this javaScript file 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 javaScript file.

It is possible that a type with the same name already exists in this javaScript file. The value of the force parameter effects the resolution of such a conflict:

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
contents - 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:
JavaScriptModelException - if the element could not be created. Reasons include:
  • The specified sibling element does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The specified sibling is not a child of this javaScript file (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)

createField

IField createField(java.lang.String contents,
                   IJavaScriptElement sibling,
                   boolean force,
                   IProgressMonitor monitor)
                   throws JavaScriptModelException
Creates and returns a var in this javaScript file with the given contents. If this javaScript file does not exist, one will be created with an appropriate package declaration.

Optionally, the new var can be positioned before the specified sibling. If sibling is null, the var will be appended to the end of this javaScript file.

It is possible that a var with the same name already exists in this javaScript file. The value of the force parameter effects the resolution of such a conflict:

Parameters:
contents - the source contents of the var declaration to add.
sibling - the existing element which the var will be inserted immediately before (if null, then this var will be inserted as the last var declaration.
force - a boolean flag indicating how to deal with duplicates
monitor - the progress monitor to notify
Returns:
the newly inserted var
Throws:
JavaScriptModelException - if the element could not be created. Reasons include:
  • The specified sibling element does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The specified sibling is not a child of this javaScript file (INVALID_SIBLING)
  • The contents could not be recognized as a var declaration (INVALID_CONTENTS)
  • There was a naming collision with an existing var (NAME_COLLISION)

createMethod

IFunction createMethod(java.lang.String contents,
                       IJavaScriptElement sibling,
                       boolean force,
                       IProgressMonitor monitor)
                       throws JavaScriptModelException
Creates and returns a function in this javaScript file with the given contents. If this javaScript file does not exist, one will be created with an appropriate package declaration.

Optionally, the new function can be positioned before the specified sibling. If sibling is null, the function will be appended to the end of this javaScript file.

It is possible that a function with the same name already exists in this javaScript file. The value of the force parameter effects the resolution of such a conflict:

Parameters:
contents - the source contents of the function declaration to add.
sibling - the existing element which the function will be inserted immediately before (if null, then this function will be inserted as the last function declaration.
force - a boolean flag indicating how to deal with duplicates
monitor - the progress monitor to notify
Returns:
the newly inserted function
Throws:
JavaScriptModelException - if the element could not be created. Reasons include:
  • The specified sibling element does not exist (ELEMENT_DOES_NOT_EXIST)
  • A org.eclipse.core.runtime.CoreException occurred while updating an underlying resource
  • The specified sibling is not a child of this javaScript file (INVALID_SIBLING)
  • The contents could not be recognized as a function declaration (INVALID_CONTENTS)
  • There was a naming collision with an existing function (NAME_COLLISION)

discardWorkingCopy

void discardWorkingCopy()
                        throws JavaScriptModelException
Changes this javaScript file in working copy mode back to its original mode.

This has no effect if this javaScript file was not in working copy mode.

If becomeWorkingCopy(org.eclipse.wst.jsdt.core.IProblemRequestor, IProgressMonitor) was called several times on this javaScript file, discardWorkingCopy() must be called as many times before it switches back to the original mode.

Throws:
JavaScriptModelException - if this working copy could not return in its original mode.
See Also:
becomeWorkingCopy(IProblemRequestor, IProgressMonitor)

findElements

IJavaScriptElement[] findElements(IJavaScriptElement element)
Finds the elements in this javaScript file that correspond to the given element. An element A corresponds to an element B if: Returns null if no such javaScript elements can be found or if the given element is not included in a javaScript file.

Specified by:
findElements in interface IWorkingCopy
Parameters:
element - the given element
Returns:
the found elements in this javaScript file that correspond to the given element

findWorkingCopy

IJavaScriptUnit findWorkingCopy(WorkingCopyOwner owner)
Finds the working copy for this javaScript file, given a WorkingCopyOwner. If no working copy has been created for this javaScript file associated with this working copy owner, returns null.

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

Parameters:
owner - the given WorkingCopyOwner
Returns:
the found working copy for this javaScript file, null if none
See Also:
WorkingCopyOwner

getAllTypes

IType[] getAllTypes()
                    throws JavaScriptModelException
Returns all types declared in this javaScript file 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).

Returns:
the array of top-level and member types defined in a javaScript file, in declaration order.
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource

getImport

IImportDeclaration getImport(java.lang.String name)
Returns the first import declaration in this javaScript file 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 javaScript file's import container.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
name - the name of the import to find
Returns:
a handle onto the corresponding import declaration. The import declaration may or may not exist.

getImportContainer

IImportContainer getImportContainer()
Returns the import container for this javaScript file. This is a handle-only method. The import container may or may not exist. The import container can used to access the imports.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Returns:
a handle onto the corresponding import container. The import contain may or may not exist.

getImports

IImportDeclaration[] getImports()
                                throws JavaScriptModelException
Returns the import declarations in this javaScript file in the order in which they appear in the source. This is a convenience method - import declarations can also be accessed from a javaScript file's import container.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Returns:
the import declarations in this javaScript file
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource

getPrimary

IJavaScriptUnit getPrimary()
Returns the primary javaScript file (whose owner is the primary owner) this working copy was created from, or this javaScript file if this a primary javaScript file.

Note that the returned primary javaScript file can be in working copy mode.

Returns:
the primary javaScript file this working copy was created from, or this javaScript file if it is primary

getOwner

WorkingCopyOwner getOwner()
Returns the working copy owner of this working copy. Returns null if it is not a working copy or if it has no owner.

Returns:
WorkingCopyOwner the owner of this working copy or null

getPackageDeclaration

IPackageDeclaration getPackageDeclaration(java.lang.String name)
Returns the first package declaration in this javaScript file 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.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Parameters:
name - the name of the package declaration
Returns:
the first package declaration in this javaScript file with the given package name

getPackageDeclarations

IPackageDeclaration[] getPackageDeclarations()
                                             throws JavaScriptModelException
Returns the package declarations in this javaScript file in the order in which they appear in the source. There normally is at most one package declaration.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Returns:
an array of package declaration (normally of size one)
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource

getTypes

IType[] getTypes()
                 throws JavaScriptModelException
Returns the top-level types declared in this javaScript file in the order in which they appear in the source.

Note: This Method only applies to ECMAScript 4 which is not yet supported

Returns:
the top-level types declared in this javaScript file
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource

getWorkingCopy

IJavaScriptUnit getWorkingCopy(IProgressMonitor monitor)
                               throws JavaScriptModelException
Returns a new working copy of this javaScript file if it is a primary javaScript file, or this javaScript file if it is already a non-primary working copy.

Note: if intending to share a working copy amongst several clients, then getWorkingCopy(WorkingCopyOwner, IProblemRequestor, IProgressMonitor) should be used instead.

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

Once done with the working copy, users of this method must discard it using discardWorkingCopy().

Since 2.1, a working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding javaScript file.

Parameters:
monitor - a progress monitor used to report progress while opening this javaScript file 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:
JavaScriptModelException - if the contents of this element can not be determined.

getWorkingCopy

IJavaScriptUnit getWorkingCopy(WorkingCopyOwner owner,
                               IProblemRequestor problemRequestor,
                               IProgressMonitor monitor)
                               throws JavaScriptModelException
Deprecated. Use ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor) instead. Note that if this deprecated method is used, problems will be reported on the passed problem requester as well as on the problem requestor returned by the working copy owner (if not null).

Returns a shared working copy on this javaScript file using the given working copy owner to create the buffer, or this javaScript file 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 javaScript file 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 javaScript file content upon creation.

When the shared working copy instance is created, an ADDED IJavaScriptElementDelta 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 javaScript file.

Parameters:
owner - 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 javaScript file 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:
JavaScriptModelException - if the contents of this element can not be determined.

hasResourceChanged

boolean hasResourceChanged()
Returns whether the resource of this working copy has changed since the inception of this working copy. Returns false if this javaScript file is not in working copy mode.

Returns:
whether the resource has changed

isWorkingCopy

boolean isWorkingCopy()
Returns whether this element is a working copy.

Specified by:
isWorkingCopy in interface IWorkingCopy
Returns:
true if this element is a working copy, false otherwise

reconcile

JavaScriptUnit reconcile(int astLevel,
                         boolean forceProblemDetection,
                         WorkingCopyOwner owner,
                         IProgressMonitor monitor)
                         throws JavaScriptModelException
Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file 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 javaScript files. 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 javaScript file is returned. Its bindings are computed only if the problem requestor is active, or if the problem detection is forced. This method returns null if the creation of the DOM AST was not requested, or if the requested level of AST API is not supported, or if the working copy was already consistent.

This method doesn't perform statements recovery. To recover statements with syntax errors, reconcile(int, boolean, boolean, WorkingCopyOwner, IProgressMonitor) must be use.

Parameters:
astLevel - either 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
owner - the owner of working copies that take precedence over the original javaScript files, or null if the primary working copy owner should be used
monitor - a progress monitor
Returns:
the javaScript file AST or null if not requested, or if the requested level of AST API is not supported, or if the working copy was consistent
Throws:
JavaScriptModelException - if the contents of the original element cannot be accessed. Reasons include:
  • The original JavaScript element does not exist (ELEMENT_DOES_NOT_EXIST)

reconcile

JavaScriptUnit reconcile(int astLevel,
                         boolean forceProblemDetection,
                         boolean enableStatementsRecovery,
                         WorkingCopyOwner owner,
                         IProgressMonitor monitor)
                         throws JavaScriptModelException
Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file 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 javaScript files. 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 javaScript file is returned. Its bindings are computed only if the problem requestor is active, or if the problem detection is forced. This method returns null if the creation of the DOM AST was not requested, or if the requested level of AST API is not supported, or if the working copy was already consistent.

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.

Parameters:
astLevel - either 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.
owner - the owner of working copies that take precedence over the original javaScript files, or null if the primary working copy owner should be used
monitor - a progress monitor
Returns:
the javaScript file AST or null if not requested, or if the requested level of AST API is not supported, or if the working copy was consistent
Throws:
JavaScriptModelException - if the contents of the original element cannot be accessed. Reasons include:
  • The original JavaScript element does not exist (ELEMENT_DOES_NOT_EXIST)

reconcile

JavaScriptUnit reconcile(int astLevel,
                         int reconcileFlags,
                         WorkingCopyOwner owner,
                         IProgressMonitor monitor)
                         throws JavaScriptModelException
Reconciles the contents of this working copy, sends out a JavaScript 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 javaScript file AST if requested.

If the problem detection is forced by passing the FORCE_PROBLEM_DETECTION bit in the given reconcile flag, problem detection is run even if the working copy is already consistent.

It performs the reconciliation by locally caching the contents of the working copy, updating the contents, then creating a delta over the cached contents and the new contents, and finally firing this delta.

This functionality allows to specify a working copy owner which is used during problem detection. All references contained in the working copy are resolved against other units; for which corresponding owned working copies are going to take precedence over their original javaScript files. 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 javaScript file is returned. Its bindings are computed only if the problem requestor is active, or if the problem detection is forced. This method returns null if the creation of the DOM AST was not requested, or if the requested level of AST API is not supported, or if the working copy was already consistent.

If statements recovery is enabled by passing the ENABLE_STATEMENTS_RECOVERY bit in the given reconcile flag then this method tries to rebuild statements with syntax error. Otherwise statements with syntax error won't be present in the returning DOM AST.

If bindings recovery is enabled by passing the ENABLE_BINDINGS_RECOVERY bit in the given reconcile flag then this method tries to resolve bindings even if the type resolution contains errors.

The given reconcile flags is a bit-mask of the different constants (ENABLE_BINDINGS_RECOVERY, ENABLE_STATEMENTS_RECOVERY, FORCE_PROBLEM_DETECTION). Unspecified values are left for future use.

Parameters:
astLevel - either NO_AST if no AST is wanted, or the AST API level of the AST if one is wanted
reconcileFlags - the given reconcile flags
owner - the owner of working copies that take precedence over the original javaScript files, or null if the primary working copy owner should be used
monitor - a progress monitor
Returns:
the javaScript file AST or null if not requested, or if the requested level of AST API is not supported, or if the working copy was consistent
Throws:
JavaScriptModelException - if the contents of the original element cannot be accessed. Reasons include:
  • The original JavaScript element does not exist (ELEMENT_DOES_NOT_EXIST)
See Also:
FORCE_PROBLEM_DETECTION, ENABLE_BINDINGS_RECOVERY, ENABLE_STATEMENTS_RECOVERY

restore

void restore()
             throws JavaScriptModelException
Restores the contents of this working copy to the current contents of this working copy's original element. Has no effect if this element is not a working copy.

Note: This is the inverse of committing the content of the working copy to the original element with commitWorkingCopy(boolean, IProgressMonitor).

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

findFunctions

IFunction[] findFunctions(IFunction function)
Finds the function in this javaScript file that correspond to the given function. Returns null if no such function can be found or if the given element is not included in a javaScript file.

Parameters:
function - the given function
Returns:
the found functions in this javaScript file that correspond to the given function