Search in sources :

Example 1 with IEncodedDocument

use of org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument in project liferay-ide by liferay.

the class AlloyJSPDocumentLoader method newEncodedDocument.

@Override
protected IEncodedDocument newEncodedDocument() {
    IEncodedDocument retval = super.newEncodedDocument();
    if (retval instanceof IStructuredDocument) {
        IStructuredDocument doc = (IStructuredDocument) retval;
        RegionParser parser = doc.getParser();
        if (parser instanceof BlockTagParser) {
            BlockTagParser blockParser = (BlockTagParser) parser;
            BlockMarker bm = new BlockMarker("aui:script", null, DOMRegionContext.BLOCK_TEXT, false);
            blockParser.addBlockMarker(bm);
        }
    }
    return retval;
}
Also used : BlockMarker(org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) BlockTagParser(org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Example 2 with IEncodedDocument

use of org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument in project webtools.sourceediting by eclipse.

the class AbstractDocumentLoader method createNewStructuredDocument.

public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream, EncodingRule encodingRule) throws UnsupportedEncodingException, IOException {
    if (filename == null && inputStream == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("can not have both null filename and inputstream");
    }
    IEncodedDocument structuredDocument = createNewStructuredDocument();
    CodedReaderCreator codedReaderCreator = getCodedReaderCreator();
    try {
        codedReaderCreator.set(filename, inputStream);
        codedReaderCreator.setEncodingRule(encodingRule);
        fEncodingMemento = codedReaderCreator.getEncodingMemento();
        fFullPreparedReader = codedReaderCreator.getCodedReader();
        structuredDocument.setEncodingMemento(fEncodingMemento);
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } catch (CoreException e) {
        // impossible in this context
        throw new Error(e);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : CodedReaderCreator(org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator) CoreException(org.eclipse.core.runtime.CoreException) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 3 with IEncodedDocument

use of org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument in project webtools.sourceediting by eclipse.

the class JSPDocumentLoader method createNewStructuredDocument.

public IEncodedDocument createNewStructuredDocument(String filename, InputStream inputStream) throws UnsupportedEncodingException, IOException {
    if (filename == null && inputStream == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("can not have both null filename and inputstream");
    }
    IEncodedDocument structuredDocument = createNewStructuredDocument();
    CodedReaderCreator codedReaderCreator = new CodedReaderCreator();
    try {
        codedReaderCreator.set(filename, inputStream);
        fFullPreparedReader = codedReaderCreator.getCodedReader();
        fEncodingMemento = codedReaderCreator.getEncodingMemento();
        structuredDocument.setEncodingMemento(fEncodingMemento);
        // the fact that file is null means this method/code path is no
        // good for JSP fragments
        EmbeddedTypeHandler embeddedType = getEmbeddedType((IFile) null);
        fFullPreparedReader.reset();
        if (embeddedType != null)
            embeddedType.initializeParser(((IStructuredDocument) structuredDocument).getParser());
        setDocumentContentsFromReader(structuredDocument, fFullPreparedReader);
    } catch (CoreException e) {
        // impossible in this context
        throw new Error(e);
    } finally {
        if (fFullPreparedReader != null) {
            fFullPreparedReader.close();
        }
    }
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) CodedReaderCreator(org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator) CoreException(org.eclipse.core.runtime.CoreException) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 4 with IEncodedDocument

use of org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument in project webtools.sourceediting by eclipse.

the class ModelManagerImpl method createUnManagedStructuredModelFor.

/**
 * Conveience method. It depends on the loaders newModel method to return
 * an appropriate StrucuturedModel appropriately initialized.
 */
public IStructuredModel createUnManagedStructuredModelFor(IFile iFile) throws IOException, CoreException {
    IStructuredModel result = null;
    result = createUnManagedEmptyModelFor(iFile);
    IDocumentLoader loader = result.getModelHandler().getDocumentLoader();
    IEncodedDocument document = loader.createNewStructuredDocument(iFile);
    result.getStructuredDocument().setText(this, document.get());
    return result;
}
Also used : IDocumentLoader(org.eclipse.wst.sse.core.internal.document.IDocumentLoader) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)

Example 5 with IEncodedDocument

use of org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument 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

IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)15 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)4 ContentTypeEncodingPreferences (org.eclipse.wst.sse.core.internal.encoding.ContentTypeEncodingPreferences)4 Preferences (org.osgi.service.prefs.Preferences)4 CoreException (org.eclipse.core.runtime.CoreException)3 CodedReaderCreator (org.eclipse.wst.sse.core.internal.encoding.CodedReaderCreator)3 RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IOException (java.io.IOException)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)1 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)1 JSPDocumentLoader (org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentLoader)1 CSSDocumentLoader (org.eclipse.wst.css.core.internal.encoding.CSSDocumentLoader)1 HTMLDocumentLoader (org.eclipse.wst.html.core.internal.encoding.HTMLDocumentLoader)1 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)1