1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core.util;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.jface.text.IDocumentListener;
15 import org.eclipse.jface.text.IDocumentPartitioner;
16 import org.eclipse.jface.text.IDocumentPartitioningListener;
17 import org.eclipse.jface.text.IPositionUpdater;
18 import org.eclipse.jface.text.IRegion;
19 import org.eclipse.jface.text.ITypedRegion;
20 import org.eclipse.jface.text.Position;
23 * Minimal implementation of IDocument to apply text edit onto a string.
25 public class SimpleDocument implements IDocument {
27 private StringBuffer buffer;
29 public SimpleDocument(String source) {
30 this.buffer = new StringBuffer(source);
36 * @see org.eclipse.jface.text.IDocument#getChar(int)
38 public char getChar(int offset) {
45 * @see org.eclipse.jface.text.IDocument#getLength()
47 public int getLength() {
48 return this.buffer.length();
54 * @see org.eclipse.jface.text.IDocument#get()
57 return this.buffer.toString();
63 * @see org.eclipse.jface.text.IDocument#get(int, int)
65 public String get(int offset, int length) {
66 return this.buffer.substring(offset, offset + length);
72 * @see org.eclipse.jface.text.IDocument#set(java.lang.String)
74 public void set(String text) {
75 // defining interface method
81 * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String)
83 public void replace(int offset, int length, String text) {
85 this.buffer.replace(offset, offset + length, text);
91 * @see org.eclipse.jface.text.IDocument#addDocumentListener(org.eclipse.jface.text.IDocumentListener)
93 public void addDocumentListener(IDocumentListener listener) {
94 // defining interface method
100 * @see org.eclipse.jface.text.IDocument#removeDocumentListener(org.eclipse.jface.text.IDocumentListener)
102 public void removeDocumentListener(IDocumentListener listener) {
103 // defining interface method
109 * @see org.eclipse.jface.text.IDocument#addPrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
111 public void addPrenotifiedDocumentListener(IDocumentListener documentAdapter) {
112 // defining interface method
118 * @see org.eclipse.jface.text.IDocument#removePrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
120 public void removePrenotifiedDocumentListener(
121 IDocumentListener documentAdapter) {
122 // defining interface method
128 * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String)
130 public void addPositionCategory(String category) {
131 // defining interface method
137 * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String)
139 public void removePositionCategory(String category) {
140 // defining interface method
146 * @see org.eclipse.jface.text.IDocument#getPositionCategories()
148 public String[] getPositionCategories() {
149 // defining interface method
156 * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String)
158 public boolean containsPositionCategory(String category) {
159 // defining interface method
166 * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position)
168 public void addPosition(Position position) {
169 // defining interface method
175 * @see org.eclipse.jface.text.IDocument#removePosition(org.eclipse.jface.text.Position)
177 public void removePosition(Position position) {
178 // defining interface method
184 * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String,
185 * org.eclipse.jface.text.Position)
187 public void addPosition(String category, Position position) {
188 // defining interface method
194 * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String,
195 * org.eclipse.jface.text.Position)
197 public void removePosition(String category, Position position) {
198 // defining interface method
204 * @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String)
206 public Position[] getPositions(String category) {
207 // defining interface method
214 * @see org.eclipse.jface.text.IDocument#containsPosition(java.lang.String,
217 public boolean containsPosition(String category, int offset, int length) {
218 // defining interface method
225 * @see org.eclipse.jface.text.IDocument#computeIndexInCategory(java.lang.String,
228 public int computeIndexInCategory(String category, int offset) {
229 // defining interface method
236 * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater)
238 public void addPositionUpdater(IPositionUpdater updater) {
239 // defining interface method
245 * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater)
247 public void removePositionUpdater(IPositionUpdater updater) {
248 // defining interface method
254 * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater,
257 public void insertPositionUpdater(IPositionUpdater updater, int index) {
258 // defining interface method
264 * @see org.eclipse.jface.text.IDocument#getPositionUpdaters()
266 public IPositionUpdater[] getPositionUpdaters() {
267 // defining interface method
274 * @see org.eclipse.jface.text.IDocument#getLegalContentTypes()
276 public String[] getLegalContentTypes() {
277 // defining interface method
284 * @see org.eclipse.jface.text.IDocument#getContentType(int)
286 public String getContentType(int offset) {
287 // defining interface method
294 * @see org.eclipse.jface.text.IDocument#getPartition(int)
296 public ITypedRegion getPartition(int offset) {
297 // defining interface method
304 * @see org.eclipse.jface.text.IDocument#computePartitioning(int, int)
306 public ITypedRegion[] computePartitioning(int offset, int length) {
307 // defining interface method
314 * @see org.eclipse.jface.text.IDocument#addDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
316 public void addDocumentPartitioningListener(
317 IDocumentPartitioningListener listener) {
318 // defining interface method
324 * @see org.eclipse.jface.text.IDocument#removeDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
326 public void removeDocumentPartitioningListener(
327 IDocumentPartitioningListener listener) {
328 // defining interface method
334 * @see org.eclipse.jface.text.IDocument#setDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)
336 public void setDocumentPartitioner(IDocumentPartitioner partitioner) {
337 // defining interface method
343 * @see org.eclipse.jface.text.IDocument#getDocumentPartitioner()
345 public IDocumentPartitioner getDocumentPartitioner() {
346 // defining interface method
353 * @see org.eclipse.jface.text.IDocument#getLineLength(int)
355 public int getLineLength(int line) {
356 // defining interface method
363 * @see org.eclipse.jface.text.IDocument#getLineOfOffset(int)
365 public int getLineOfOffset(int offset) {
366 // defining interface method
373 * @see org.eclipse.jface.text.IDocument#getLineOffset(int)
375 public int getLineOffset(int line) {
376 // defining interface method
383 * @see org.eclipse.jface.text.IDocument#getLineInformation(int)
385 public IRegion getLineInformation(int line) {
386 // defining interface method
393 * @see org.eclipse.jface.text.IDocument#getLineInformationOfOffset(int)
395 public IRegion getLineInformationOfOffset(int offset) {
396 // defining interface method
403 * @see org.eclipse.jface.text.IDocument#getNumberOfLines()
405 public int getNumberOfLines() {
406 // defining interface method
413 * @see org.eclipse.jface.text.IDocument#getNumberOfLines(int, int)
415 public int getNumberOfLines(int offset, int length) {
416 // defining interface method
423 * @see org.eclipse.jface.text.IDocument#computeNumberOfLines(java.lang.String)
425 public int computeNumberOfLines(String text) {
426 // defining interface method
433 * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters()
435 public String[] getLegalLineDelimiters() {
436 // defining interface method
443 * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int)
445 public String getLineDelimiter(int line) {
446 // defining interface method
451 * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String,
452 * boolean, boolean, boolean)
455 public int search(int startOffset, String findString,
456 boolean forwardSearch, boolean caseSensitive, boolean wholeWord) {
457 // defining interface method