Search in sources :

Example 31 with ITextRegionList

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

the class StructuredDocumentReParser method transferEmbeddedRegions.

/**
 * The purpose of this method is to "reuse" the old container region, when
 * found to be same (so same instance doesn't change). The goal is to
 * "transform" the old region, so its equivelent to the newly parsed one.
 */
private void transferEmbeddedRegions(IStructuredDocumentRegion oldNode, ITextRegionContainer oldRegion, ITextRegionContainer newRegion) {
    // the oldRegion should already have the right parent, since
    // we got here because all's equivelent except the region
    // postions have changed.
    // oldRegion.setParent(newRegion.getParent());
    // but we should check if there's "nested" embedded regions, and if
    // so, we can just move them over. setting their parent as this old
    // region.
    ITextRegionList newRegionsToTransfer = newRegion.getRegions();
    oldRegion.setRegions(newRegionsToTransfer);
    Iterator newRegionsInOldOne = newRegionsToTransfer.iterator();
    while (newRegionsInOldOne.hasNext()) {
        ITextRegion newOne = (ITextRegion) newRegionsInOldOne.next();
        if (isCollectionRegion(newOne)) {
            // ||
            // hasContainerRegions(newOne)) {
            // ((ITextRegionContainer) newOne).setParent(oldRegion);
            oldRegion.setRegions(newRegion.getRegions());
        }
    }
}
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 ITextRegionList

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

the class BasicStructuredDocumentRegion method getType.

/**
 * Provides the type of IStructuredDocumentRegion ... not to be confused
 * with type of XML node! This is subclassed, if something other than type
 * of first region is desired.
 */
public String getType() {
    String result = UNDEFINED;
    ITextRegionList subregions = getRegions();
    if (subregions != null && subregions.size() > 0) {
        ITextRegion firstRegion = subregions.get(0);
        if (firstRegion != null) {
            result = firstRegion.getType();
        }
    }
    return result;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 33 with ITextRegionList

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

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

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

the class JSPValidator method getAttributeValueRegion.

/**
 * @param sdr
 * @param attrName
 * @return the ITextRegion for the attribute value of the given attribute
 *         name, case sensitive, null if no matching attribute is found
 */
protected ITextRegion getAttributeValueRegion(ITextRegionCollection sdr, String attrName) {
    ITextRegion valueRegion = null;
    ITextRegionList subRegions = sdr.getRegions();
    for (int i = 0; i < subRegions.size(); i++) {
        ITextRegion subRegion = subRegions.get(i);
        if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME && sdr.getText(subRegion).equals(attrName)) {
            for (int j = i; j < subRegions.size(); j++) {
                subRegion = subRegions.get(j);
                if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                    valueRegion = subRegion;
                    break;
                }
            }
            break;
        }
    }
    return valueRegion;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) 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