Search in sources :

Example 61 with ITextRegion

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

the class XMLJSPRegionHelper method getRegionName.

protected String getRegionName(IStructuredDocumentRegion sdRegion) {
    // $NON-NLS-1$
    String nameStr = "";
    ITextRegionList regions = sdRegion.getRegions();
    for (int i = 0; i < regions.size(); i++) {
        ITextRegion r = regions.get(i);
        if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
            nameStr = fTextToParse.substring(sdRegion.getStartOffset(r), sdRegion.getTextEndOffset(r));
            break;
        }
    }
    return nameStr.trim();
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 62 with ITextRegion

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

the class CSSSyntaxColoringPage method getNamedStyleAtOffset.

private String getNamedStyleAtOffset(int offset) {
    // ensure the offset is clean
    if (offset >= fDocument.getLength())
        return getNamedStyleAtOffset(fDocument.getLength() - 1);
    else if (offset < 0)
        return getNamedStyleAtOffset(0);
    IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
    while (documentRegion != null && !documentRegion.containsOffset(offset)) {
        documentRegion = documentRegion.getNext();
    }
    if (documentRegion != null) {
        // find the ITextRegion's Context at this offset
        ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset);
        if (interest == null)
            return null;
        if (offset > documentRegion.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) fContextToStyleMap.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 63 with ITextRegion

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

the class StructuredAutoEditStrategyCSS method getIndentFor.

/**
 */
protected String getIndentFor(CompoundRegion region, boolean indentForNextRegion) {
    if (region == null)
        return null;
    IStructuredDocumentRegion flatNode = region.getDocumentRegion();
    if (flatNode == null)
        return null;
    try {
        if (region.getType() == CSSRegionContexts.CSS_LBRACE || region.getType() == CSSRegionContexts.CSS_DELIMITER || region.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
            // get meanful flat node
            RegionIterator it = new RegionIterator(flatNode, region.getTextRegion());
            it.prev();
            while (it.hasPrev()) {
                ITextRegion r = it.prev();
                region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
                if (region.getType() != CSSRegionContexts.CSS_S)
                    break;
            }
            flatNode = region.getDocumentRegion();
            // get indent string
            int position = flatNode.getStart();
            int line = structuredDocument.getLineOfOffset(position);
            int start = structuredDocument.getLineOffset(line);
            int end = findEndOfWhiteSpace(structuredDocument, start, position);
            return structuredDocument.get(start, end - start);
        } else if (region.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_START || // region.getType() == CSSRegionContexts.CSS_PARENTHESIS_OPEN ||
        region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION || region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
            int position = flatNode.getStart() + region.getStart();
            int line = structuredDocument.getLineOfOffset(position);
            int start = structuredDocument.getLineOffset(line);
            int end = findEndOfWhiteSpace(structuredDocument, start, position);
            StringBuffer buf = new StringBuffer(structuredDocument.get(start, end - start));
            position += region.getText().length();
            if (indentForNextRegion) {
                int tokenStart = findEndOfWhiteSpace(structuredDocument, position, structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1);
                if (tokenStart < structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1) {
                    position = tokenStart;
                }
            }
            while (position - end > 0) {
                // $NON-NLS-1$
                buf.append(" ");
                end++;
            }
            return buf.toString();
        } else
            // $NON-NLS-1$
            return "";
    } catch (BadLocationException excp) {
        Logger.logException(excp);
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 64 with ITextRegion

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

the class CSSProposalGenerator method checkLeadingColon.

/**
 */
protected boolean checkLeadingColon() {
    boolean hasLeadingColon = false;
    ITextRegion targetRegion = fContext.getTargetRegion();
    if (targetRegion == null && 0 < fContext.getCursorPos()) {
        targetRegion = fContext.getRegionByOffset(fContext.getCursorPos() - 1);
        if (targetRegion != null && targetRegion.getType() == CSSRegionContexts.CSS_SELECTOR_PSEUDO) {
            hasLeadingColon = true;
        }
    } else if (targetRegion != null) {
        // The target region should be the CSS_SELECTOR_PSEUDO now
        if (targetRegion.getType() == CSSRegionContexts.CSS_SELECTOR_PSEUDO) {
            hasLeadingColon = true;
        }
    }
    return hasLeadingColon;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 65 with ITextRegion

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

the class CSSProposalGeneratorForDeclarationValue method checkSemiColon.

/**
 */
private void checkSemiColon() {
    fAppendSemiColon = false;
    ITextRegion targetRegion = fContext.getTargetRegion();
    if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        // find trailing ":" or ";"
        // if ":" before ";" is found, add ";"
        RegionIterator iterator = fContext.getRegionIterator();
        IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion();
        while (iterator.hasNext()) {
            ITextRegion region = iterator.next();
            if (iterator.getStructuredDocumentRegion() != container) {
                break;
            }
            if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
                fAppendSemiColon = true;
                break;
            }
        }
        if (!fAppendSemiColon) {
            // second chance:
            // leading IStructuredDocumentRegion is not ";"
            IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container);
            if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
                fAppendSemiColon = true;
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator)

Aggregations

ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)447 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)179 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)174 Iterator (java.util.Iterator)75 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)58 ArrayList (java.util.ArrayList)40 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)39 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)35 List (java.util.List)33 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)31 BadLocationException (org.eclipse.jface.text.BadLocationException)30 RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)19 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)16 Node (org.w3c.dom.Node)16 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)15 IOException (java.io.IOException)13 IRegion (org.eclipse.jface.text.IRegion)13 StyleRange (org.eclipse.swt.custom.StyleRange)13