Search in sources :

Example 6 with RegionsReplacedEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent in project webtools.sourceediting by eclipse.

the class TestRegionsReplacedEvent method testRegionsReplacedEvent.

public void testRegionsReplacedEvent() {
    RegionsReplacedEvent event = getBasicEvent();
    assertNotNull(event);
}
Also used : RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)

Example 7 with RegionsReplacedEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent in project webtools.sourceediting by eclipse.

the class UnitTests method handleEvent.

protected void handleEvent(StructuredDocumentEvent structuredDocumentEvent) {
    eventResult = false;
    switch(eventCase) {
        case 1:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 2:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 3:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 4:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 5:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 6:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                                if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                                    // ok
                                    eventResult = true;
                                }
                }
                break;
            }
        case 7:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 8:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // if ("<B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(0).getText()))
                            // if ("</B>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().item(1).getText())) {
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 9:
        case 10:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 11:
        case 12:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (2 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (0 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            if ("<TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(0).getText()))
                                if ("</TD>".equals(((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().item(1).getText()))
                                    // ok
                                    eventResult = true;
                }
                break;
            }
        case 13:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size())
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 14:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    if (3 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getOldStructuredDocumentRegions().getLength())
                        if (1 == ((StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent).getNewStructuredDocumentRegions().getLength())
                            // ok
                            eventResult = true;
                }
                break;
            }
        case 15:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    RegionChangedEvent regionChangedEvent = (RegionChangedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegion documentRegion = ((RegionChangedEvent) structuredDocumentEvent).getStructuredDocumentRegion();
                    if ("b ".equals(documentRegion.getFullText(regionChangedEvent.getRegion()))) {
                        // ok
                        eventResult = true;
                    }
                }
                break;
            }
        case 16:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (0 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 17:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (1 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (3 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 18:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getOldRegions().size()) {
                        if (2 == ((RegionsReplacedEvent) structuredDocumentEvent).getNewRegions().size()) {
                            // ok
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 19:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 20:
        case 21:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 22:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 23:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 24:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 25:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 26:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP5
        case 27:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 28:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 29:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 30:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        // JSP6
        case 31:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 32:
            {
                // changed 2002, 9/12 to fit -- this is definitely a change
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    RegionsReplacedEvent regionsReplacedEvent = (RegionsReplacedEvent) structuredDocumentEvent;
                    if (1 == regionsReplacedEvent.getOldRegions().size()) {
                        ITextRegion region = regionsReplacedEvent.getOldRegions().get(0);
                        IStructuredDocumentRegion documentRegion = regionsReplacedEvent.getStructuredDocumentRegion();
                        String text = documentRegion.getText(region);
                        if ("<% aaa %>".equals(text)) {
                            // ok
                            eventResult = true;
                        }
                    }
                } else if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    StructuredDocumentRegionsReplacedEvent nodesReplacedEvent = (StructuredDocumentRegionsReplacedEvent) structuredDocumentEvent;
                    IStructuredDocumentRegionList regions = nodesReplacedEvent.getNewStructuredDocumentRegions();
                    if (1 == regions.getLength()) {
                        IStructuredDocumentRegion region = regions.item(0);
                        String text = region.getText();
                        // System.out.println(text);
                        if ("<c<% aaa ".equals(text)) {
                            eventResult = true;
                        }
                    }
                }
                break;
            }
        case 33:
            {
                // changed 2002, 9/12 to fit
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 34:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 35:
            {
                // if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 36:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 37:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 38:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 39:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case 40:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NODES_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof StructuredDocumentRegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGIONS_REPLACED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionsReplacedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_REGION_CHANGED_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof RegionChangedEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NEW_MODEL_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        case GENERIC_NO_CHANGE_EVENT_CASE:
            {
                if (structuredDocumentEvent instanceof NoChangeEvent) {
                    // ok
                    eventResult = true;
                }
                break;
            }
        default:
            {
                if (structuredDocumentEvent instanceof NewDocumentEvent) {
                    // ok
                    eventResult = true;
                }
            }
    }
}
Also used : NewDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)

Example 8 with RegionsReplacedEvent

use of org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent in project webtools.sourceediting by eclipse.

the class StructuredDocumentReParser method regionCheck.

/**
 * If only one node is involved, sees how many regions are changed. If
 * only one, then its a 'regionChanged' event ... if more than one, its a
 * 'regionsReplaced' event.
 */
protected StructuredDocumentEvent regionCheck(IStructuredDocumentRegion oldNode, IStructuredDocumentRegion newNode) {
    // 
    StructuredDocumentEvent result = null;
    ITextRegionList oldRegions = oldNode.getRegions();
    ITextRegionList newRegions = newNode.getRegions();
    ITextRegion[] oldRegionsArray = oldRegions.toArray();
    ITextRegion[] newRegionsArray = newRegions.toArray();
    // 
    // for the 'regionsReplaced' event, we don't care if
    // the regions changed due to type, or text,
    // we'll just collect all those that are not equal
    // into the old and new region lists.
    // Note: we, of course, assume that old and new regions
    // are basically contiguous -- and we force it to be so,
    // even if not literally so, by starting at beginning to
    // find first difference, and then starting at end to find
    // last difference. Everything in between we assume is different.
    // 
    // going up is easy, we start at zero in each, and continue
    // till regions are not the same.
    int startOfDifferences = _computeStartOfDifferences(oldNode, oldRegions, newNode, newRegions);
    int endOfDifferencesOld = -1;
    int endOfDifferencesNew = -1;
    // then some portion of the lists are identical
    if ((startOfDifferences >= oldRegions.size()) || (startOfDifferences >= newRegions.size())) {
        if (oldRegions.size() < newRegions.size()) {
            // INSERT CASE
            // then there are new regions to add
            // these lengths will cause the vector of old ones to not
            // have any elements, and the vector of new regions to have
            // just the new ones.
            startOfDifferences = oldRegionsArray.length;
            endOfDifferencesOld = oldRegionsArray.length - 1;
            endOfDifferencesNew = newRegionsArray.length - 1;
        } else {
            if (oldRegions.size() > newRegions.size()) {
                // DELETE CASE
                // then there are old regions to delete
                // these lengths will cause the vector of old regions to
                // contain the ones to delete, and the vector of new
                // regions
                // not have any elements
                startOfDifferences = newRegionsArray.length;
                endOfDifferencesOld = oldRegionsArray.length - 1;
                endOfDifferencesNew = newRegionsArray.length - 1;
            } else {
                // else the lists are identical!
                // unlikely event, probably error in current design, since
                // we check for identity at the very beginning of
                // reparsing.
                result = new NoChangeEvent(fStructuredDocument, fRequester, fChanges, fStart, fLengthToReplace);
            }
        }
    } else {
        if ((startOfDifferences > -1) && (endOfDifferencesOld < 0) && (endOfDifferencesNew < 0)) {
            // We found a normal startOfDiffernces, but have not yet found
            // the ends.
            // We'll look for the end of differences by going backwards
            // down the two lists.
            // Here we need a seperate index for each array, since they
            // may
            // be (and
            // probably are) of different lengths.
            int indexOld = oldRegionsArray.length - 1;
            int indexNew = newRegionsArray.length - 1;
            while ((indexOld >= startOfDifferences) && (_greaterThanEffectedRegion(oldNode, oldRegionsArray[indexOld]))) {
                if ((!(oldNode.sameAs(oldRegionsArray[indexOld], newNode, newRegionsArray[indexNew], fLengthDifference)))) {
                    // endOfDifferencesNew = indexTwo;
                    break;
                }
                indexOld--;
                indexNew--;
            }
            endOfDifferencesOld = indexOld;
            endOfDifferencesNew = indexNew;
        }
    }
    // result != null means the impossible case above occurred
    if (result == null) {
        // Now form the two vectors of different regions
        ITextRegionList holdOldRegions = new TextRegionListImpl();
        ITextRegionList holdNewRegions = new TextRegionListImpl();
        if (startOfDifferences > -1 && endOfDifferencesOld > -1) {
            for (int i = startOfDifferences; i <= endOfDifferencesOld; i++) {
                holdOldRegions.add(oldRegionsArray[i]);
            }
        }
        if (startOfDifferences > -1 && endOfDifferencesNew > -1) {
            for (int i = startOfDifferences; i <= endOfDifferencesNew; i++) {
                holdNewRegions.add(newRegionsArray[i]);
            }
        }
        if (holdOldRegions.size() == 0 && holdNewRegions.size() == 0) {
            // then this means the regions were identical, which means
            // someone
            // pasted exactly the same thing they had selected, or !!!
            // someone deleted the end bracket of the tag. !!!?
            result = new NoChangeEvent(fStructuredDocument, fRequester, fChanges, fStart, fLengthToReplace);
        } else {
            // old instance of old node
            if ((holdOldRegions.size() == 1) && (holdNewRegions.size() == 1) && _regionsSameKind((holdNewRegions.get(0)), (holdOldRegions.get(0)))) {
                ITextRegion newOldRegion = swapNewForOldRegion(oldNode, holdOldRegions.get(0), newNode, holdNewRegions.get(0));
                // -- need to update any down stream regions, within this
                // 'oldNode'
                updateDownStreamRegions(oldNode, newOldRegion);
                result = new RegionChangedEvent(fStructuredDocument, fRequester, oldNode, newOldRegion, fChanges, fStart, fLengthToReplace);
            } else {
                replaceRegions(oldNode, holdOldRegions, newNode, holdNewRegions);
                // -- need to update any down stream regions, within this
                // 'oldNode'
                // don't need with the way replaceRegions is implemented.
                // It handles.
                // if(holdNewRegions.size() > 0)
                // updateDownStreamRegions(oldNode, (ITextRegion)
                // holdNewRegions.lastElement());
                result = new RegionsReplacedEvent(fStructuredDocument, fRequester, oldNode, holdOldRegions, holdNewRegions, fChanges, fStart, fLengthToReplace);
            }
        }
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Aggregations

RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)8 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)3 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)3 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)3 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 NewDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent)1 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1