Search in sources :

Example 1 with ITextRegionList

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

the class AlloyJsTranslator method translateInlineJSNode.

public void translateInlineJSNode(IStructuredDocumentRegion container) {
    /* start a function header.. will amend later */
    ITextRegionList t = container.getRegions();
    ITextRegion r;
    Iterator<?> regionIterator = t.iterator();
    while (regionIterator.hasNext() && !isCanceled()) {
        r = (ITextRegion) regionIterator.next();
        if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
            r.getStart();
            r.getTextEnd();
            String tagAttrname = container.getText(r);
            /*
				 * Attribute values aren't case sensative, also make sure next region is attrib
				 * value
				 */
            if (NodeHelper.isInArray(JsDataTypes.HTMLATREVENTS, tagAttrname) || NodeHelper.isInArray(ALLOYATTREVENTS, tagAttrname)) {
                if (regionIterator.hasNext()) {
                    regionIterator.next();
                }
                if (regionIterator.hasNext()) {
                    r = (ITextRegion) regionIterator.next();
                }
                if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                    int valStartOffset = container.getStartOffset(r);
                    String rawText = container.getText(r);
                    if ((rawText == null) || (rawText.length() == 0)) {
                        continue;
                    }
                    /* Strip quotes */
                    switch(rawText.charAt(0)) {
                        case '\'':
                        case '"':
                            rawText = rawText.substring(1);
                            valStartOffset++;
                    }
                    if ((rawText == null) || (rawText.length() == 0)) {
                        continue;
                    }
                    switch(rawText.charAt(rawText.length() - 1)) {
                        case '\'':
                        case '"':
                            rawText = rawText.substring(0, rawText.length() - 1);
                    }
                    new Position(valStartOffset, rawText.length());
                    char[] spaces = Util.getPad(Math.max(0, valStartOffset - scriptOffset - _EVENT_HANDLER_PRE_LENGTH));
                    for (int i = 0; i < spaces.length; i++) {
                        try {
                            char c = fStructuredDocument.getChar(scriptOffset + i);
                            if ((c == '\n') || (c == '\r') || (c == '\t')) {
                                spaces[i] = c;
                            }
                        } catch (BadLocationException ble) {
                            Logger.logException(ble);
                        }
                    }
                    fScriptText.append(spaces);
                    fScriptText.append(_EVENT_HANDLER_PRE);
                    appendAndTrack(rawText, valStartOffset);
                    if (ADD_SEMICOLON_AT_INLINE) {
                        fScriptText.append(";");
                    }
                    if (r.getLength() > rawText.length()) {
                        fScriptText.append(_EVENT_HANDLER_POST);
                        spaces = Util.getPad(Math.max(0, r.getLength() - rawText.length() - _EVENT_HANDLER_POST_LENGTH));
                        fScriptText.append(spaces);
                    }
                    scriptOffset = container.getEndOffset(r);
                }
            }
        }
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) Position(org.eclipse.jface.text.Position) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ITextRegionList

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

the class AbstractLineStyleProvider method prepareTextRegion.

/**
 * @param region
 * @param start
 * @param length
 * @param holdResults
 * @return
 */
private boolean prepareTextRegion(ITextRegionCollection blockedRegion, int partitionStartOffset, int partitionLength, Collection holdResults) {
    boolean handled = false;
    final int partitionEndOffset = partitionStartOffset + partitionLength - 1;
    ITextRegion region = null;
    ITextRegionList regions = blockedRegion.getRegions();
    int nRegions = regions.size();
    StyleRange styleRange = null;
    for (int i = 0; i < nRegions; i++) {
        region = regions.get(i);
        TextAttribute attr = null;
        TextAttribute previousAttr = null;
        if (blockedRegion.getStartOffset(region) > partitionEndOffset)
            break;
        if (blockedRegion.getEndOffset(region) <= partitionStartOffset)
            continue;
        if (region instanceof ITextRegionCollection) {
            handled = prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults);
        } else {
            attr = getAttributeFor(blockedRegion, region);
            if (attr != null) {
                handled = true;
                // regions correctly
                if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) {
                    styleRange.length += region.getLength();
                } else {
                    styleRange = createStyleRange(blockedRegion, region, attr, partitionStartOffset, partitionLength);
                    holdResults.add(styleRange);
                    // technically speaking, we don't need to update
                    // previousAttr
                    // in the other case, because the other case is when
                    // it hasn't changed
                    previousAttr = attr;
                }
            } else {
                previousAttr = null;
            }
        }
    }
    return handled;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 3 with ITextRegionList

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

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

