1 /**********************************************************************
2 Copyright (c) 2000, 2003 IBM Corp. 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 implementation
10 **********************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.BadPositionCategoryException;
15 import org.eclipse.jface.text.Document;
16 import org.eclipse.jface.text.ISynchronizable;
17 import org.eclipse.jface.text.Position;
20 * Document that can also be used by a background reconciler.
22 public class PartiallySynchronizedDocument extends Document implements
25 private final Object fInternalLockObject = new Object();
27 private Object fLockObject;
30 * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object)
32 public void setLockObject(Object lockObject) {
33 fLockObject = lockObject;
37 * @see org.eclipse.jface.text.ISynchronizable#getLockObject()
39 public Object getLockObject() {
40 return fLockObject == null ? fInternalLockObject : fLockObject;
44 * @see IDocumentExtension#startSequentialRewrite(boolean)
46 public void startSequentialRewrite(boolean normalized) {
47 synchronized (getLockObject()) {
48 super.startSequentialRewrite(normalized);
53 * @see IDocumentExtension#stopSequentialRewrite()
55 public void stopSequentialRewrite() {
56 synchronized (getLockObject()) {
57 super.stopSequentialRewrite();
62 * @see IDocument#get()
65 synchronized (getLockObject()) {
71 * @see IDocument#get(int, int)
73 public String get(int offset, int length) throws BadLocationException {
74 synchronized (getLockObject()) {
75 return super.get(offset, length);
80 * @see IDocument#getChar(int)
82 public char getChar(int offset) throws BadLocationException {
83 synchronized (getLockObject()) {
84 return super.getChar(offset);
89 * @see IDocument#replace(int, int, String)
91 public void replace(int offset, int length, String text)
92 throws BadLocationException {
93 synchronized (getLockObject()) {
94 super.replace(offset, length, text);
99 * @see IDocument#set(String)
101 public void set(String text) {
102 synchronized (getLockObject()) {
108 * @see org.eclipse.jface.text.AbstractDocument#addPosition(java.lang.String,
109 * org.eclipse.jface.text.Position)
111 public void addPosition(String category, Position position)
112 throws BadLocationException, BadPositionCategoryException {
113 synchronized (getLockObject()) {
114 super.addPosition(category, position);
119 * @see org.eclipse.jface.text.AbstractDocument#removePosition(java.lang.String,
120 * org.eclipse.jface.text.Position)
122 public void removePosition(String category, Position position)
123 throws BadPositionCategoryException {
124 synchronized (getLockObject()) {
125 super.removePosition(category, position);
130 * @see org.eclipse.jface.text.AbstractDocument#getPositions(java.lang.String)
132 public Position[] getPositions(String category)
133 throws BadPositionCategoryException {
134 synchronized (getLockObject()) {
135 return super.getPositions(category);