Search in sources :

Example 1 with StructuredTextPartitioner

use of org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner 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 2 with StructuredTextPartitioner

use of org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner 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 3 with StructuredTextPartitioner

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

the class StructuredTextPartitionerForJSP method createStructuredTextPartitioner.

private IStructuredTextPartitioner createStructuredTextPartitioner(IStructuredDocument structuredDocument) {
    IStructuredTextPartitioner result = null;
    // this same detector should underly content describer, to have consistent results
    JSPDocumentHeadContentDetector jspHeadContentDetector = new JSPDocumentHeadContentDetector();
    jspHeadContentDetector.set(structuredDocument);
    String contentType = null;
    try {
        contentType = jspHeadContentDetector.getContentType();
        // if XHTML or WML, that trumps what is in the page directive
        if (jspHeadContentDetector.isXHTML() || jspHeadContentDetector.isWML()) {
            contentType = "text/html";
        }
    } catch (IOException e) {
        // impossible in this context, since working with document stream
        throw new Error(e);
    }
    // null or empty, treat as "default"
    if (contentType == null || contentType.length() == 0) {
        // $NON-NLS-1$
        contentType = "text/html";
    }
    // make or tie-in to existing registry.
    if (contentType.equalsIgnoreCase(HTML_MIME_TYPE) || contentType.equalsIgnoreCase(VND_WAP_WML)) {
        result = new StructuredTextPartitionerForHTML();
        result.connect(structuredDocument);
    } else if (contentType.equalsIgnoreCase(XHTML_MIME_TYPE)) {
        result = new StructuredTextPartitionerForHTML();
        result.connect(structuredDocument);
    } else if (contentType.equalsIgnoreCase(XML_MIME_TYPE) || contentType.endsWith("+xml")) {
        // $NON-NLS-1$
        result = new StructuredTextPartitionerForXML();
        result.connect(structuredDocument);
    } else {
        result = new StructuredTextPartitioner();
        result.connect(structuredDocument);
    }
    return result;
}
Also used : JSPDocumentHeadContentDetector(org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentHeadContentDetector) StructuredTextPartitionerForXML(org.eclipse.wst.xml.core.internal.text.rules.StructuredTextPartitionerForXML) StructuredTextPartitionerForHTML(org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML) IOException(java.io.IOException) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner) IStructuredTextPartitioner(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)

Example 4 with StructuredTextPartitioner

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

the class StructuredTextViewerConfiguration method getContentFormatter.

/**
 * Returns the content formatter ready to be used with the given source
 * viewer.
 * <p>
 * It is not recommended that clients override this method as it may
 * become <code>final</code> in the future and replaced by an extensible
 * framework.
 * </p>
 *
 * @param sourceViewer
 *            the source viewer to be configured by this configuration
 * @return a content formatter or <code>null</code> if formatting should
 *         not be supported
 */
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
    // try to use the StructuredTextMultiPassContentFormatter so that it
    // picks up any additional formatting strategies contributed via the
    // editorConfiguration extension point
    IContentFormatter formatter = null;
    if (sourceViewer != null) {
        IDocument document = sourceViewer.getDocument();
        if (document instanceof IDocumentExtension3) {
            String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
            IDocumentPartitioner partitioner = ((IDocumentExtension3) document).getDocumentPartitioner(partitioning);
            if (partitioner instanceof StructuredTextPartitioner) {
                String defaultPartitionType = ((StructuredTextPartitioner) partitioner).getDefaultPartitionType();
                formatter = new StructuredTextMultiPassContentFormatter(partitioning, defaultPartitionType);
            }
        }
    }
    return formatter;
}
Also used : IContentFormatter(org.eclipse.jface.text.formatter.IContentFormatter) IDocumentExtension3(org.eclipse.jface.text.IDocumentExtension3) IDocumentPartitioner(org.eclipse.jface.text.IDocumentPartitioner) IDocument(org.eclipse.jface.text.IDocument) StructuredTextPartitioner(org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner)

Aggregations

StructuredTextPartitioner (org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner)4 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)1 IContentFormatter (org.eclipse.jface.text.formatter.IContentFormatter)1 JSPDocumentHeadContentDetector (org.eclipse.jst.jsp.core.internal.encoding.JSPDocumentHeadContentDetector)1 StructuredTextPartitionerForHTML (org.eclipse.wst.html.core.internal.text.StructuredTextPartitionerForHTML)1 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)1 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)1 RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)1 StructuredDocumentRegionHandler (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler)1 StructuredDocumentRegionHandlerExtension (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandlerExtension)1 StructuredDocumentRegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)1 StructuredDocumentRegionParserExtension (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IStructuredTextPartitioner (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextPartitioner)1