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;
30 public SimpleDocument(String source) {
31 this.buffer = new StringBuffer(source);
35 * @see org.eclipse.jface.text.IDocument#getChar(int)
37 public char getChar(int offset) {
42 * @see org.eclipse.jface.text.IDocument#getLength()
44 public int getLength() {
45 return this.buffer.length();
49 * @see org.eclipse.jface.text.IDocument#get()
52 return this.buffer.toString();
56 * @see org.eclipse.jface.text.IDocument#get(int, int)
58 public String get(int offset, int length) {
59 return this.buffer.substring(offset, offset + length);
63 * @see org.eclipse.jface.text.IDocument#set(java.lang.String)
65 public void set(String text) {
66 // defining interface method
70 * @see org.eclipse.jface.text.IDocument#replace(int, int, java.lang.String)
72 public void replace(int offset, int length, String text) {
74 this.buffer.replace(offset, offset + length, text);
78 * @see org.eclipse.jface.text.IDocument#addDocumentListener(org.eclipse.jface.text.IDocumentListener)
80 public void addDocumentListener(IDocumentListener listener) {
81 // defining interface method
85 * @see org.eclipse.jface.text.IDocument#removeDocumentListener(org.eclipse.jface.text.IDocumentListener)
87 public void removeDocumentListener(IDocumentListener listener) {
88 // defining interface method
92 * @see org.eclipse.jface.text.IDocument#addPrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
94 public void addPrenotifiedDocumentListener(IDocumentListener documentAdapter) {
95 // defining interface method
99 * @see org.eclipse.jface.text.IDocument#removePrenotifiedDocumentListener(org.eclipse.jface.text.IDocumentListener)
101 public void removePrenotifiedDocumentListener(IDocumentListener documentAdapter) {
102 // defining interface method
106 * @see org.eclipse.jface.text.IDocument#addPositionCategory(java.lang.String)
108 public void addPositionCategory(String category) {
109 // defining interface method
113 * @see org.eclipse.jface.text.IDocument#removePositionCategory(java.lang.String)
115 public void removePositionCategory(String category) {
116 // defining interface method
120 * @see org.eclipse.jface.text.IDocument#getPositionCategories()
122 public String[] getPositionCategories() {
123 // defining interface method
128 * @see org.eclipse.jface.text.IDocument#containsPositionCategory(java.lang.String)
130 public boolean containsPositionCategory(String category) {
131 // defining interface method
136 * @see org.eclipse.jface.text.IDocument#addPosition(org.eclipse.jface.text.Position)
138 public void addPosition(Position position) {
139 // defining interface method
143 * @see org.eclipse.jface.text.IDocument#removePosition(org.eclipse.jface.text.Position)
145 public void removePosition(Position position) {
146 // defining interface method
150 * @see org.eclipse.jface.text.IDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
152 public void addPosition(String category, Position position) {
153 // defining interface method
157 * @see org.eclipse.jface.text.IDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
159 public void removePosition(String category, Position position) {
160 // defining interface method
164 * @see org.eclipse.jface.text.IDocument#getPositions(java.lang.String)
166 public Position[] getPositions(String category) {
167 // defining interface method
172 * @see org.eclipse.jface.text.IDocument#containsPosition(java.lang.String, int, int)
174 public boolean containsPosition(String category, int offset, int length) {
175 // defining interface method
180 * @see org.eclipse.jface.text.IDocument#computeIndexInCategory(java.lang.String, int)
182 public int computeIndexInCategory(String category, int offset) {
183 // defining interface method
188 * @see org.eclipse.jface.text.IDocument#addPositionUpdater(org.eclipse.jface.text.IPositionUpdater)
190 public void addPositionUpdater(IPositionUpdater updater) {
191 // defining interface method
195 * @see org.eclipse.jface.text.IDocument#removePositionUpdater(org.eclipse.jface.text.IPositionUpdater)
197 public void removePositionUpdater(IPositionUpdater updater) {
198 // defining interface method
202 * @see org.eclipse.jface.text.IDocument#insertPositionUpdater(org.eclipse.jface.text.IPositionUpdater, int)
204 public void insertPositionUpdater(IPositionUpdater updater, int index) {
205 // defining interface method
209 * @see org.eclipse.jface.text.IDocument#getPositionUpdaters()
211 public IPositionUpdater[] getPositionUpdaters() {
212 // defining interface method
217 * @see org.eclipse.jface.text.IDocument#getLegalContentTypes()
219 public String[] getLegalContentTypes() {
220 // defining interface method
225 * @see org.eclipse.jface.text.IDocument#getContentType(int)
227 public String getContentType(int offset) {
228 // defining interface method
233 * @see org.eclipse.jface.text.IDocument#getPartition(int)
235 public ITypedRegion getPartition(int offset) {
236 // defining interface method
241 * @see org.eclipse.jface.text.IDocument#computePartitioning(int, int)
243 public ITypedRegion[] computePartitioning(int offset, int length) {
244 // defining interface method
249 * @see org.eclipse.jface.text.IDocument#addDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
251 public void addDocumentPartitioningListener(IDocumentPartitioningListener listener) {
252 // defining interface method
256 * @see org.eclipse.jface.text.IDocument#removeDocumentPartitioningListener(org.eclipse.jface.text.IDocumentPartitioningListener)
258 public void removeDocumentPartitioningListener(IDocumentPartitioningListener listener) {
259 // defining interface method
263 * @see org.eclipse.jface.text.IDocument#setDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner)
265 public void setDocumentPartitioner(IDocumentPartitioner partitioner) {
266 // defining interface method
270 * @see org.eclipse.jface.text.IDocument#getDocumentPartitioner()
272 public IDocumentPartitioner getDocumentPartitioner() {
273 // defining interface method
278 * @see org.eclipse.jface.text.IDocument#getLineLength(int)
280 public int getLineLength(int line) {
281 // defining interface method
286 * @see org.eclipse.jface.text.IDocument#getLineOfOffset(int)
288 public int getLineOfOffset(int offset) {
289 // defining interface method
294 * @see org.eclipse.jface.text.IDocument#getLineOffset(int)
296 public int getLineOffset(int line) {
297 // defining interface method
302 * @see org.eclipse.jface.text.IDocument#getLineInformation(int)
304 public IRegion getLineInformation(int line) {
305 // defining interface method
310 * @see org.eclipse.jface.text.IDocument#getLineInformationOfOffset(int)
312 public IRegion getLineInformationOfOffset(int offset) {
313 // defining interface method
318 * @see org.eclipse.jface.text.IDocument#getNumberOfLines()
320 public int getNumberOfLines() {
321 // defining interface method
326 * @see org.eclipse.jface.text.IDocument#getNumberOfLines(int, int)
328 public int getNumberOfLines(int offset, int length) {
329 // defining interface method
334 * @see org.eclipse.jface.text.IDocument#computeNumberOfLines(java.lang.String)
336 public int computeNumberOfLines(String text) {
337 // defining interface method
342 * @see org.eclipse.jface.text.IDocument#getLegalLineDelimiters()
344 public String[] getLegalLineDelimiters() {
345 // defining interface method
350 * @see org.eclipse.jface.text.IDocument#getLineDelimiter(int)
352 public String getLineDelimiter(int line) {
353 // defining interface method
358 * @see org.eclipse.jface.text.IDocument#search(int, java.lang.String, boolean, boolean, boolean)
364 boolean forwardSearch,
365 boolean caseSensitive,
367 // defining interface method