Search in sources :

Example 31 with ITextRegion

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

the class SyntaxValidator method getEndTagFullText.

private String getEndTagFullText(ElementInfo info) {
    // $NON-NLS-1$
    String hint = "";
    ITextRegionList regions = info.endTag.getRegions();
    Iterator iter = regions.iterator();
    while (iter.hasNext()) {
        ITextRegion rgn = (ITextRegion) iter.next();
        String type = rgn.getType();
        if (type == null)
            continue;
        if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_TAG_CLOSE)
            continue;
        hint += info.endTag.getFullText(rgn);
    }
    return hint;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator)

Example 32 with ITextRegion

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

the class HTMLTokenizer method getRegions.

/**
 * user method - skeleton.sed
 *
 * Return ALL of the regions scannable within the remaining text
 * Note: for verification use
 */
public final List getRegions() {
    List tokens = new ArrayList();
    ITextRegion region = null;
    try {
        region = getNextToken();
        while (region != null) {
            if (region != null) {
                tokens.add(region);
            }
            region = getNextToken();
        }
    } catch (StackOverflowError e) {
        // $NON-NLS-1$
        Logger.logException(getClass().getName() + ": input could not be tokenized correctly at position " + getOffset(), e);
        throw e;
    } catch (Exception e) {
        // Since this is convenience method and NOT the recommended
        // way of getting tokens, many errors are simply hidden
        // $NON-NLS-1$
        Logger.logException("Exception not handled retrieving regions: " + e.getLocalizedMessage(), e);
    }
    return tokens;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 33 with ITextRegion

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

the class FMUtil method getSegment.

/**
 */
public static final Segment getSegment(IDOMNode target, int segType) {
    if (target == null)
        return new Segment(0, 0);
    Segment seg = null;
    IStructuredDocumentRegion startTag = null;
    IStructuredDocumentRegion endTag = null;
    switch(segType) {
        case SEG_WHOLE_TAG:
            startTag = target.getFirstStructuredDocumentRegion();
            if (startTag != null) {
                endTag = target.getLastStructuredDocumentRegion();
                seg = new Segment(startTag, endTag);
            } else {
                int startOffset = target.getStartOffset();
                int endOffset = target.getEndOffset();
                seg = new Segment(startOffset, endOffset - startOffset);
            }
            break;
        case SEG_START_TAG:
            startTag = target.getStartStructuredDocumentRegion();
            if (startTag != null) {
                seg = new Segment(startTag);
            } else {
                seg = new Segment(target.getStartOffset(), 1);
            }
            break;
        case SEG_END_TAG:
            endTag = target.getEndStructuredDocumentRegion();
            if (endTag != null) {
                seg = new Segment(endTag);
            } else {
                seg = new Segment(target.getEndOffset(), 1);
            }
            break;
        case SEG_START_TAG_NAME:
            startTag = target.getStartStructuredDocumentRegion();
            if (startTag != null) {
                ITextRegion nameRegion = getNameRegion(startTag);
                if (nameRegion != null) {
                    seg = new Segment(startTag.getStartOffset(nameRegion), nameRegion.getTextLength());
                }
            }
            if (seg == null) {
                seg = getSegment(target, SEG_START_TAG);
            }
            break;
        case SEG_END_TAG_NAME:
            endTag = target.getEndStructuredDocumentRegion();
            if (endTag != null) {
                ITextRegion nameRegion = getNameRegion(endTag);
                if (nameRegion != null) {
                    seg = new Segment(endTag.getStartOffset(nameRegion), nameRegion.getTextLength());
                }
            }
            if (seg == null) {
                seg = getSegment(target, SEG_END_TAG);
            }
            break;
        case SEG_NONE:
        default:
            return new Segment(0, 0);
    }
    return seg;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 34 with ITextRegion

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

the class RegionIterator method prev.

/**
 */
public ITextRegion prev() {
    if (documentRegion == null)
        return null;
    if (current < 0 || documentRegion.getRegions() == null || documentRegion.getRegions().size() <= current)
        return null;
    ITextRegion region = documentRegion.getRegions().get(current);
    curDocumentRegion = documentRegion;
    if (current == 0) {
        documentRegion = documentRegion.getPrevious();
        if (documentRegion != null)
            current = documentRegion.getRegions().size();
        else
            current = 0;
    }
    current--;
    return region;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 35 with ITextRegion

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

the class CSSUtil method stripSurroundingSpace.

/**
 */
public static void stripSurroundingSpace(ITextRegionList regions) {
    if (regions == null) {
        return;
    }
    while (!regions.isEmpty()) {
        ITextRegion region = regions.get(0);
        String type = region.getType();
        if (type == CSSRegionContexts.CSS_S || type == CSSRegionContexts.CSS_COMMENT) {
            regions.remove(0);
        } else {
            break;
        }
    }
    while (!regions.isEmpty()) {
        ITextRegion region = regions.get(regions.size() - 1);
        String type = region.getType();
        if (type == CSSRegionContexts.CSS_S || type == CSSRegionContexts.CSS_COMMENT) {
            regions.remove(region);
        } else {
            break;
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

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