7dfb207d6d2f3d893e173cb78a5b0489b8e9ccec
[phpeclipse.git] /
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
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  **********************************************************************/
11 package net.sourceforge.phpeclipse.phpeditor;
12
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;
18
19 /**
20  * Document that can also be used by a background reconciler.
21  */
22 public class PartiallySynchronizedDocument extends Document implements
23                 ISynchronizable {
24
25         private final Object fInternalLockObject = new Object();
26
27         private Object fLockObject;
28
29         /*
30          * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object)
31          */
32         public void setLockObject(Object lockObject) {
33                 fLockObject = lockObject;
34         }
35
36         /*
37          * @see org.eclipse.jface.text.ISynchronizable#getLockObject()
38          */
39         public Object getLockObject() {
40                 return fLockObject == null ? fInternalLockObject : fLockObject;
41         }
42
43         /*
44          * @see IDocumentExtension#startSequentialRewrite(boolean)
45          */
46         public void startSequentialRewrite(boolean normalized) {
47                 synchronized (getLockObject()) {
48                         super.startSequentialRewrite(normalized);
49                 }
50         }
51
52         /*
53          * @see IDocumentExtension#stopSequentialRewrite()
54          */
55         public void stopSequentialRewrite() {
56                 synchronized (getLockObject()) {
57                         super.stopSequentialRewrite();
58                 }
59         }
60
61         /*
62          * @see IDocument#get()
63          */
64         public String get() {
65                 synchronized (getLockObject()) {
66                         return super.get();
67                 }
68         }
69
70         /*
71          * @see IDocument#get(int, int)
72          */
73         public String get(int offset, int length) throws BadLocationException {
74                 synchronized (getLockObject()) {
75                         return super.get(offset, length);
76                 }
77         }
78
79         /*
80          * @see IDocument#getChar(int)
81          */
82         public char getChar(int offset) throws BadLocationException {
83                 synchronized (getLockObject()) {
84                         return super.getChar(offset);
85                 }
86         }
87
88         /*
89          * @see IDocument#replace(int, int, String)
90          */
91         public void replace(int offset, int length, String text)
92                         throws BadLocationException {
93                 synchronized (getLockObject()) {
94                         super.replace(offset, length, text);
95                 }
96         }
97
98         /*
99          * @see IDocument#set(String)
100          */
101         public void set(String text) {
102                 synchronized (getLockObject()) {
103                         super.set(text);
104                 }
105         }
106
107         /*
108          * @see org.eclipse.jface.text.AbstractDocument#addPosition(java.lang.String,
109          *      org.eclipse.jface.text.Position)
110          */
111         public void addPosition(String category, Position position)
112                         throws BadLocationException, BadPositionCategoryException {
113                 synchronized (getLockObject()) {
114                         super.addPosition(category, position);
115                 }
116         }
117
118         /*
119          * @see org.eclipse.jface.text.AbstractDocument#removePosition(java.lang.String,
120          *      org.eclipse.jface.text.Position)
121          */
122         public void removePosition(String category, Position position)
123                         throws BadPositionCategoryException {
124                 synchronized (getLockObject()) {
125                         super.removePosition(category, position);
126                 }
127         }
128
129         /*
130          * @see org.eclipse.jface.text.AbstractDocument#getPositions(java.lang.String)
131          */
132         public Position[] getPositions(String category)
133                         throws BadPositionCategoryException {
134                 synchronized (getLockObject()) {
135                         return super.getPositions(category);
136                 }
137         }
138 }