Search in sources :

Example 6 with BasicStructuredDocument

use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.

the class AbstractModelLoader method transformInstance.

/**
 * this work is done better elsewhere, but done here for this version to
 * reduce changes. especially since the need for it should go away once we
 * no longer need to re-use old document instance.
 */
private void transformInstance(IStructuredDocument oldInstance, IStructuredDocument newInstance) {
    /**
     * https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920
     *
     * JSP taglib support broken, correct by duplicating extended setup
     * information (BlockTagParser extension,
     * StructuredDocumentRegionParser extensions)
     */
    RegionParser oldParser = oldInstance.getParser();
    RegionParser newParser = newInstance.getParser().newInstance();
    // parser
    if (oldParser instanceof StructuredDocumentRegionParserExtension && newParser instanceof StructuredDocumentRegionParserExtension) {
        List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();
        for (int i = 0; i < oldHandlers.size(); i++) {
            StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));
            if (handler instanceof StructuredDocumentRegionHandlerExtension) {
            /**
             * Skip the transferring here, the handler will do this
             * after everything else but the source is transferred.
             */
            } else {
                ((StructuredDocumentRegionParser) oldParser).removeStructuredDocumentRegionHandler(handler);
                ((StructuredDocumentRegionParser) newParser).addStructuredDocumentRegionHandler(handler);
                handler.resetNodes();
            }
        }
    }
    // Add any global BlockMarkers to the new parser
    if (oldParser instanceof BlockTagParser && newParser instanceof BlockTagParser) {
        List oldBlockMarkers = ((BlockTagParser) oldParser).getBlockMarkers();
        for (int i = 0; i < oldBlockMarkers.size(); i++) {
            BlockMarker blockMarker = ((BlockMarker) oldBlockMarkers.get(i));
            if (blockMarker.isGlobal()) {
                ((BlockTagParser) newParser).addBlockMarker(blockMarker);
            }
        }
    }
    ((BasicStructuredDocument) oldInstance).setParser(newParser);
    ((BasicStructuredDocument) oldInstance).setReParser(newInstance.getReParser().newInstance());
    if (newInstance.getDocumentPartitioner() instanceof StructuredTextPartitioner) {
        StructuredTextPartitioner partitioner = null;
        if (oldInstance instanceof IDocumentExtension3 && newInstance instanceof IDocumentExtension3) {
            partitioner = ((StructuredTextPartitioner) ((IDocumentExtension3) newInstance).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING));
            if (partitioner != null) {
                partitioner = (StructuredTextPartitioner) partitioner.newInstance();
            }
            ((IDocumentExtension3) oldInstance).setDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING, partitioner);
        }
        if (partitioner == null) {
            partitioner = (StructuredTextPartitioner) ((StructuredTextPartitioner) newInstance.getDocumentPartitioner()).newInstance();
            oldInstance.setDocumentPartitioner(partitioner);
        }
        if (partitioner != null) {
            partitioner.connect(oldInstance);
        }
    }
    String existingLineDelimiter = null;
    try {
        existingLineDelimiter = newInstance.getLineDelimiter(0);
    } catch (BadLocationException e) {
        // if empty file, assume platform default
        // TODO: should be using user set preference, per content type?
        // $NON-NLS-1$
        existingLineDelimiter = System.getProperty("line.separator");
    }
    // $NON-NLS-1$);
    oldInstance.setLineDelimiter(existingLineDelimiter);
    if (newInstance.getEncodingMemento() != null) {
        oldInstance.setEncodingMemento((EncodingMemento) newInstance.getEncodingMemento().clone());
    }
    /**
     * https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=4920
     *
     * JSP taglib support broken, correct by duplicating extended setup
     * information (BlockTagParser extension,
     * StructuredDocumentRegionParser extensions)
     */
    if (oldParser instanceof StructuredDocumentRegionParserExtension && newParser instanceof StructuredDocumentRegionParserExtension) {
        List oldHandlers = ((StructuredDocumentRegionParserExtension) oldParser).getStructuredDocumentRegionHandlers();
        for (int i = 0; i < oldHandlers.size(); i++) {
            StructuredDocumentRegionHandler handler = ((StructuredDocumentRegionHandler) oldHandlers.get(i));
            if (handler instanceof StructuredDocumentRegionHandlerExtension) {
                StructuredDocumentRegionHandlerExtension handlerExtension = (StructuredDocumentRegionHandlerExtension) handler;
                handlerExtension.setStructuredDocument(oldInstance);
            }
        }
    }
    String holdString = newInstance.get();
    newInstance = null;
    oldInstance.set(holdString);
}
Also used : StructuredDocumentRegionParserExtension(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) StructuredDocumentRegionHandler(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) StructuredDocumentRegionHandlerExtension(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandlerExtension) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) BlockMarker(org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) ArrayList(java.util.ArrayList) List(java.util.List) BlockTagParser(org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 7 with BasicStructuredDocument

use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.

the class JSPModelLoader method newStructuredDocument.

/**
 * This method must return a new instance of IStructuredDocument, that has
 * been initialized with appropriate parser. For many loaders, the
 * (default) parser used is known for any input. For others, the correct
 * parser (and its initialization) is normall dependent on the content of
 * the file. This no-argument method should assume "empty input" and would
 * therefore return the default parser for the default contentType.
 *
 * If the parser is to handle tag libraries, it must have a TaglibSupport
 * object with a valid URIResolver and this IStructuredDocument attached
 * to it before the contents are set on the IStructuredDocument.
 */
public IStructuredDocument newStructuredDocument() {
    IStructuredDocument structuredDocument = StructuredDocumentFactory.getNewStructuredDocumentInstance(getParser());
    ((BasicStructuredDocument) structuredDocument).setReParser(new JSPReParser());
    // structuredDocument.setDocumentPartitioner(new
    // JSPJavaDocumentPartioner());
    // even though this is an "empty model" ... we want it to have at
    // least the
    // default embeddeded content type handler
    EmbeddedTypeHandler embeddedType = getJSPDefaultEmbeddedType(null);
    embeddedType.initializeParser(structuredDocument.getParser());
    return structuredDocument;
}
Also used : EmbeddedTypeHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) JSPReParser(org.eclipse.jst.jsp.core.internal.parser.JSPReParser)

