Search in sources :

Example 1 with IStructuredDocument

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

the class JSPFileWTP method createSearchResult.

@Override
protected SearchResult createSearchResult(String searchContext, int startOffset, int endOffset, int startLine, int endLine, boolean fullMatch) {
    IDOMModel jspModel = null;
    try {
        int jspStartOffset = _translation.getJspOffset(startOffset);
        int jspEndOffset = _translation.getJspOffset(endOffset);
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(_translation.getJspFile());
        IDOMDocument domDocument = jspModel.getDocument();
        IStructuredDocument structuredDocument = domDocument.getStructuredDocument();
        int jspStartLine = structuredDocument.getLineOfOffset(jspStartOffset) + 1;
        int jspEndLine = structuredDocument.getLineOfOffset(jspEndOffset) + 1;
        return super.createSearchResult(searchContext, jspStartOffset, jspEndOffset, jspStartLine, jspEndLine, fullMatch);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return super.createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, fullMatch);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with IStructuredDocument

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

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument 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 4 with IStructuredDocument

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

the class CSSModelParser method getStructuredDocumentRegionList.

/**
 */
private IStructuredDocumentRegionList getStructuredDocumentRegionList(int start, int end) {
    IStructuredDocumentRegionList nodeList = null;
    if (0 <= start && start <= end) {
        ICSSModel model = fDocument.getModel();
        if (model instanceof CSSModelImpl) {
            IStructuredDocument structuredDocument = ((CSSModelImpl) model).getStructuredDocument();
            if (structuredDocument != null) {
                IStructuredDocumentRegion startNode = structuredDocument.getRegionAtCharacterOffset(start);
                IStructuredDocumentRegion endNode = structuredDocument.getRegionAtCharacterOffset(end - 1);
                if (startNode != null && endNode != null) {
                    nodeList = new CoreNodeList(startNode, endNode);
                }
            }
        }
    }
    return nodeList;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CoreNodeList(org.eclipse.wst.sse.core.internal.text.CoreNodeList)

Example 5 with IStructuredDocument

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

the class AttrFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    ICSSAttr attr = (ICSSAttr) node;
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        int start = ((IndexedRegion) node).getStartOffset();
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBetween(node, regions[i - 1], regions[i], source);
                source.append(decoratedRegion(regions[i], 0, stgy));
            }
        } else if (attr.getName().equals(ICSSImportRule.HREF)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        } else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedIdentRegion(regions[i], stgy));
            }
        } else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        } else if (attr.getName() == null || attr.getName().length() == 0) {
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedIdentRegion(regions[i], stgy));
            }
        } else {
            // counter attributes
            for (int i = 0; i < regions.length; i++) {
                if (i != 0)
                    appendSpaceBefore(node, regions[i], source);
                source.append(decoratedPropValueRegion(regions[i], stgy));
            }
        }
    } else {
        // generate source
        Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
        String value = attr.getValue();
        if (value == null)
            // $NON-NLS-1$
            value = "";
        if (attr.getName().equals(ICSSStyleRule.SELECTOR) || attr.getName().equals(ICSSPageRule.SELECTOR)) {
        } else if (attr.getName().equals(ICSSImportRule.HREF)) {
            String uri = org.eclipse.wst.css.core.internal.util.CSSLinkConverter.stripFunc(value);
            // $NON-NLS-2$//$NON-NLS-1$
            String func = preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER ? "URL(" : "url(";
            if (preferences.getBoolean(CSSCorePreferenceNames.FORMAT_QUOTE_IN_URI)) {
                String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
                quote = CSSUtil.detectQuote(uri, quote);
                // $NON-NLS-1$
                value = func + quote + uri + quote + ")";
            } else {
                // $NON-NLS-1$
                value = func + uri + ")";
            }
        } else if (attr.getName().equals(ICSSCharsetRule.ENCODING)) {
            String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
            if (// $NON-NLS-2$//$NON-NLS-1$
            !value.startsWith("\"") && !value.startsWith("\'"))
                value = quote + value;
            if (// $NON-NLS-2$//$NON-NLS-1$
            !value.endsWith("\"") && !value.endsWith("\'"))
                value = value + quote;
        } else if (attr.getName().equals(ICSSStyleDeclItem.IMPORTANT)) {
            if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        } else if (attr.getName() == null || attr.getName().length() == 0) {
            if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        } else {
            if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                value = value.toUpperCase();
            else
                value = value.toLowerCase();
        }
        source.append(value);
    }
}
Also used : ICSSAttr(org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)432 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)96 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)79 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)68 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)44 Node (org.w3c.dom.Node)42 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)41 Document (org.w3c.dom.Document)36 BadLocationException (org.eclipse.jface.text.BadLocationException)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)34 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)34 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)33 Element (org.w3c.dom.Element)30 IDocument (org.eclipse.jface.text.IDocument)29 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)28 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)26 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)23 Test (org.junit.Test)22 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)20 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)20