restore calls to getOriginalSourceModule() & getBufferContent() in openBuffer()
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/AbstractSourceModule.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/AbstractSourceModule.java
index b584562..c575366 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/AbstractSourceModule.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/AbstractSourceModule.java
@@ -618,12 +618,13 @@
protected IBuffer openBuffer(IProgressMonitor pm, Object info)
throws ModelException {
// create buffer
- BufferManager bufManager = getBufferManager();
- boolean isWorkingCopy = isWorkingCopy();
+ final BufferManager bufManager = getBufferManager();
+ final boolean isWorkingCopy = isWorkingCopy();
IBuffer buffer = isWorkingCopy ? this.owner.createBuffer(this)
: BufferManager.createBuffer(this);
- if (buffer == null)
+ if (buffer == null) {
return null;
+ }
ISourceModule original = null;
boolean mustSetToOriginalContent = false;
@@ -632,53 +633,55 @@
// synchronized block
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=237772
mustSetToOriginalContent = !isPrimary()
- && (original = new SourceModule((ModelElement) getParent(),
- getElementName(), DefaultWorkingCopyOwner.PRIMARY))
- .isOpen();
+ && (original = getOriginalSourceModule()).isOpen();
}
- // synchronize to ensure that 2 threads are not putting 2 different
- // buffers at the same time
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146331
+ /*
+ * synchronize to ensure that 2 threads are not putting 2 different
+ * buffers at the same time see
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=146331
+ */
synchronized (bufManager) {
- IBuffer existingBuffer = bufManager.getBuffer(this);
+ final IBuffer existingBuffer = bufManager.getBuffer(this);
if (existingBuffer != null)
return existingBuffer;
-
// set the buffer source
if (buffer.getCharacters() == null) {
if (isWorkingCopy) {
if (mustSetToOriginalContent) {
buffer.setContents(original.getSource());
} else {
- IFile file = (IFile) getResource();
- if (file == null || !file.exists()) {
- // initialize buffer with empty contents
- buffer.setContents(CharOperation.NO_CHAR);
- } else {
- buffer.setContents(Util
- .getResourceContentsAsCharArray(file));
+ char[] content;
+ try {
+ content = getBufferContent();
+ } catch (ModelException e) {
+ if (e.getStatus().getCode() == IModelStatusConstants.ELEMENT_DOES_NOT_EXIST) {
+ content = CharOperation.NO_CHAR;
+ } else {
+ throw e;
+ }
}
+ buffer.setContents(content);
}
} else {
- IFile file = (IFile) getResource();
- if (file == null || !file.exists())
- throw newNotPresentException();
- buffer.setContents(Util
- .getResourceContentsAsCharArray(file));
+ char[] content = getBufferContent();
+ buffer.setContents(content);
}
}
// add buffer to buffer cache
- // note this may cause existing buffers to be removed from the
- // buffer cache, but only primary compilation unit's buffer
- // can be closed, thus no call to a client's IBuffer#close() can be
- // done in this synchronized block.
+ /*
+ * note this may cause existing buffers to be removed from the
+ * buffer cache, but only primary compilation unit's buffer can be
+ * closed, thus no call to a client's IBuffer#close() can be done in
+ * this synchronized block.
+ */
bufManager.addBuffer(buffer);
// listen to buffer changes
buffer.addBufferChangedListener(this);
}
+
return buffer;
}