public class Buffer extends java.lang.Object implements IBuffer
IBuffer
implementation. This implementation is not backed
by an underlying resource, so saving the buffer only modifies its "dirty"
state; it does not really save its contents.
An instance of this class is safe for use by multiple threads. Clients can use this class as it stands or subclass it as circumstances warrant.
Constructor and Description |
---|
Buffer()
Creates a new buffer instance that is initially empty.
|
Buffer(java.lang.String contents)
Creates a new buffer instance and initializes it with the given contents.
|
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.
|
protected org.eclipse.jface.text.IDocument |
createEmptyDocument() |
protected void |
doSave(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor) |
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 Buffer()
It is the client responsibility to release
the created buffer after it is no longer needed.
public Buffer(java.lang.String contents)
It is the client responsibility to release
the created buffer after it is no longer needed.
contents
- initial contentspublic 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()
protected org.eclipse.jface.text.IDocument createEmptyDocument()
protected void doSave(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
org.eclipse.core.runtime.CoreException
Copyright (c) 2014, 2019 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0