Example 8 with BasicStructuredDocument

use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.

the class PositionUpdatingCornerCasesTest method createDocument.

private IDocument createDocument(String contents) {
    IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.jst.jsp.jspsource");
    BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
    document.set(contents);
    return document;
}
Also used : BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Example 9 with BasicStructuredDocument

use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.

the class TransitionTests method testSoftRevert.

public void testSoftRevert() throws CoreException, IOException {
    // $NON-NLS-1$
    String filePath = "testfiles/xml/EmptyFile.xml";
    IFile file = (IFile) fTestProject.findMember(filePath);
    // $NON-NLS-1$
    assertNotNull("Test Case in error. Could not find file " + filePath, file);
    IPath locationPath = file.getLocation();
    ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
    bufferManager.connect(locationPath, null);
    ITextFileBuffer buffer = bufferManager.getTextFileBuffer(locationPath);
    IDocument document = buffer.getDocument();
    assertNotNull(document);
    // $NON-NLS-1$
    assertTrue("wrong class of document", document instanceof BasicStructuredDocument);
    // $NON-NLS-1$
    assertTrue("wrong partitioner in document.", ((IDocumentExtension3) document).getDocumentPartitioner(IStructuredPartitioning.DEFAULT_STRUCTURED_PARTITIONING) instanceof StructuredTextPartitionerForXML);
    IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit((IStructuredDocument) document);
    try {
        try {
            // $NON-NLS-1$
            document.replace(0, 0, "__");
            // $NON-NLS-1$
            document.replace(2, 0, "<a");
            // $NON-NLS-1$
            document.replace(4, 0, ">");
            // $NON-NLS-1$
            document.replace(5, 0, "  ");
        } catch (BadLocationException e) {
            assertNull(e);
        }
        // $NON-NLS-1$
        document.set("");
    } finally {
        model.releaseFromEdit();
        bufferManager.disconnect(locationPath, null);
    }
}
Also used : StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) IFile(org.eclipse.core.resources.IFile) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IPath(org.eclipse.core.runtime.IPath) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 10 with BasicStructuredDocument

use of org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument in project webtools.sourceediting by eclipse.

the class ExclusivePositionUpdaterTest method createDocument.

private IDocument createDocument(String contents) {
    IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerForContentTypeId("org.eclipse.jst.jsp.jspsource");
    BasicStructuredDocument document = (BasicStructuredDocument) handler.getDocumentLoader().createNewStructuredDocument();
    document.set(contents);
    return document;
}
Also used : BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)

Aggregations

BasicStructuredDocument (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)14 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)5 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)2 JSPReParser (org.eclipse.jst.jsp.core.internal.parser.JSPReParser)2 EmbeddedTypeHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.EmbeddedTypeHandler)2 BasicStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.text.BasicStructuredDocumentRegion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)1 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 IDocument (org.eclipse.jface.text.IDocument)1 TLDCMDocumentManager (org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager)1 CSSStructuredDocumentReParser (org.eclipse.wst.css.core.internal.text.CSSStructuredDocumentReParser)1 DTDStructuredDocumentReParser (org.eclipse.wst.dtd.core.internal.text.DTDStructuredDocumentReParser)1 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)1 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)1