PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/eclipse-phpeclipse-1.2.3/plugins/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/IBuffer.java

#
Java | 320 lines | 26 code | 22 blank | 272 comment | 0 complexity | a36d37a07be1a941baefe4e264cb09b9 MD5 | raw file
  1. /*******************************************************************************
  2. * Copyright (c) 2000, 2003 IBM Corporation and others.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package net.sourceforge.phpdt.core;
  12. import org.eclipse.core.resources.IResource;
  13. import org.eclipse.core.runtime.IProgressMonitor;
  14. /**
  15. * A buffer contains the text contents of a resource. It is not
  16. * language-specific. The contents may be in the process of being edited,
  17. * differing from the actual contents of the underlying resource. A buffer has
  18. * an owner, which is an <code>IOpenable</code>. If a buffer does not have an
  19. * underlying resource, saving the buffer has no effect. Buffers can be
  20. * read-only.
  21. * <p>
  22. * Note that java model operations that manipulate an <code>IBuffer</code>
  23. * (for example, <code>IType.createMethod(...)</code>) ensures that the same
  24. * line delimiter (either <code>"\n"</code> or <code>"\r"</code> or
  25. * <code>"\r\n"</code>) is used across the whole buffer. Thus these
  26. * operations may change the line delimiter(s) included in the string to be
  27. * append, or replaced. However implementers of this interface should be aware
  28. * that other clients of <code>IBuffer</code> might not do such
  29. * transformations beforehand.
  30. * <p>
  31. * This interface may be implemented by clients.
  32. * </p>
  33. */
  34. public interface IBuffer {
  35. /**
  36. * Adds the given listener for changes to this buffer. Has no effect if an
  37. * identical listener is already registered or if the buffer is closed.
  38. *
  39. * @param listener
  40. * the listener of buffer changes
  41. */
  42. public void addBufferChangedListener(IBufferChangedListener listener);
  43. /**
  44. * Appends the given character array to the contents of the buffer. This
  45. * buffer will now have unsaved changes. Any client can append to the
  46. * contents of the buffer, not just the owner of the buffer. Reports a
  47. * buffer changed event.
  48. * <p>
  49. * Has no effect if this buffer is read-only.
  50. * <p>
  51. * A <code>RuntimeException</code> might be thrown if the buffer is
  52. * closed.
  53. *
  54. * @param text
  55. * the given character array to append to contents of the buffer
  56. */
  57. public void append(char[] text);
  58. /**
  59. * Appends the given string to the contents of the buffer. This buffer will
  60. * now have unsaved changes. Any client can append to the contents of the
  61. * buffer, not just the owner of the buffer. Reports a buffer changed event.
  62. * <p>
  63. * Has no effect if this buffer is read-only.
  64. * <p>
  65. * A <code>RuntimeException</code> might be thrown if the buffer is
  66. * closed.
  67. *
  68. * @param text
  69. * the <code>String</code> to append to the contents of the
  70. * buffer
  71. */
  72. public void append(String text);
  73. /**
  74. * Closes the buffer. Any unsaved changes are lost. Reports a buffer changed
  75. * event with a 0 offset and a 0 length. When this event is fired, the
  76. * buffer should already be closed.
  77. * <p>
  78. * Further operations on the buffer are not allowed, except for close. If an
  79. * attempt is made to close an already closed buffer, the second attempt has
  80. * no effect.
  81. */
  82. public void close();
  83. /**
  84. * Returns the character at the given position in this buffer.
  85. * <p>
  86. * A <code>RuntimeException</code> might be thrown if the buffer is
  87. * closed.
  88. *
  89. * @param position
  90. * a zero-based source offset in this buffer
  91. * @return the character at the given position in this buffer
  92. */
  93. public char getChar(int position);
  94. /**
  95. * Returns the contents of this buffer as a character array, or
  96. * <code>null</code> if the buffer has not been initialized.
  97. * <p>
  98. * Callers should make no assumption about whether the returned character
  99. * array is or is not the genuine article or a copy. In other words, if the
  100. * client wishes to change this array, they should make a copy. Likewise, if
  101. * the client wishes to hang on to the array in its current state, they
  102. * should make a copy.
  103. * </p>
  104. * <p>
  105. * A <code>RuntimeException</code> might be thrown if the buffer is
  106. * closed.
  107. *
  108. * @return the characters contained in this buffer
  109. */
  110. public char[] getCharacters();
  111. /**
  112. * Returns the contents of this buffer as a <code>String</code>. Like all
  113. * strings, the result is an immutable value object., It can also answer
  114. * <code>null</code> if the buffer has not been initialized.
  115. * <p>
  116. * A <code>RuntimeException</code> might be thrown if the buffer is
  117. * closed.
  118. *
  119. * @return the contents of this buffer as a <code>String</code>
  120. */
  121. public String getContents();
  122. /**
  123. * Returns number of characters stored in this buffer.
  124. * <p>
  125. * A <code>RuntimeException</code> might be thrown if the buffer is
  126. * closed.
  127. *
  128. * @return the number of characters in this buffer
  129. */
  130. public int getLength();
  131. /**
  132. * Returns the Java openable element owning of this buffer.
  133. *
  134. * @return the openable element owning this buffer
  135. */
  136. public IOpenable getOwner();
  137. /**
  138. * Returns the given range of text in this buffer.
  139. * <p>
  140. * A <code>RuntimeException</code> might be thrown if the buffer is
  141. * closed.
  142. *
  143. * @param offset
  144. * the zero-based starting offset
  145. * @param length
  146. * the number of characters to retrieve
  147. * @return the given range of text in this buffer
  148. */
  149. public String getText(int offset, int length);
  150. /**
  151. * Returns the underlying resource for which this buffer was opened, or
  152. * <code>null</code> if this buffer was not opened on a resource.
  153. *
  154. * @return the underlying resource for this buffer, or <code>null</code>
  155. * if none.
  156. */
  157. public IResource getUnderlyingResource();
  158. /**
  159. * Returns whether this buffer has been modified since it was opened or
  160. * since it was last saved. If a buffer does not have an underlying
  161. * resource, this method always returns <code>true</code>.
  162. *
  163. * @return a <code>boolean</code> indicating presence of unsaved changes
  164. * (in the absence of any underlying resource, it will always return
  165. * <code>true</code>).
  166. */
  167. public boolean hasUnsavedChanges();
  168. /**
  169. * Returns whether this buffer has been closed.
  170. *
  171. * @return a <code>boolean</code> indicating whether this buffer is
  172. * closed.
  173. */
  174. public boolean isClosed();
  175. /**
  176. * Returns whether this buffer is read-only.
  177. *
  178. * @return a <code>boolean</code> indicating whether this buffer is
  179. * read-only
  180. */
  181. public boolean isReadOnly();
  182. /**
  183. * Removes the given listener from this buffer. Has no affect if an
  184. * identical listener is not registered or if the buffer is closed.
  185. *
  186. * @param listener
  187. * the listener
  188. */
  189. public void removeBufferChangedListener(IBufferChangedListener listener);
  190. /**
  191. * Replaces the given range of characters in this buffer with the given
  192. * text. <code>position</code> and <code>position + length</code> must
  193. * be in the range [0, getLength()]. <code>length</code> must not be
  194. * negative.
  195. * <p>
  196. * A <code>RuntimeException</code> might be thrown if the buffer is
  197. * closed.
  198. *
  199. * @param position
  200. * the zero-based starting position of the affected text range in
  201. * this buffer
  202. * @param length
  203. * the length of the affected text range in this buffer
  204. * @param text
  205. * the replacing text as a character array
  206. */
  207. public void replace(int position, int length, char[] text);
  208. /**
  209. * Replaces the given range of characters in this buffer with the given
  210. * text. <code>position</code> and <code>position + length</code> must
  211. * be in the range [0, getLength()]. <code>length</code> must not be
  212. * negative.
  213. * <p>
  214. * A <code>RuntimeException</code> might be thrown if the buffer is
  215. * closed.
  216. *
  217. * @param position
  218. * the zero-based starting position of the affected text range in
  219. * this buffer
  220. * @param length
  221. * the length of the affected text range in this buffer
  222. * @param text
  223. * the replacing text as a <code>String</code>
  224. */
  225. public void replace(int position, int length, String text);
  226. /**
  227. * Saves the contents of this buffer to its underlying resource. If
  228. * successful, this buffer will have no unsaved changes. The buffer is left
  229. * open. Saving a buffer with no unsaved changes has no effect - the
  230. * underlying resource is not changed. If the buffer does not have an
  231. * underlying resource or is read-only, this has no effect.
  232. * <p>
  233. * The <code>force</code> parameter controls how this method deals with
  234. * cases where the workbench is not completely in sync with the local file
  235. * system. If <code>false</code> is specified, this method will only
  236. * attempt to overwrite a corresponding file in the local file system
  237. * provided it is in sync with the workbench. This option ensures there is
  238. * no unintended data loss; it is the recommended setting. However, if
  239. * <code>true</code> is specified, an attempt will be made to write a
  240. * corresponding file in the local file system, overwriting any existing one
  241. * if need be. In either case, if this method succeeds, the resource will be
  242. * marked as being local (even if it wasn't before).
  243. * <p>
  244. * A <code>RuntimeException</code> might be thrown if the buffer is
  245. * closed.
  246. *
  247. * @param progress
  248. * the progress monitor to notify
  249. * @param force
  250. * a <code> boolean </code> flag indicating how to deal with
  251. * resource inconsistencies.
  252. *
  253. * @exception JavaModelException
  254. * if an error occurs writing the buffer to the underlying
  255. * resource
  256. *
  257. * @see org.eclipse.core.resources.IFile#setContents(java.io.InputStream,
  258. * boolean, boolean, org.eclipse.core.runtime.IProgressMonitor)
  259. */
  260. public void save(IProgressMonitor progress, boolean force)
  261. throws JavaModelException;
  262. /**
  263. * Sets the contents of this buffer to the given character array. This
  264. * buffer will now have unsaved changes. Any client can set the contents of
  265. * the buffer, not just the owner of the buffer. Reports a buffer changed
  266. * event.
  267. * <p>
  268. * Equivalent to <code>replace(0,getLength(),contents)</code>.
  269. * </p>
  270. * <p>
  271. * Has no effect if this buffer is read-only.
  272. * <p>
  273. * A <code>RuntimeException</code> might be thrown if the buffer is
  274. * closed.
  275. *
  276. * @param contents
  277. * the new contents of this buffer as a character array
  278. */
  279. public void setContents(char[] contents);
  280. /**
  281. * Sets the contents of this buffer to the given <code>String</code>.
  282. * This buffer will now have unsaved changes. Any client can set the
  283. * contents of the buffer, not just the owner of the buffer. Reports a
  284. * buffer changed event.
  285. * <p>
  286. * Equivalent to <code>replace(0,getLength(),contents)</code>.
  287. * </p>
  288. * <p>
  289. * Has no effect if this buffer is read-only.
  290. * <p>
  291. * A <code>RuntimeException</code> might be thrown if the buffer is
  292. * closed.
  293. *
  294. * @param contents
  295. * the new contents of this buffer as a <code>String</code>
  296. */
  297. public void setContents(String contents);
  298. }