1 11 package org.eclipse.core.internal.filebuffers; 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 28 public class SynchronizableDocument extends Document implements ISynchronizable { 29 30 private Object fLockObject; 31 32 35 public synchronized void setLockObject(Object lockObject) { 36 fLockObject= lockObject; 37 } 38 39 42 public synchronized Object getLockObject() { 43 return fLockObject; 44 } 45 46 49 public void startSequentialRewrite(boolean normalized) { 50 Object lockObject= getLockObject(); 51 if (lockObject == null) { 52 super.startSequentialRewrite(normalized); 53 return; 54 } 55 synchronized (lockObject) { 56 super.startSequentialRewrite(normalized); 57 } 58 } 59 60 63 public void stopSequentialRewrite() { 64 Object lockObject= getLockObject(); 65 if (lockObject == null) { 66 super.stopSequentialRewrite(); 67 return; 68 } 69 synchronized (lockObject) { 70 super.stopSequentialRewrite(); 71 } 72 } 73 74 77 public String get() { 78 Object lockObject= getLockObject(); 79 if (lockObject == null) { 80 return super.get(); 81 } 82 synchronized (lockObject) { 83 return super.get(); 84 } 85 } 86 87 90 public String get(int offset, int length) throws BadLocationException { 91 Object lockObject= getLockObject(); 92 if (lockObject == null) { 93 return super.get(offset, length); 94 } 95 synchronized (lockObject) { 96 return super.get(offset, length); 97 } 98 } 99 100 103 public char getChar(int offset) throws BadLocationException { 104 Object lockObject= getLockObject(); 105 if (lockObject == null) { 106 return super.getChar(offset); 107 } 108 synchronized (lockObject) { 109 return super.getChar(offset); 110 } 111 } 112 113 117 public long getModificationStamp() { 118 Object lockObject= getLockObject(); 119 if (lockObject == null) { 120 return super.getModificationStamp(); 121 } 122 synchronized (lockObject) { 123 return super.getModificationStamp(); 124 } 125 } 126 127 130 public void replace(int offset, int length, String text) throws BadLocationException { 131 Object lockObject= getLockObject(); 132 if (lockObject == null) { 133 super.replace(offset, length, text); 134 return; 135 } 136 synchronized (lockObject) { 137 super.replace(offset, length, text); 138 } 139 } 140 141 144 public void replace(int offset, int length, String text, long modificationStamp) throws BadLocationException { 145 Object lockObject= getLockObject(); 146 if (lockObject == null) { 147 super.replace(offset, length, text, modificationStamp); 148 return; 149 } 150 synchronized (lockObject) { 151 super.replace(offset, length, text, modificationStamp); 152 } 153 } 154 155 158 public void set(String text) { 159 Object lockObject= getLockObject(); 160 if (lockObject == null) { 161 super.set(text); 162 return; 163 } 164 synchronized (lockObject) { 165 super.set(text); 166 } 167 } 168 169 172 public void set(String text, long modificationStamp) { 173 Object lockObject= getLockObject(); 174 if (lockObject == null) { 175 super.set(text, modificationStamp); 176 return; 177 } 178 synchronized (lockObject) { 179 super.set(text, modificationStamp); 180 } 181 } 182 183 186 public void addPosition(String category, Position position) throws BadLocationException, BadPositionCategoryException { 187 Object lockObject= getLockObject(); 188 if (lockObject == null) { 189 super.addPosition(category, position); 190 return; 191 } 192 synchronized (lockObject) { 193 super.addPosition(category, position); 194 } 195 } 196 197 200 public void removePosition(String category, Position position) throws BadPositionCategoryException { 201 Object lockObject= getLockObject(); 202 if (lockObject == null) { 203 super.removePosition(category, position); 204 return; 205 } 206 synchronized (lockObject) { 207 super.removePosition(category, position); 208 } 209 } 210 211 214 public Position[] getPositions(String category) throws BadPositionCategoryException { 215 Object lockObject= getLockObject(); 216 if (lockObject == null) { 217 return super.getPositions(category); 218 } 219 synchronized (lockObject) { 220 return super.getPositions(category); 221 } 222 } 223 } 224 | Popular Tags |