public final class TextFileBuffer extends java.lang.Object implements IBuffer
IBuffer
backed by an ITextFileBuffer
.
An instance of this class is safe for use by multiple threads, provided that
the underlying ITextFileBuffer
and its document are thread-safe.
This class has an optional dependency on IFile
and can safely be used
even when org.eclipse.core.resources
bundle is not available.
Constructor and Description |
---|
TextFileBuffer(ICoreTextFileBufferProvider provider,
org.eclipse.core.runtime.IProgressMonitor monitor)
Creates a new text file buffer instance and connects it to an underlying
ITextFileBuffer via the given provider. |
Modifier and Type | Method and Description |
---|---|
void |
addRef()
Spawns a new independent ownership of this object.
|
IBufferChange |
applyChange(IBufferChange change,
org.eclipse.core.runtime.IProgressMonitor monitor)
Applies the given change to this buffer.
|
static TextFileBuffer |
forFile(org.eclipse.core.resources.IFile file)
Returns a
TextFileBuffer for the given file resource. |
static TextFileBuffer |
forFileStore(org.eclipse.core.filesystem.IFileStore fileStore)
Returns a
TextFileBuffer for the given file store. |
static TextFileBuffer |
forLocation(org.eclipse.core.runtime.IPath location,
org.eclipse.core.filebuffers.LocationKind locationKind)
Returns a
TextFileBuffer for the given file location. |
ICoreTextFileBufferProvider |
getCoreTextFileBufferProvider()
Returns the provider of the underlying
ITextFileBuffer
for this buffer. |
org.eclipse.jface.text.IDocument |
getDocument()
Returns the underlying document of this buffer.
|
ISnapshot |
getSnapshot()
Returns the current snapshot of this buffer.
|
boolean |
isDirty()
Returns whether this buffer has been modified since the last time
it was opened or saved.
|
void |
release()
Relinquishes an independent ownership of this object.
|
void |
save(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Saves this buffer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public TextFileBuffer(ICoreTextFileBufferProvider provider, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
ITextFileBuffer
via the given provider.
It is the client responsibility to release
the created buffer after it is no longer needed.
provider
- a provider of the underlying ITextFileBuffer
(not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiver.
The progress monitor is only valid for the duration of the invocation
of this constructororg.eclipse.core.runtime.CoreException
- if the buffer could not be createdorg.eclipse.core.runtime.OperationCanceledException
- if this constructor is canceledpublic static TextFileBuffer forLocation(org.eclipse.core.runtime.IPath location, org.eclipse.core.filebuffers.LocationKind locationKind) throws org.eclipse.core.runtime.CoreException
TextFileBuffer
for the given file location.
It is the client responsibility to release
the buffer after it is no longer needed.
location
- not null
locationKind
- not null
null
)org.eclipse.core.runtime.CoreException
- if the buffer could not be createdpublic static TextFileBuffer forFileStore(org.eclipse.core.filesystem.IFileStore fileStore) throws org.eclipse.core.runtime.CoreException
TextFileBuffer
for the given file store.
It is the client responsibility to release
the buffer after it is no longer needed.
fileStore
- not null
null
)org.eclipse.core.runtime.CoreException
- if the buffer could not be createdpublic static TextFileBuffer forFile(org.eclipse.core.resources.IFile file) throws org.eclipse.core.runtime.CoreException
TextFileBuffer
for the given file resource.
It is the client responsibility to release
the buffer after it is no longer needed.
file
- not null
null
)org.eclipse.core.runtime.CoreException
- if the buffer could not be createdpublic ICoreTextFileBufferProvider getCoreTextFileBufferProvider()
ITextFileBuffer
for this buffer.null
)java.lang.IllegalStateException
- if this buffer is no longer accessiblepublic org.eclipse.jface.text.IDocument getDocument()
IBuffer
getDocument
in interface IBuffer
null
)public ISnapshot getSnapshot()
IBuffer
Note that it is possible to obtain a non-expiring
snapshot from the buffer, although protractedly holding on non-expiring
snapshots is not recommended as they may potentially consume large amount
of space.
getSnapshot
in interface IBuffer
getSnapshot
in interface ISnapshotProvider
null
)public IBufferChange applyChange(IBufferChange change, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
IBuffer
Note that an update conflict may occur if the buffer's contents have
changed since the inception of the snapshot on which the change is based.
In that case, a StaleSnapshotException
is thrown.
applyChange
in interface IBuffer
change
- a buffer change (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
org.eclipse.core.runtime.CoreException
- if the change's edit tree is not in a valid state,
or if one of the edits in the tree could not be executed, or if save
is requested by the change but the buffer could not be savedpublic void save(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
IBuffer
save
in interface IBuffer
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if the buffer could not be savedpublic boolean isDirty()
IBuffer
public void addRef()
IReferenceCountable
addRef()
must ultimately be
followed by exactly one call to IReferenceCountable.release()
.addRef
in interface IBuffer
addRef
in interface ISnapshotProvider
addRef
in interface IReferenceCountable
public void release()
IReferenceCountable
release
in interface IBuffer
release
in interface ISnapshotProvider
release
in interface IReferenceCountable
IReferenceCountable.close()
Copyright (c) 2014, 2018 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0