Search in sources :

Example 76 with ITextRegion

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

the class BasicStructuredDocumentRegion method updateDownStreamRegions.

private void updateDownStreamRegions(ITextRegion changedRegion, int lengthDifference) {
    int listLength = _getRegions().size();
    int startIndex = 0;
    // first, loop through to find index of where to start
    for (int i = 0; i < listLength; i++) {
        ITextRegion region = _getRegions().get(i);
        if (region == changedRegion) {
            startIndex = i;
            break;
        }
    }
    // now, beginning one past the one that was changed, loop
    // through to end of list, adjusting the start postions.
    startIndex++;
    for (int j = startIndex; j < listLength; j++) {
        ITextRegion region = _getRegions().get(j);
        region.adjustStart(lengthDifference);
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 77 with ITextRegion

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

the class BasicStructuredDocumentRegion method getRegionAtCharacterOffset.

/**
 * The parameter offset refers to the overall offset in the document.
 */
public ITextRegion getRegionAtCharacterOffset(int offset) {
    if (_getRegions() != null) {
        int thisStartOffset = getStartOffset();
        if (offset < thisStartOffset)
            return null;
        int thisEndOffset = getStartOffset() + getLength();
        if (offset > thisEndOffset)
            return null;
        // transform the requested offset to the "scale" that
        // regions are stored in, which are all relative to the
        // start point.
        // int transformedOffset = offset - getStartOffset();
        // 
        ITextRegionList regions = getRegions();
        int length = regions.size();
        int low = 0;
        int high = length;
        int mid = 0;
        // Binary search for the region
        while (low < high) {
            mid = low + ((high - low) >> 1);
            ITextRegion region = regions.get(mid);
            if (Debug.debugStructuredDocument) {
                // $NON-NLS-1$
                System.out.println("region(s) in IStructuredDocumentRegion::getRegionAtCharacterOffset: " + region);
                // $NON-NLS-1$
                System.out.println("       requested offset: " + offset);
                // System.out.println(" transformedOffset: " +
                // transformedOffset); //$NON-NLS-1$
                // $NON-NLS-1$
                System.out.println("       region start: " + region.getStart());
                // $NON-NLS-1$
                System.out.println("       region end: " + region.getEnd());
                // $NON-NLS-1$
                System.out.println("       region type: " + region.getType());
                // $NON-NLS-1$
                System.out.println("       region class: " + region.getClass());
            }
            // Region is before this one
            if (offset < region.getStart() + thisStartOffset)
                high = mid;
            else if (offset > (region.getEnd() + thisStartOffset - 1))
                low = mid + 1;
            else
                return region;
        }
    }
    return null;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 78 with ITextRegion

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

the class StructuredDocumentRegionUtil method getFirstRegionType.

/**
 * Returns the type of the first region.
 */
static String getFirstRegionType(IStructuredDocumentRegion flatNode) {
    if (flatNode instanceof StructuredDocumentRegionProxy) {
        flatNode = ((StructuredDocumentRegionProxy) flatNode).getStructuredDocumentRegion();
    }
    if (flatNode == null)
        return JSONRegionContexts.UNDEFINED;
    ITextRegionList regions = flatNode.getRegions();
    if (regions == null || regions.size() == 0)
        return JSONRegionContexts.UNDEFINED;
    ITextRegion region = regions.get(0);
    return region.getType();
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 79 with ITextRegion

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

the class JSPIncludeRegionHelper method getRegionName.

// different btwn XML-JSP and JSP tags
protected String getRegionName(IStructuredDocumentRegion sdRegion) {
    ITextRegion nameRegion = null;
    // $NON-NLS-1$
    String nameStr = "";
    int size = sdRegion.getRegions().size();
    if (size > 1) {
        // presumably XML-JSP <jsp:scriptlet> | <jsp:expression> | <jsp:declaration>
        nameRegion = sdRegion.getRegions().get(1);
    } else if (size == 1) {
        // presumably JSP open <% | <%= | <%!
        nameRegion = sdRegion.getRegions().get(0);
    }
    if (nameRegion != null)
        nameStr = fTextToParse.substring(sdRegion.getStartOffset(nameRegion), sdRegion.getTextEndOffset(nameRegion));
    return nameStr.trim();
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 80 with ITextRegion

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

the class JSONModelImpl method regionChanged.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.wst.sse.core.internal.provisional.events.
	 * IStructuredDocumentListener
	 * #regionChanged(org.eclipse.wst.sse.core.internal
	 * .provisional.events.RegionChangedEvent)
	 */
@Override
public void regionChanged(RegionChangedEvent event) {
    if (event == null)
        return;
    IStructuredDocumentRegion flatNode = event.getStructuredDocumentRegion();
    if (flatNode == null)
        return;
    ITextRegion region = event.getRegion();
    if (region == null)
        return;
    JSONModelUpdater updater = getActiveUpdater();
    if (updater != null) {
        // being updated
        try {
            updater.changeRegion(event, flatNode, region);
        } catch (Exception ex) {
            Logger.logException(ex);
            this.refresh = true;
            handleRefresh();
        } finally {
            setActive(null);
        }
        // checkForReinit();
        return;
    }
    JSONModelNotifier notifier = getModelNotifier();
    boolean isChanging = notifier.isChanging();
    if (!isChanging)
        notifier.beginChanging();
    JSONModelParser parser = getModelParser();
    setActive(parser);
    try {
        parser.changeRegion(event, flatNode, region);
    /* workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=486860 */
    // this.refresh = true;
    // handleRefresh();
    } catch (Exception ex) {
        Logger.logException(ex);
        this.refresh = true;
        handleRefresh();
    } finally {
        setActive(null);
        if (!isChanging) {
            notifier.endChanging();
            handleRefresh();
        }
    }
// checkForReinit();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) 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