Search in sources :

Example 1 with IStructuredDocumentRegion

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

the class AlloyStructuredTextPartitionerForJSP method _isAUIScriptRegion.

private boolean _isAUIScriptRegion(IStructuredDocumentRegion sdRegion) {
    /*
		 *  TODO can this handle content with other regions like
		 *  <aui:script> function foo() {}; <portletTag/> function bar(){}</aui:script>
		 */
    IStructuredDocumentRegion previousRegion = sdRegion.getPrevious();
    if (previousRegion == null) {
        return false;
    }
    String info = previousRegion.toString();
    if ((sdRegion != null) && (sdRegion.getPrevious() != null) && info.contains("aui:script")) {
        return true;
    }
    return false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 2 with IStructuredDocumentRegion

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

the class AlloyStructuredTextPartitionerForJSP method getPartitionType.

@Override
public String getPartitionType(ITextRegion region, int offset) {
    String retval = super.getPartitionType(region, offset);
    IStructuredDocumentRegion sdRegion = this.fStructuredDocument.getRegionAtCharacterOffset(offset);
    if (_isAUIScriptRegion(sdRegion)) {
        retval = IHTMLPartitions.SCRIPT;
    } else if (_isAUIEventHandlerAttrValue(sdRegion, sdRegion.getRegionAtCharacterOffset(offset))) {
        retval = IHTMLPartitions.SCRIPT_EVENTHANDLER;
    }
    return retval;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 3 with IStructuredDocumentRegion

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

the class StyledTextColorPicker method getNamedStyleAtOffset.

protected String getNamedStyleAtOffset(int offset) {
    // ensure the offset is clean
    if (offset >= fInput.length())
        return getNamedStyleAtOffset(fInput.length() - 1);
    else if (offset < 0)
        return getNamedStyleAtOffset(0);
    // find the ITextRegion at this offset
    if (fNodes == null)
        return null;
    IStructuredDocumentRegion aNode = fNodes;
    while (aNode != null && !aNode.containsOffset(offset)) aNode = aNode.getNext();
    if (aNode != null) {
        // find the ITextRegion's Context at this offset
        ITextRegion interest = aNode.getRegionAtCharacterOffset(offset);
        if (interest == null)
            return null;
        if (offset > aNode.getTextEndOffset(interest))
            return null;
        String regionContext = interest.getType();
        if (regionContext == null)
            return null;
        // find the named style (internal/selectable name) for that
        // context
        String namedStyle = (String) getContextStyleMap().get(regionContext);
        if (namedStyle != null) {
            return namedStyle;
        }
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 4 with IStructuredDocumentRegion

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

the class StyledTextColorPicker method applyStyles.

protected void applyStyles() {
    if (fText == null || fText.isDisposed() || fInput == null || fInput.length() == 0)
        return;
    // List regions = fParser.getRegions();
    IStructuredDocumentRegion node = fNodes;
    while (node != null) {
        ITextRegionList regions = node.getRegions();
        for (int i = 0; i < regions.size(); i++) {
            ITextRegion currentRegion = regions.get(i);
            // lookup the local coloring type and apply it
            String namedStyle = (String) getContextStyleMap().get(currentRegion.getType());
            if (namedStyle == null)
                continue;
            TextAttribute attribute = getAttribute(namedStyle);
            if (attribute == null)
                continue;
            StyleRange style = new StyleRange(node.getStartOffset(currentRegion), currentRegion.getLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
            fText.setStyleRange(style);
        }
        node = node.getNext();
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 5 with IStructuredDocumentRegion

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

the class AbstractJSONCompletionProposalComputer method computeCompletionProposals.

@Override
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    int documentPosition = context.getInvocationOffset();
    setErrorMessage(null);
    fTextViewer = textViewer;
    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition <= 0 ? 0 : documentPosition - 1);
    IJSONNode node = (IJSONNode) treeNode;
    while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
        node = node.getParentNode();
    }
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
    // Fix completion region in case of JSON_OBJECT_CLOSE
    if (completionRegion != null && completionRegion.getType() == JSONRegionContexts.JSON_OBJECT_CLOSE && documentPosition > 0) {
        completionRegion = getCompletionRegion(documentPosition, node);
    }
    String matchString = EMPTY;
    if (completionRegion != null) {
        if (isPairValue(context, node)) {
            try {
                String nodeText = getNodeText(node);
                int colonIndex = nodeText.indexOf(COLON);
                int offset = documentPosition - node.getStartOffset();
                if (colonIndex >= 0 && offset >= 0) {
                    String str = nodeText.substring(colonIndex + 1, offset);
                    // $NON-NLS-1$
                    str = str.replaceAll(",", BLANK);
                    matchString = str;
                }
            } catch (BadLocationException e) {
            // ignore
            }
        } else {
            matchString = getMatchString(sdRegion, completionRegion, documentPosition);
        }
    }
    // compute normal proposals
    contentAssistRequest = computeCompletionProposals(matchString, completionRegion, (IJSONNode) treeNode, node != null ? node.getParentNode() : null, context);
    if (contentAssistRequest == null) {
        contentAssistRequest = new ContentAssistRequest((IJSONNode) treeNode, node != null ? node.getParentNode() : null, sdRegion, completionRegion, documentPosition, 0, EMPTY);
        setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
    }
    /*
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892 Only set this
		 * error message if nothing else was already set
		 */
    if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
        setErrorMessage(JSONUIMessages.Content_Assist_not_availab_UI_);
    }
    ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
    return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) IJSONNode(org.eclipse.wst.json.core.document.IJSONNode) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextViewer(org.eclipse.jface.text.ITextViewer)

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13