Search in sources :

Example 1 with StructuredDocumentRegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser in project webtools.sourceediting by eclipse.

the class DocumentRegionProcessor method uninstall.

/**
 * @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#uninstall()
 */
public void uninstall() {
    if (isInstalled()) {
        IReconcilingStrategy validatorStrategy = getValidatorStrategy();
        if (validatorStrategy != null) {
            if (validatorStrategy instanceof IReleasable)
                ((IReleasable) validatorStrategy).release();
        }
        if (fSpellcheckStrategy != null) {
            fSpellcheckStrategy.setDocument(null);
            fSpellcheckStrategy = null;
        }
        fReconcileListeners = new ISourceReconcilingListener[0];
        if (getDocument() instanceof IStructuredDocument) {
            RegionParser parser = ((IStructuredDocument) getDocument()).getParser();
            if (parser instanceof StructuredDocumentRegionParser) {
                ((StructuredDocumentRegionParser) parser).removeStructuredDocumentRegionHandler(fResetHandler);
            }
        }
    }
    super.uninstall();
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) IReleasable(org.eclipse.wst.sse.ui.internal.IReleasable) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)

Example 2 with StructuredDocumentRegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser 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 StructuredDocumentRegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser in project webtools.sourceediting by eclipse.

the class StructuredFileTaskScanner method findTasks.

private void findTasks(IFile file, final TaskTag[] taskTags, final IProgressMonitor monitor) {
    try {
        IModelHandler handler = ModelHandlerRegistry.getInstance().getHandlerFor(file);
        // records if the optimized streamish parse was possible
        boolean didStreamParse = false;
        final IEncodedDocument defaultDocument = handler.getDocumentLoader().createNewStructuredDocument();
        if (defaultDocument instanceof IStructuredDocument) {
            RegionParser parser = ((IStructuredDocument) defaultDocument).getParser();
            if (parser instanceof StructuredDocumentRegionParser) {
                didStreamParse = true;
                String charset = detectCharset(file);
                StructuredDocumentRegionParser documentParser = (StructuredDocumentRegionParser) parser;
                final IDocument textDocument = new Document();
                setDocumentContent(textDocument, file.getContents(true), charset);
                monitor.beginTask("", textDocument.getLength());
                documentParser.reset(new DocumentReader(textDocument));
                documentParser.addStructuredDocumentRegionHandler(new StructuredDocumentRegionHandler() {

                    public void nodeParsed(IStructuredDocumentRegion documentRegion) {
                        ITextRegionList regions = documentRegion.getRegions();
                        for (int j = 0; j < regions.size(); j++) {
                            ITextRegion comment = regions.get(j);
                            findTasks(textDocument, taskTags, documentRegion, comment);
                        }
                        // disconnect the document regions
                        if (documentRegion.getPrevious() != null) {
                            documentRegion.getPrevious().setPrevious(null);
                            documentRegion.getPrevious().setNext(null);
                        }
                        if (monitor.isCanceled()) {
                            // $NON-NLS-1$
                            textDocument.set("");
                        }
                        monitor.worked(documentRegion.getLength());
                    }

                    public void resetNodes() {
                    }
                });
                documentParser.getDocumentRegions();
            }
        }
        if (!didStreamParse) {
            // Use a StructuredDocument
            IEncodedDocument document = handler.getDocumentLoader().createNewStructuredDocument(file);
            monitor.beginTask("", document.getLength());
            if (document instanceof IStructuredDocument) {
                IStructuredDocumentRegion documentRegion = ((IStructuredDocument) document).getFirstStructuredDocumentRegion();
                while (documentRegion != null) {
                    ITextRegionList regions = documentRegion.getRegions();
                    for (int j = 0; j < regions.size(); j++) {
                        ITextRegion comment = regions.get(j);
                        findTasks(document, taskTags, documentRegion, comment);
                    }
                    monitor.worked(documentRegion.getLength());
                    documentRegion = documentRegion.getNext();
                }
            }
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    } catch (CharacterCodingException e) {
        // $NON-NLS-1$
        Logger.log(Logger.INFO, "StructuredFileTaskScanner encountered CharacterCodingException reading " + file.getFullPath());
    } catch (Exception e) {
        // $NON-NLS-1$
        Logger.logException("Exception with " + file.getFullPath().toString(), e);
    }
    monitor.done();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) StructuredDocumentRegionHandler(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) CharacterCodingException(java.nio.charset.CharacterCodingException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IModelHandler(org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler) CharacterCodingException(java.nio.charset.CharacterCodingException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) CoreException(org.eclipse.core.runtime.CoreException) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IEncodedDocument(org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with StructuredDocumentRegionParser

use of org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser in project webtools.sourceediting by eclipse.

the class DocumentRegionProcessor method setDocument.

public void setDocument(IDocument doc) {
    if (getDocument() instanceof IStructuredDocument) {
        RegionParser parser = ((IStructuredDocument) getDocument()).getParser();
        if (parser instanceof StructuredDocumentRegionParser) {
            ((StructuredDocumentRegionParser) parser).removeStructuredDocumentRegionHandler(fResetHandler);
        }
    }
    super.setDocument(doc);
    IReconcilingStrategy validatorStrategy = getValidatorStrategy();
    if (validatorStrategy != null) {
        validatorStrategy.setDocument(doc);
    }
    if (fSemanticHighlightingStrategy != null) {
        fSemanticHighlightingStrategy.setDocument(doc);
    }
    fSpellcheckStrategy = null;
    if (fFoldingStrategy != null) {
        fFoldingStrategy.uninstall();
    }
    fFoldingStrategy = null;
    if (getDocument() instanceof IStructuredDocument) {
        RegionParser parser = ((IStructuredDocument) doc).getParser();
        if (parser instanceof StructuredDocumentRegionParser) {
            ((StructuredDocumentRegionParser) parser).addStructuredDocumentRegionHandler(fResetHandler);
        }
    }
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) StructuredDocumentRegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)

Aggregations

RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)4 StructuredDocumentRegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)4 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)2 StructuredDocumentRegionHandler (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler)2 IOException (java.io.IOException)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)1 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)1 IModelHandler (org.eclipse.wst.sse.core.internal.ltk.modelhandler.IModelHandler)1 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)1 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)1 StructuredDocumentRegionHandlerExtension (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandlerExtension)1 StructuredDocumentRegionParserExtension (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParserExtension)1