Search in sources :

Example 1 with RegionParser

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

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

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

the class BasicStructuredDocument method resetParser.

void resetParser(int startOffset, int endOffset) {
    RegionParser parser = getParser();
    ITextStore textStore = getStore();
    if (textStore instanceof CharSequence) {
        CharSequenceReader subSetTextStoreReader = new CharSequenceReader((CharSequence) textStore, startOffset, endOffset - startOffset);
        parser.reset(subSetTextStoreReader, startOffset);
    } else {
        String newNodeText = get(startOffset, endOffset - startOffset);
        parser.reset(newNodeText, startOffset);
    }
}
Also used : ITextStore(org.eclipse.jface.text.ITextStore) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)

Example 4 with RegionParser

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

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

the class StructuredTextPartitionerForJSP method isAction.

/**
 * @param sdRegion
 * @param offset
 * @return
 */
private boolean isAction(IStructuredDocumentRegion sdRegion, int offset) {
    if (!sdRegion.getType().equals(DOMRegionContext.XML_TAG_NAME))
        return false;
    /*
		 * shouldn't get a tag name region type unless a tag name region
		 * exists at [1]
		 */
    ITextRegion tagNameRegion = sdRegion.getRegions().get(1);
    String tagName = sdRegion.getText(tagNameRegion);
    RegionParser parser = fStructuredDocument.getParser();
    if (parser instanceof JSPSourceParser) {
        if (tagName.equals(fLastCheckedPrefix))
            return true;
        List fCustomActionPrefixes = ((JSPSourceParser) parser).getNestablePrefixes();
        for (int i = 0; i < fCustomActionPrefixes.size(); i++) if (tagName.startsWith(((TagMarker) fCustomActionPrefixes.get(i)).getTagName())) {
            fLastCheckedPrefix = ((TagMarker) fCustomActionPrefixes.get(i)).getTagName();
            return true;
        }
    }
    return false;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) List(java.util.List) RegionParser(org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser) JSPSourceParser(org.eclipse.jst.jsp.core.internal.parser.JSPSourceParser) TagMarker(org.eclipse.wst.sse.core.internal.ltk.parser.TagMarker)

Aggregations

RegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.RegionParser)13 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 StructuredDocumentRegionParser (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionParser)4 List (java.util.List)3 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)2 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)2 BlockMarker (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker)2 BlockTagParser (org.eclipse.wst.sse.core.internal.ltk.parser.BlockTagParser)2 StructuredDocumentRegionHandler (org.eclipse.wst.sse.core.internal.ltk.parser.StructuredDocumentRegionHandler)2 IEncodedDocument (org.eclipse.wst.sse.core.internal.provisional.document.IEncodedDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 Reader (java.io.Reader)1