KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > PartiallySynchronizedDocument


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.javaeditor;
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 /**
21  * Document that can also be used by a background reconciler.
22  */

23 public class PartiallySynchronizedDocument extends Document implements ISynchronizable {
24     
25     private final Object JavaDoc fInternalLockObject= new Object JavaDoc();
26     private Object JavaDoc fLockObject;
27     
28     /*
29      * @see org.eclipse.jface.text.ISynchronizable#setLockObject(java.lang.Object)
30      */

31     public void setLockObject(Object JavaDoc lockObject) {
32         fLockObject= lockObject;
33     }
34
35     /*
36      * @see org.eclipse.jface.text.ISynchronizable#getLockObject()
37      */

38     public Object JavaDoc getLockObject() {
39         return fLockObject == null ? fInternalLockObject : fLockObject;
40     }
41     
42     /*
43      * @see IDocumentExtension#startSequentialRewrite(boolean)
44      */

45     public void startSequentialRewrite(boolean normalized) {
46         synchronized (getLockObject()) {
47             super.startSequentialRewrite(normalized);
48         }
49     }
50
51     /*
52      * @see IDocumentExtension#stopSequentialRewrite()
53      */

54     public void stopSequentialRewrite() {
55         synchronized (getLockObject()) {
56             super.stopSequentialRewrite();
57         }
58     }
59     
60     /*
61      * @see IDocument#get()
62      */

63     public String JavaDoc get() {
64         synchronized (getLockObject()) {
65             return super.get();
66         }
67     }
68     
69     /*
70      * @see IDocument#get(int, int)
71      */

72     public String JavaDoc get(int offset, int length) throws BadLocationException {
73         synchronized (getLockObject()) {
74             return super.get(offset, length);
75         }
76     }
77     
78     /*
79      * @see IDocument#getChar(int)
80      */

81     public char getChar(int offset) throws BadLocationException {
82         synchronized (getLockObject()) {
83             return super.getChar(offset);
84         }
85     }
86     
87     /*
88      * @see org.eclipse.jface.text.IDocumentExtension4#getModificationStamp()
89      * @since 3.1
90      */

91     public long getModificationStamp() {
92         synchronized (getLockObject()) {
93             return super.getModificationStamp();
94         }
95     }
96     
97     /*
98      * @see IDocument#replace(int, int, String)
99      */

100     public void replace(int offset, int length, String JavaDoc text) throws BadLocationException {
101         synchronized (getLockObject()) {
102             super.replace(offset, length, text);
103         }
104     }
105     
106     /*
107      * @see IDocumentExtension4#replace(int, int, String, long)
108      */

109     public void replace(int offset, int length, String JavaDoc text, long modificationStamp) throws BadLocationException {
110         synchronized (getLockObject()) {
111             super.replace(offset, length, text, modificationStamp);
112         }
113     }
114     
115     /*
116      * @see IDocument#set(String)
117      */

118     public void set(String JavaDoc text) {
119         synchronized (getLockObject()) {
120             super.set(text);
121         }
122     }
123     
124     /*
125      * @see IDocumentExtension4#set(String, long)
126      */

127     public void set(String JavaDoc text, long modificationStamp) {
128         synchronized (getLockObject()) {
129             super.set(text, modificationStamp);
130         }
131     }
132     
133     /*
134      * @see org.eclipse.jface.text.AbstractDocument#addPosition(java.lang.String, org.eclipse.jface.text.Position)
135      */

136     public void addPosition(String JavaDoc category, Position position) throws BadLocationException, BadPositionCategoryException {
137         synchronized (getLockObject()) {
138             super.addPosition(category, position);
139         }
140     }
141     
142     /*
143      * @see org.eclipse.jface.text.AbstractDocument#removePosition(java.lang.String, org.eclipse.jface.text.Position)
144      */

145     public void removePosition(String JavaDoc category, Position position) throws BadPositionCategoryException {
146         synchronized (getLockObject()) {
147             super.removePosition(category, position);
148         }
149     }
150     
151     /*
152      * @see org.eclipse.jface.text.AbstractDocument#getPositions(java.lang.String)
153      */

154     public Position[] getPositions(String JavaDoc category) throws BadPositionCategoryException {
155         synchronized (getLockObject()) {
156             return super.getPositions(category);
157         }
158     }
159 }
160
Popular Tags