Search in sources :

Example 71 with IStructuredDocument

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) FileNotFoundException(java.io.FileNotFoundException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 72 with IStructuredDocument

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;
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner)

Example 73 with IStructuredDocument

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;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ResourceAlreadyExists(org.eclipse.wst.sse.core.internal.provisional.exceptions.ResourceAlreadyExists) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 74 with IStructuredDocument

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);
    }
}
Also used : DocumentChanged(org.eclipse.wst.sse.core.internal.provisional.DocumentChanged) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 75 with IStructuredDocument

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));
    }
}
Also used : IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20