use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method doTestNonExistentDocument.
private void doTestNonExistentDocument(String filePath, Class expectedDocumentClass, Class expectedPartioner) throws ResourceAlreadyExists, ResourceInUse, IOException, CoreException {
String contents = null;
boolean expectedExceptionCaught = false;
IModelManager modelManager = StructuredModelManager.getModelManager();
IFile file = (IFile) fTestProject.findMember(filePath);
if (file == null) {
file = fTestProject.getFile(filePath);
}
IStructuredDocument document = null;
try {
document = modelManager.createStructuredDocumentFor(file);
} catch (FileNotFoundException e) {
expectedExceptionCaught = true;
}
if (expectedExceptionCaught) {
document = modelManager.createNewStructuredDocumentFor(file);
assertNotNull(document);
assertTrue("wrong class of document", expectedDocumentClass.isInstance(document));
IDocumentPartitioner setupPartitioner = null;
if (Utilities.contains(expectedDocumentClass.getInterfaces(), IDocumentExtension3.class)) {
setupPartitioner = ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING);
} else {
setupPartitioner = document.getDocumentPartitioner();
}
assertTrue("wrong partitioner in document.", expectedPartioner.isInstance(setupPartitioner));
contents = document.get();
assertNotNull("contents were null", contents);
assertTrue("contents were *not* empty as expected", contents.length() == 0);
} else {
assertTrue("FileNotFound exception was *not* thrown as expected", false);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class BasicStructuredDocument method newInstance.
public IStructuredDocument newInstance() {
IStructuredDocument newInstance = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser().newInstance());
((BasicStructuredDocument) newInstance).setReParser(getReParser().newInstance());
if (getDocumentPartitioner() instanceof StructuredTextPartitioner) {
newInstance.setDocumentPartitioner(((StructuredTextPartitioner) getDocumentPartitioner()).newInstance());
newInstance.getDocumentPartitioner().connect(newInstance);
}
newInstance.setLineDelimiter(getLineDelimiter());
if (getEncodingMemento() != null) {
newInstance.setEncodingMemento((EncodingMemento) getEncodingMemento().clone());
}
return newInstance;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class ModelManagerImpl method createNewStructuredDocumentFor.
/**
* Factory method, since a proper IStructuredDocument must have a proper
* parser assigned. Note: its assume that IFile does not actually exist as
* a resource yet. If it does, ResourceAlreadyExists exception is thrown.
* If the resource does already exist, then createStructuredDocumentFor is
* the right API to use.
*
* @throws ResourceInUse
*/
public IStructuredDocument createNewStructuredDocumentFor(IFile iFile) throws ResourceAlreadyExists, IOException, CoreException {
if (iFile.exists()) {
throw new ResourceAlreadyExists(iFile.getFullPath().toOSString());
}
// Will reconsider in future version
// String id = calculateId(iFile);
// if (isResourceInUse(id)) {
// throw new ResourceInUse(iFile.getFullPath().toOSString());
// }
IDocumentLoader loader = null;
IModelHandler handler = calculateType(iFile);
loader = handler.getDocumentLoader();
// for this API, "createNew" we assume the IFile does not exist yet
// as checked above, so just create empty document.
IStructuredDocument result = (IStructuredDocument) loader.createNewStructuredDocument();
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class AbstractStructuredModel method setStructuredDocument.
public void setStructuredDocument(IStructuredDocument newStructuredDocument) {
boolean lifeCycleNotification = false;
if (fStructuredDocument != null) {
fStructuredDocument.removeDocumentChangedListener(fDirtyStateWatcher);
fStructuredDocument.removeDocumentAboutToChangeListener(fDocumentToModelNotifier);
fStructuredDocument.removeDocumentChangedListener(fDocumentToModelNotifier);
// prechange notification
lifeCycleNotification = true;
ModelLifecycleEvent modelLifecycleEvent = new DocumentChanged(ModelLifecycleEvent.PRE_EVENT, this, fStructuredDocument, newStructuredDocument);
signalLifecycleEvent(modelLifecycleEvent);
}
// hold for life cycle notification
IStructuredDocument previousDocument = fStructuredDocument;
// the actual change
fStructuredDocument = newStructuredDocument;
// so we can set our dirty state flag
if (fStructuredDocument != null) {
fStructuredDocument.addDocumentChangedListener(fDirtyStateWatcher);
fStructuredDocument.addDocumentAboutToChangeListener(fDocumentToModelNotifier);
fStructuredDocument.addDocumentChangedListener(fDocumentToModelNotifier);
}
if (lifeCycleNotification) {
// post change notification
ModelLifecycleEvent modelLifecycleEvent = new DocumentChanged(ModelLifecycleEvent.POST_EVENT, this, previousDocument, newStructuredDocument);
signalLifecycleEvent(modelLifecycleEvent);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument in project webtools.sourceediting by eclipse.
the class AbstractModelLoader method load.
public void load(String filename, InputStream inputStream, IStructuredModel model, String junk, String dummy) throws UnsupportedEncodingException, java.io.IOException {
long memoryUsed = 0;
if (DEBUG) {
memoryUsed = computeMem();
// $NON-NLS-1$
System.out.println("measuring heap memory for " + filename);
// System.out.println("heap memory used before load: " +
// memoryUsed);
}
// during an initial load, we expect the olddocument to be empty
// during re-load, however, it would be full.
IEncodedDocument newstructuredDocument = null;
IEncodedDocument oldStructuredDocument = model.getStructuredDocument();
// get new document
if (inputStream == null) {
newstructuredDocument = getDocumentLoader().createNewStructuredDocument();
} else {
newstructuredDocument = getDocumentLoader().createNewStructuredDocument(filename, inputStream);
}
if (DEBUG) {
long memoryAtEnd = computeMem();
// System.out.println("heap memory used after loading new
// document: " + memoryAtEnd);
// $NON-NLS-1$
System.out.println(" heap memory implied used by document: " + (memoryAtEnd - memoryUsed));
}
// TODO: need to straighten out IEncodedDocument mess
if (newstructuredDocument instanceof IStructuredDocument) {
transformInstance((IStructuredDocument) oldStructuredDocument, (IStructuredDocument) newstructuredDocument);
} else {
// we don't really expect this case, just included for safety
oldStructuredDocument.set(newstructuredDocument.get());
}
// original hack
// model.setStructuredDocument((IStructuredDocument)
// structuredDocument);
// ((IStructuredDocument) structuredDocument).fireNewDocument(this);
documentLoaderInstance = null;
// documentLoaderInstance = null;
if (DEBUG) {
long memoryAtEnd = computeMem();
// System.out.println("heap memory used after setting to model: "
// + memoryAtEnd);
// $NON-NLS-1$
System.out.println(" heap memory implied used by document and model: " + (memoryAtEnd - memoryUsed));
}
}
Aggregations