the class CSSModelParser method insertPageRule.

/**
 */
private CSSNodeImpl insertPageRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
    CSSNodeImpl parent = fCreationContext.getTargetNode();
    if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    // get selector regions
    ITextRegionList selectorRegions = new TextRegionListImpl(flatNode.getRegions());
    // must be "@page"
    selectorRegions.remove(0);
    CSSUtil.stripSurroundingSpace(selectorRegions);
    CSSPageRuleImpl rule = fFeeder.getCSSPageRule();
    if (rule == null) {
        return null;
    }
    if (!fUpdateContext.isActive()) {
        String selectorStr = CSSUtil.getRegionText(flatNode, selectorRegions);
        if (0 < selectorStr.length()) {
            rule.setSelectorText(selectorStr);
        }
    }
    // setup flat container
    rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
    CSSAttrImpl attr = rule.getAttributeNode(ICSSPageRule.SELECTOR);
    if (attr != null && selectorRegions != null && !selectorRegions.isEmpty()) {
        attr.setRangeRegion(flatNode, selectorRegions.get(0), selectorRegions.get(selectorRegions.size() - 1));
    }
    // insert to tree
    if (!fUpdateContext.isActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = fCreationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    fCreationContext.setTargetNode(rule);
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)

Example 5 with ITextRegionList

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

the class CSSModelParser method insertImportRule.

/**
 */
private CSSNodeImpl insertImportRule(IStructuredDocumentRegion beginDocRegion, IStructuredDocumentRegion endDocRegion) {
    CSSNodeImpl parent = fCreationContext.getTargetNode();
    if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
        return null;
    }
    ITextRegionList regions = new TextRegionListImpl(beginDocRegion.getRegions());
    // must be "@import"
    regions.remove(0);
    ITextRegion hrefRegion = null;
    while (!regions.isEmpty()) {
        ITextRegion textRegion = regions.remove(0);
        if (textRegion == null) {
            continue;
        }
        String type = textRegion.getType();
        if (type == CSSRegionContexts.CSS_S || type == CSSRegionContexts.CSS_COMMENT) {
            continue;
        }
        if (type == CSSRegionContexts.CSS_URI || type == CSSRegionContexts.CSS_STRING) {
            hrefRegion = textRegion;
            break;
        } else {
            break;
        }
    }
    if (hrefRegion == null) {
        return null;
    }
    CSSImportRuleImpl rule = fFeeder.getCSSImportRule();
    if (rule == null) {
        return null;
    }
    CSSUtil.stripSurroundingSpace(regions);
    MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
    setMediaList(mediaList, beginDocRegion, regions);
    if (!fUpdateContext.isActive()) {
        rule.setAttribute(ICSSImportRule.HREF, beginDocRegion.getText(hrefRegion));
    }
    // setup flat container
    rule.setRangeStructuredDocumentRegion(beginDocRegion, endDocRegion);
    CSSAttrImpl attr = rule.getAttributeNode(ICSSImportRule.HREF);
    if (attr != null) {
        attr.setRangeRegion(beginDocRegion, hrefRegion, hrefRegion);
    }
    // insert to tree
    if (!fUpdateContext.isActive() && parent != null) {
        propagateRangePreInsert(parent, rule);
        CSSNodeImpl next = fCreationContext.getNextNode();
        if (next != null) {
            parent.insertBefore(rule, next);
        } else {
            parent.appendChild(rule);
        }
    }
    return rule;
}
Also used : ICSSRuleContainer(org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)193 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)171 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)74 Iterator (java.util.Iterator)46 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)27 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)24 ArrayList (java.util.ArrayList)21 List (java.util.List)18 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)16 StyleRange (org.eclipse.swt.custom.StyleRange)13 TextAttribute (org.eclipse.jface.text.TextAttribute)12 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)12 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)9 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8 DOMException (org.w3c.dom.DOMException)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)7