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;
21 * Document that can also be used by a background reconciler.
23 public class PartiallySynchronizedDocument extends Document implements ISynchronizable {
25 private final Object fInternalLockObject= new Object();
26 private Object fLockObject;
29 * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object)
31 public void setLockObject(Object lockObject) {
32 fLockObject= lockObject;
36 * @see org.eclipse.jface.text.ISynchronizable#getLockObject()
38 public Object getLockObject() {
39 return fLockObject == null ? fInternalLockObject : fLockObject;
43 * @see IDocumentExtension#startSequentialRewrite(boolean)
45 public void startSequentialRewrite(boolean normalized) {
46 synchronized (getLockObject()) {
47 super.startSequentialRewrite(normalized);
52 * @see IDocumentExtension#stopSequentialRewrite()
54 public void stopSequentialRewrite() {
55 synchronized (getLockObject()) {
56 super.stopSequentialRewrite();
61 * @see IDocument#get()
64 synchronized (getLockObject()) {
70 * @see IDocument#get(int, int)
72 public String get(int offset, int length) throws BadLocationException {
73 synchronized (getLockObject()) {
74 return super.get(offset, length);
79 * @see IDocument#getChar(int)
81 public char getChar(int offset) throws BadLocationException {
82 synchronized (getLockObject()) {
83 return super.getChar(offset);
88 * @see IDocument#replace(int, int, String)
90 public void replace(int offset, int length, String text) throws BadLocationException {
91 synchronized (getLockObject()) {
92 super.replace(offset, length, text);
97 * @see IDocument#set(String)
99 public void set(String text) {
100 synchronized (getLockObject()) {
106 * @see org.eclipse.jface.text.AbstractDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
108 public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException {
109 synchronized (getLockObject()) {
110 super.addPosition(category, position);
115 * @see org.eclipse.jface.text.AbstractDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
117 public void removePosition(String category, Position position) throws BadPositionCategoryException {
118 synchronized (getLockObject()) {
119 super.removePosition(category, position);
124 * @see org.eclipse.jface.text.AbstractDocument#getPositions(java.lang.String)
126 public Position[] getPositions(String category) throws BadPositionCategoryException {
127 synchronized (getLockObject()) {
128 return super.getPositions(category);