org.eclipse.wst.jsdt.core
Class WorkingCopyOwner

java.lang.Object
  extended by org.eclipse.wst.jsdt.core.WorkingCopyOwner

public abstract class WorkingCopyOwner
extends java.lang.Object

The owner of an IJavaScriptUnit handle in working copy mode. An owner is used to identify a working copy and to create its buffer.

Clients should subclass this class to instantiate a working copy owner that is specific to their need and that they can pass in to various APIs (e.g. IType.resolveType(String, WorkingCopyOwner). Clients can also override the default implementation of createBuffer(IJavaScriptUnit).

Note: even though this class has no abstract method, which means that it provides functional default behavior, it is still an abstract class, as clients are intended to own their owner implementation.

See Also:
IJavaScriptUnit#becomeWorkingCopy(org.eclipse.core.runtime.IProgressMonitor), IJavaScriptUnit.discardWorkingCopy(), 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.

Constructor Summary
WorkingCopyOwner()
           
 
Method Summary
 IBuffer createBuffer(IJavaScriptUnit workingCopy)
          Creates a buffer for the given working copy.
 IProblemRequestor getProblemRequestor(IJavaScriptUnit workingCopy)
          Returns the problem requestor used by a working copy of this working copy owner.
 IJavaScriptUnit newWorkingCopy(java.lang.String name, IIncludePathEntry[] classpath, IProblemRequestor problemRequestor, IProgressMonitor monitor)
          Deprecated. Use newWorkingCopy(String, IIncludePathEntry[], IProgressMonitor) instead. Note that if this deprecated method is used, problems may be reported twice if the given requestor is not the same as the current working copy owner one.
 IJavaScriptUnit newWorkingCopy(java.lang.String name, IIncludePathEntry[] classpath, IProgressMonitor monitor)
          Returns a new working copy with the given name using this working copy owner to create its buffer.
static void setPrimaryBufferProvider(WorkingCopyOwner primaryBufferProvider)
          Sets the buffer provider of the primary working copy owner.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkingCopyOwner

public WorkingCopyOwner()
Method Detail

setPrimaryBufferProvider

public static void setPrimaryBufferProvider(WorkingCopyOwner primaryBufferProvider)
Sets the buffer provider of the primary working copy owner. Note that even if the buffer provider is a working copy owner, only its createBuffer(IJavaScriptUnit) method is used by the primary working copy owner. It doesn't replace the internal primary working owner.

This method is for internal use by the jsdt-related plug-ins. Clients outside of the jsdt should not reference this method.

Parameters:
primaryBufferProvider - the primary buffer provider

createBuffer

public IBuffer createBuffer(IJavaScriptUnit workingCopy)
Creates a buffer for the given working copy. The new buffer will be initialized with the contents of the underlying file if and only if it was not already initialized by the compilation owner (a buffer is uninitialized if its content is null).

Note: This buffer will be associated to the working copy for its entire life-cycle. Another working copy on same unit but owned by a different owner would not share the same buffer unless its owner decided to implement such a sharing behaviour.

Parameters:
workingCopy - the working copy of the buffer
Returns:
IBuffer the created buffer for the given working copy
See Also:
IBuffer

getProblemRequestor

public IProblemRequestor getProblemRequestor(IJavaScriptUnit workingCopy)
Returns the problem requestor used by a working copy of this working copy owner.

By default, no problem requestor is configured. Clients can override this method to provide a requestor.

Parameters:
workingCopy - The problem requestor used for the given working copy.
Returns:
the problem requestor to be used by working copies of this working copy owner or null if no problem requestor is configured.

newWorkingCopy

public final IJavaScriptUnit newWorkingCopy(java.lang.String name,
                                            IIncludePathEntry[] classpath,
                                            IProblemRequestor problemRequestor,
                                            IProgressMonitor monitor)
                                     throws JavaScriptModelException
Deprecated. Use newWorkingCopy(String, IIncludePathEntry[], IProgressMonitor) instead. Note that if this deprecated method is used, problems may be reported twice if the given requestor is not the same as the current working copy owner one.

Returns a new working copy with the given name using this working copy owner to create its buffer.

This working copy always belongs to the default package in a package fragment root that corresponds to its JavaScript project, and this JavaScript project never exists. However this JavaScript project has the given includepath that is used when resolving names in this working copy.

A DOM AST created using this working copy will have bindings resolved using the given includepath, and problem are reported to the given problem requestor.

JavaScriptCore#getOptions() is used to create the DOM AST as it is not possible to set the options on the non-existing JavaScript project.

When the working copy instance is created, an added delta is reported on this working copy.

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

Note that when such working copy is committed, only its buffer is saved (see IBuffer.save(IProgressMonitor, boolean)) but no resource is created.

This method is not intended to be overriden by clients.

Parameters:
name - the name of the working copy (e.g. "X.js")
includepath - the includepath used to resolve names in this 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 the working copy or null if no progress should be reported
Returns:
a new working copy
Throws:
JavaScriptModelException - if the contents of this working copy can not be determined.
See Also:
IJavaScriptUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor)

newWorkingCopy

public final IJavaScriptUnit newWorkingCopy(java.lang.String name,
                                            IIncludePathEntry[] classpath,
                                            IProgressMonitor monitor)
                                     throws JavaScriptModelException
Returns a new working copy with the given name using this working copy owner to create its buffer.

This working copy always belongs to the default package in a package fragment root that corresponds to its JavaScript project, and this JavaScript project never exists. However this JavaScript project has the given includepath that is used when resolving names in this working copy.

If a DOM AST is created using this working copy, then given includepath will be used if bindings need to be resolved. Problems will be reported to the problem requestor of the current working copy owner problem if it is not null.

Options used to create the DOM AST are got from JavaScriptCore.getOptions() as it is not possible to set the options on a non-existing JavaScript project.

When the working copy instance is created, an added delta is reported on this working copy.

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

Note that when such working copy is committed, only its buffer is saved (see IBuffer.save(IProgressMonitor, boolean)) but no resource is created.

This method is not intended to be overriden by clients.

Parameters:
name - the name of the working copy (e.g. "X.js")
classpath - the includepath used to resolve names in this working copy
monitor - a progress monitor used to report progress while opening the working copy or null if no progress should be reported
Returns:
a new working copy
Throws:
JavaScriptModelException - if the contents of this working copy can not be determined.
See Also:
IJavaScriptUnit.becomeWorkingCopy(IProgressMonitor)