org.eclipse.wst.jsdt.core

## Interface IJavaScriptModel

All Superinterfaces:
  IJavaScriptElement, ILookupScope, IOpenable, IParent

    public interface IJavaScriptModel
    extends IJavaScriptElement, IOpenable, IParent

Represent the root JavaScript element corresponding to the workspace. Since there is only one such root element, it is commonly referred to as the JavaScript model element. The JavaScript model element needs to be opened before it can be navigated or manipulated. The JavaScript model element has no parent (it is the root of the JavaScript element hierarchy). Its children are `IJavaScriptProject`s.

This interface provides methods for performing copy, move, rename, and delete operations on multiple JavaScript elements.

This interface is not intended to be implemented by clients. An instance of one of these handles can be created via `JavaScriptCore.create(workspace.getRoot())`.

See Also:
  `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

### Fields inherited from interface org.eclipse.wst.jsdt.core.IJavaScriptElement

`CLASS_FILE, EXPORT_CONTAINER, EXPORT_DECLARATION, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVASCRIPT_MODEL, JAVASCRIPT_PROJECT, JAVASCRIPT_UNIT, LOCAL_VARIABLE, METHOD, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE`

### Method Summary

All Methods Instance Methods Abstract Methods
`boolean` `contains(IResource resource)` Returns whether this JavaScript model contains an `IJavaScriptElement` whose resource is the given resource or a non-JavaScript resource which is the given resource.
`void` `copy(IJavaScriptElement[] elements, IJavaScriptElement[] containers, IJavaScriptElement[] siblings, java.lang.String[] renamings, boolean replace, IProgressMonitor monitor)` Copies the given elements to the specified container(s).
`void` `delete(IJavaScriptElement[] elements, boolean force, IProgressMonitor monitor)` Deletes the given elements, forcing the operation if necessary and specified.
`IJavaScriptProject` `getJavaScriptProject(java.lang.String name)` Returns the JavaScript project with the given name.
`IJavaScriptProject[]` `getJavaScriptProjects()` Returns the JavaScript projects in this JavaScript model, or an empty array if there are none.
`java.lang.Object[]` `getNonJavaScriptResources()` Returns an array of non-JavaScript resources (that is, non-JavaScript projects) in the workspace.
`IWorkspace` `getWorkspace()` Returns the workspace associated with this JavaScript model.
`void` `move(IJavaScriptElement[] elements, IJavaScriptElement[] containers, IJavaScriptElement[] siblings, java.lang.String[] renamings, boolean replace, IProgressMonitor monitor)` Moves the given elements to the specified container(s).
`void` `refreshExternalArchives(IJavaScriptElement[] elementsScope, IProgressMonitor monitor)` Triggers an update of the JavaScriptModel with respect to the referenced external archives.
`void` `rename(IJavaScriptElement[] elements, IJavaScriptElement[] destinations, java.lang.String[] names, boolean replace, IProgressMonitor monitor)` Renames the given elements as specified.

### 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.IOpenable

`close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save`

### Methods inherited from interface org.eclipse.wst.jsdt.core.IParent

`getChildren, hasChildren`

### Method Detail

#### contains

    boolean contains(IResource resource)

Returns whether this JavaScript model contains an `IJavaScriptElement` whose resource is the given resource or a non-JavaScript resource which is the given resource.

Note: no existency check is performed on the argument resource. If it is not accessible (see `IResource.isAccessible()`) yet but would be located in JavaScript model range, then it will return `true`.

If the resource is accessible, it can be reached by navigating the JavaScript model down using the `getChildren()` and/or `getNonJavaResources()` methods.

Parameters:
  `resource` - the resource to check
Returns:
  true if the resource is accessible through the JavaScript model

#### copy

    void copy(IJavaScriptElement[] elements,
              IJavaScriptElement[] containers,
              IJavaScriptElement[] siblings,
              java.lang.String[] renamings,
              boolean replace,
              IProgressMonitor monitor)
       throws JavaScriptModelException

Copies the given elements to the specified container(s). If one container is specified, all elements are copied to that container. If more than one container is specified, the number of elements and containers must match, and each element is copied to its associated container.

Optionally, each copy can positioned before a sibling element. If `null` is specified for a given sibling, the copy is inserted as the last child of its associated container.

Optionally, each copy can be renamed. If `null` is specified for the new name, the copy is not renamed.

Optionally, any existing child in the destination container with the same name can be replaced by specifying `true` for force. Otherwise an exception is thrown in the event that a name collision occurs.

Parameters:
  `elements` - the elements to copy
  `containers` - the container, or list of containers
  `siblings` - the list of siblings element any of which may be `null`; or `null`
  `renamings` - the list of new names any of which may be `null`; or `null`
  `replace` - `true` if any existing child in a target 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:
  `JavaScriptModelException` - if an element could not be copied. Reasons include:
  - There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
  - A specified element, container, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
  - A `CoreException` occurred while updating an underlying resource
  - A container is of an incompatible type (`INVALID_DESTINATION`)
  - A sibling is not a child of it associated container (`INVALID_SIBLING`)
  - A new name is invalid (`INVALID_NAME`)
  - A child in its associated container already exists with the same name and `replace` has been specified as `false` (`NAME_COLLISION`)
  - A container or element is read-only (`READ_ONLY`)

#### delete

    void delete(IJavaScriptElement[] elements,
                boolean force,
                IProgressMonitor monitor)
         throws JavaScriptModelException

Deletes the given elements, forcing the operation if necessary and specified.

Parameters:
  `elements` - the elements to delete
  `force` - a flag controlling whether underlying resources that are not in sync with the local file system will be tolerated
  `monitor` - a progress monitor
Throws:
  `JavaScriptModelException` - if an element could not be deleted. Reasons include:
  - There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
  - A specified element does not exist (ELEMENT_DOES_NOT_EXIST)
  - A `CoreException` occurred while updating an underlying resource
  - An element is read-only (`READ_ONLY`)

#### getJavaScriptProject

    IJavaScriptProject getJavaScriptProject(java.lang.String name)

Returns the JavaScript project with the given name. This is a handle-only method. The project may or may not exist.

Parameters:
  `name` - the name of the JavaScript project
Returns:
  the JavaScript project with the given name

#### getJavaScriptProjects

    IJavaScriptProject[] getJavaScriptProjects()
                                        throws JavaScriptModelException

Returns the JavaScript projects in this JavaScript model, or an empty array if there are none.

Returns:
  the JavaScript projects in this JavaScript model, or an empty array if there are none
Throws:
  `JavaScriptModelException` - if this request fails.

#### getNonJavaScriptResources

    java.lang.Object[] getNonJavaScriptResources()
                                          throws JavaScriptModelException

Returns an array of non-JavaScript resources (that is, non-JavaScript projects) in the workspace.

Non-JavaScript projects include all projects that are closed (even if they have the JavaScript nature).

Returns:
  an array of non-JavaScript projects (`IProject`s) contained in the workspace.
Throws:
  `JavaScriptModelException` - if this element does not exist or if an exception occurs while accessing its corresponding resource

#### getWorkspace

    IWorkspace getWorkspace()

Returns the workspace associated with this JavaScript model.

Returns:
  the workspace associated with this JavaScript model

#### move

    void move(IJavaScriptElement[] elements,
              IJavaScriptElement[] containers,
              IJavaScriptElement[] siblings,
              java.lang.String[] renamings,
              boolean replace,
              IProgressMonitor monitor)
       throws JavaScriptModelException

Moves the given elements to the specified container(s). If one container is specified, all elements are moved to that container. If more than one container is specified, the number of elements and containers must match, and each element is moved to its associated container.

Optionally, each element can positioned before a sibling element. If `null` is specified for sibling, the element is inserted as the last child of its associated container.

Optionally, each element can be renamed. If `null` is specified for the new name, the element is not renamed.

Optionally, any existing child in the destination container with the same name can be replaced by specifying `true` for force. Otherwise an exception is thrown in the event that a name collision occurs.

Parameters:
  `elements` - the elements to move
  `containers` - the container, or list of containers
  `siblings` - the list of siblings element any of which may be `null`; or `null`
  `renamings` - the list of new names any of which may be `null`; or `null`
  `replace` - `true` if any existing child in a target 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:
  `JavaScriptModelException` - if an element could not be moved. Reasons include:
  - There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
  - A specified element, container, or sibling does not exist (ELEMENT_DOES_NOT_EXIST)
  - A `CoreException` occurred while updating an underlying resource
  - A container is of an incompatible type (`INVALID_DESTINATION`)
  - A sibling is not a child of it associated container (`INVALID_SIBLING`)
  - A new name is invalid (`INVALID_NAME`)
  - A child in its associated container already exists with the same name and `replace` has been specified as `false` (`NAME_COLLISION`)
  - A container or element is read-only (`READ_ONLY`)
  `java.lang.IllegalArgumentException` - any element or container is `null`

#### refreshExternalArchives

    void refreshExternalArchives(IJavaScriptElement[] elementsScope,
                                 IProgressMonitor monitor)
                          throws JavaScriptModelException

Triggers an update of the JavaScriptModel with respect to the referenced external archives. This operation will issue a JavaScriptModel delta describing the discovered changes, in term of JavaScript element package fragment roots added, removed or changed. Note that a collection of elements can be passed so as to narrow the set of archives to refresh (passing `null` along is equivalent to refreshing the entire mode). The elements can be:

- package fragment roots corresponding to external archives
- JavaScript projects, which referenced external archives will be refreshed
- JavaScript model, all referenced external archives will be refreshed.

In case an archive is used by multiple projects, the delta issued will account for all of them. This means that even if a project was not part of the elements scope, it may still be notified of changes if it is referencing a library comprised in the scope.

Parameters:
  `elementsScope` - - a collection of elements defining the scope of the refresh
  `monitor` - - a progress monitor used to report progress
Throws:
  `JavaScriptModelException` - in one of the corresponding situation:
  - an exception occurs while accessing project resources
See Also:
  `IJavaScriptElementDelta`

#### rename

    void rename(IJavaScriptElement[] elements,
                IJavaScriptElement[] destinations,
                java.lang.String[] names,
                boolean replace,
                IProgressMonitor monitor)
         throws JavaScriptModelException

Renames the given elements as specified. If one container is specified, all elements are renamed within that container. If more than one container is specified, the number of elements and containers must match, and each element is renamed within its associated container.

Parameters:
  `elements` - the elements to rename
  `destinations` - the container, or list of containers
  `names` - the list of new names
  `replace` - `true` if an existing child in a target 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:
  `JavaScriptModelException` - if an element could not be renamed. Reasons include:
  - There is no element to process (NO_ELEMENTS_TO_PROCESS). The given elements is null or empty
  - A specified element does not exist (ELEMENT_DOES_NOT_EXIST)
  - A `CoreException` occurred while updating an underlying resource
  - A new name is invalid (`INVALID_NAME`)
  - A child already exists with the same name and `replace` has been specified as `false` (`NAME_COLLISION`)
  - An element is read-only (`READ_ONLY`)