|
Eclipse JDT 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A buffer contains the text contents of a resource. It is not language-specific.
The contents may be in the process of being edited, differing from the actual contents of the
underlying resource. A buffer has an owner, which is an IOpenable
.
If a buffer does not have an underlying resource, saving the buffer has no effect.
Buffers can be read-only.
Note that java model operations that manipulate an IBuffer
(e.g.
IType.createMethod(...)
) ensures that the same line delimiter
(i.e. either "\n"
or "\r"
or "\r\n"
) is
used across the whole buffer. Thus these operations may change the line delimiter(s)
included in the string to be append, or replaced.
However implementers of this interface should be aware that other clients of IBuffer
might not do such transformations beforehand.
This interface may be implemented by clients.
Method Summary | |
void |
addBufferChangedListener(IBufferChangedListener listener)
Adds the given listener for changes to this buffer. |
void |
append(char[] text)
Appends the given character array to the contents of the buffer. |
void |
append(String text)
Appends the given string to the contents of the buffer. |
void |
close()
Closes the buffer. |
char |
getChar(int position)
Returns the character at the given position in this buffer. |
char[] |
getCharacters()
Returns the contents of this buffer as a character array, or null if
the buffer has not been initialized. |
String |
getContents()
Returns the contents of this buffer as a String . |
int |
getLength()
Returns number of characters stored in this buffer. |
IOpenable |
getOwner()
Returns the Java openable element owning of this buffer. |
String |
getText(int offset,
int length)
Returns the given range of text in this buffer. |
IResource |
getUnderlyingResource()
Returns the underlying resource for which this buffer was opened, or null if this buffer was not opened on a resource. |
boolean |
hasUnsavedChanges()
Returns whether this buffer has been modified since it was opened or since it was last saved. |
boolean |
isClosed()
Returns whether this buffer has been closed. |
boolean |
isReadOnly()
Returns whether this buffer is read-only. |
void |
removeBufferChangedListener(IBufferChangedListener listener)
Removes the given listener from this buffer. |
void |
replace(int position,
int length,
char[] text)
Replaces the given range of characters in this buffer with the given text. |
void |
replace(int position,
int length,
String text)
Replaces the given range of characters in this buffer with the given text. |
void |
save(IProgressMonitor progress,
boolean force)
Saves the contents of this buffer to its underlying resource. |
void |
setContents(char[] contents)
Sets the contents of this buffer to the given character array. |
void |
setContents(String contents)
Sets the contents of this buffer to the given String . |
Method Detail |
public void addBufferChangedListener(IBufferChangedListener listener)
listener
- the listener of buffer changespublic void append(char[] text)
Has no effect if this buffer is read-only.
A RuntimeException
might be thrown if the buffer is closed.
text
- the given character array to append to contents of the bufferpublic void append(String text)
Has no effect if this buffer is read-only.
A RuntimeException
might be thrown if the buffer is closed.
text
- the String
to append to the contents of the bufferpublic void close()
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.
public char getChar(int position)
A RuntimeException
might be thrown if the buffer is closed.
position
- a zero-based source offset in this buffer
public char[] getCharacters()
null
if
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.
A RuntimeException
might be thrown if the buffer is closed.
public String getContents()
String
. Like all strings,
the result is an immutable value object., It can also answer null
if
the buffer has not been initialized.
A RuntimeException
might be thrown if the buffer is closed.
String
public int getLength()
A RuntimeException
might be thrown if the buffer is closed.
public IOpenable getOwner()
public String getText(int offset, int length)
A RuntimeException
might be thrown if the buffer is closed.
offset
- the zero-based starting offsetlength
- the number of characters to retrieve
public IResource getUnderlyingResource()
null
if this buffer was not opened on a resource.
null
if none.public boolean hasUnsavedChanges()
true
.
boolean
indicating presence of unsaved changes (in
the absence of any underlying resource, it will always return true
).public boolean isClosed()
boolean
indicating whether this buffer is closed.public boolean isReadOnly()
boolean
indicating whether this buffer is read-onlypublic void removeBufferChangedListener(IBufferChangedListener listener)
listener
- the listenerpublic void replace(int position, int length, char[] text)
position
and position + length
must be in the range [0, getLength()].
length
must not be negative.
A RuntimeException
might be thrown if the buffer is closed.
position
- the zero-based starting position of the affected text range in this bufferlength
- the length of the affected text range in this buffertext
- the replacing text as a character arraypublic void replace(int position, int length, String text)
position
and position + length
must be in the range [0, getLength()].
length
must not be negative.
A RuntimeException
might be thrown if the buffer is closed.
position
- the zero-based starting position of the affected text range in this bufferlength
- the length of the affected text range in this buffertext
- the replacing text as a String
public void save(IProgressMonitor progress, boolean force) throws JavaModelException
The force
parameter controls how this method deals with
cases where the workbench is not completely in sync with the local file system.
If false
is 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, if true
is 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).
A RuntimeException
might be thrown if the buffer is closed.
progress
- the progress monitor to notifyforce
- a boolean
flag indicating how to deal with resource
inconsistencies.
JavaModelException
- if an error occurs writing the buffer
to the underlying resourceIFile.setContents(java.io.InputStream, boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
public void setContents(char[] contents)
Equivalent to replace(0,getLength(),contents)
.
Has no effect if this buffer is read-only.
A RuntimeException
might be thrown if the buffer is closed.
contents
- the new contents of this buffer as a character arraypublic void setContents(String contents)
String
.
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.
A RuntimeException
might be thrown if the buffer is closed.
contents
- the new contents of this buffer as a String
|
Eclipse JDT 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |