Class Buffer
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.aspectj.org.eclipse.jdt.core.IBuffer
IBuffer.ITextEditCapability -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.eclipse.core.runtime.ListenerList<IBufferChangedListener> protected char[]protected static final intprotected static final intprotected static final intprotected final org.eclipse.core.resources.IFileprotected intprotected intprotected intprotected Objectprotected final IOpenable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given listener for changes to this buffer.voidappend(char[] text) Append thetextto the actual content, the gap is moved to the end of thetext.voidAppend thetextto the actual content, the gap is moved to the end of thetext.voidclose()Closes the buffer.chargetChar(int position) Returns the character at the given position in this buffer.char[]Returns the contents of this buffer as a character array, ornullif the buffer has not been initialized.Returns the contents of this buffer as aString.intReturns number of characters stored in this buffer.getOwner()Returns the Java openable element owning of this buffer.getText(int offset, int length) Returns the given range of text in this buffer.org.eclipse.core.resources.IResourceReturns the underlying resource for which this buffer was opened, ornullif this buffer was not opened on a resource.booleanReturns whether this buffer has been modified since it was opened or since it was last saved.booleanisClosed()Returns whether this buffer has been closed.booleanReturns whether this buffer is read-only.protected voidmoveAndResizeGap(int position, int size) Moves the gap to location and adjust its size to the anticipated change size.protected voidnotifyChanged(BufferChangedEvent event) Notify the listeners that this buffer has changed.voidRemoves the given listener from this buffer.voidreplace(int position, int length, char[] text) Replaceslengthcharacters starting frompositionwithtext.voidReplaceslengthcharacters starting frompositionwithtext.voidsave(org.eclipse.core.runtime.IProgressMonitor progress, boolean force) Saves the contents of this buffer to its underlying resource.voidsetContents(char[] newContents) Sets the contents of this buffer to the given character array.voidsetContents(String newContents) Sets the contents of this buffer to the givenString.protected voidsetReadOnly(boolean readOnly) Sets thisBufferto be read only.toString()
-
Field Details
-
file
protected final org.eclipse.core.resources.IFile file -
flags
protected int flags -
contents
protected char[] contents -
changeListeners
-
owner
-
gapStart
protected int gapStart -
gapEnd
protected int gapEnd -
lock
-
F_HAS_UNSAVED_CHANGES
protected static final int F_HAS_UNSAVED_CHANGES- See Also:
-
F_IS_READ_ONLY
protected static final int F_IS_READ_ONLY- See Also:
-
F_IS_CLOSED
protected static final int F_IS_CLOSED- See Also:
-
-
Constructor Details
-
Buffer
Creates a new buffer on an underlying resource.
-
-
Method Details
-
addBufferChangedListener
Description copied from interface:IBufferAdds the given listener for changes to this buffer. Has no effect if an identical listener is already registered or if the buffer is closed.- Specified by:
addBufferChangedListenerin interfaceIBuffer- Parameters:
listener- the listener of buffer changes- See Also:
-
append
-
append
-
close
public void close()Description copied from interface:IBufferCloses the buffer. Any unsaved changes are lost. Reports a buffer changed event with a 0 offset and a 0 length. When this event is fired, the buffer should already be closed.Further operations on the buffer are not allowed, except for close. If an attempt is made to close an already closed buffer, the second attempt has no effect.
-
getChar
public char getChar(int position) Description copied from interface:IBufferReturns the character at the given position in this buffer.The returned value is undefined if the buffer is closed.
-
getCharacters
public char[] getCharacters()Description copied from interface:IBufferReturns the contents of this buffer as a character array, ornullif the buffer has not been initialized.Callers should make no assumption about whether the returned character array is or is not the genuine article or a copy. In other words, if the client wishes to change this array, they should make a copy. Likewise, if the client wishes to hang on to the array in its current state, they should make a copy.
The returned value is undefined if the buffer is closed.
- Specified by:
getCharactersin interfaceIBuffer- Returns:
- the characters contained in this buffer
- See Also:
-
getContents
Description copied from interface:IBufferReturns the contents of this buffer as aString. Like all strings, the result is an immutable value object., It can also answernullif the buffer has not been initialized.The returned value is undefined if the buffer is closed.
- Specified by:
getContentsin interfaceIBuffer- Returns:
- the contents of this buffer as a
String - See Also:
-
getLength
-
getOwner
-
getText
Description copied from interface:IBufferReturns the given range of text in this buffer.The returned value is undefined if the buffer is closed.
-
getUnderlyingResource
public org.eclipse.core.resources.IResource getUnderlyingResource()Description copied from interface:IBufferReturns the underlying resource for which this buffer was opened, ornullif this buffer was not opened on a resource.- Specified by:
getUnderlyingResourcein interfaceIBuffer- Returns:
- the underlying resource for this buffer, or
nullif none. - See Also:
-
hasUnsavedChanges
public boolean hasUnsavedChanges()Description copied from interface:IBufferReturns whether this buffer has been modified since it was opened or since it was last saved. If a buffer does not have an underlying resource, this method always returnstrue.NOTE: when a buffer does not have unsaved changes, the model may decide to close it to claim some memory back. If the associated element needs to be reopened later on, its buffer factory will be requested to create a new buffer.
- Specified by:
hasUnsavedChangesin interfaceIBuffer- Returns:
- a
booleanindicating presence of unsaved changes (in the absence of any underlying resource, it will always returntrue). - See Also:
-
isClosed
-
isReadOnly
public boolean isReadOnly()Description copied from interface:IBufferReturns whether this buffer is read-only.- Specified by:
isReadOnlyin interfaceIBuffer- Returns:
- a
booleanindicating whether this buffer is read-only - See Also:
-
moveAndResizeGap
protected void moveAndResizeGap(int position, int size) Moves the gap to location and adjust its size to the anticipated change size. The size represents the expected range of the gap that will be filled after the gap has been moved. Thus the gap is resized to actual size + the specified size and moved to the given position. -
notifyChanged
Notify the listeners that this buffer has changed. To avoid deadlock, this should not be called in a synchronized block. -
removeBufferChangedListener
Description copied from interface:IBufferRemoves the given listener from this buffer. Has no effect if an identical listener is not registered or if the buffer is closed.- Specified by:
removeBufferChangedListenerin interfaceIBuffer- Parameters:
listener- the listener- See Also:
-
replace
public void replace(int position, int length, char[] text) Replaceslengthcharacters starting frompositionwithtext. After that operation, the gap is placed at the end of the insertedtext. -
replace
Replaceslengthcharacters starting frompositionwithtext. After that operation, the gap is placed at the end of the insertedtext. -
save
public void save(org.eclipse.core.runtime.IProgressMonitor progress, boolean force) throws JavaModelException Description copied from interface:IBufferSaves the contents of this buffer to its underlying resource. If successful, this buffer will have no unsaved changes. The buffer is left open. Saving a buffer with no unsaved changes has no effect - the underlying resource is not changed. If the buffer does not have an underlying resource or is read-only, this has no effect.The
forceparameter controls how this method deals with cases where the workbench is not completely in sync with the local file system. Iffalseis specified, this method will only attempt to overwrite a corresponding file in the local file system provided it is in sync with the workbench. This option ensures there is no unintended data loss; it is the recommended setting. However, iftrueis specified, an attempt will be made to write a corresponding file in the local file system, overwriting any existing one if need be. In either case, if this method succeeds, the resource will be marked as being local (even if it wasn't before).Has no effect if this buffer is read-only or if the buffer is closed.
- Specified by:
savein interfaceIBuffer- Parameters:
progress- the progress monitor to notifyforce- abooleanflag indicating how to deal with resource inconsistencies.- Throws:
JavaModelException- if an error occurs writing the buffer to the underlying resource- See Also:
-
setContents
public void setContents(char[] newContents) Description copied from interface:IBufferSets the contents of this buffer to the given character array. This buffer will now have unsaved changes. Any client can set the contents of the buffer, not just the owner of the buffer. Reports a buffer changed event.Equivalent to
replace(0,getLength(),contents).Has no effect if this buffer is read-only or if the buffer is closed.
- Specified by:
setContentsin interfaceIBuffer- Parameters:
newContents- the new contents of this buffer as a character array- See Also:
-
setContents
Description copied from interface:IBufferSets the contents of this buffer to the givenString. This buffer will now have unsaved changes. Any client can set the contents of the buffer, not just the owner of the buffer. Reports a buffer changed event.Equivalent to
replace(0,getLength(),contents).Has no effect if this buffer is read-only or if the buffer is closed.
- Specified by:
setContentsin interfaceIBuffer- Parameters:
newContents- the new contents of this buffer as aString- See Also:
-
setReadOnly
protected void setReadOnly(boolean readOnly) Sets thisBufferto be read only. -
toString
-