Search in sources :

Example 56 with StructuredDocumentEvent

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

the class StructuredDocumentReParser method minimumEvent.

/**
 * The minimization algorithm simply checks the old nodes to see if any of
 * them "survived" the rescan and are unchanged. If so, the instance of
 * the old node is used instead of the new node. Before the requested
 * change, need to check type, offsets, and text to determine if the same.
 * After the requested change, need to check type and text, but adjust the
 * offsets to what ever the change was.
 */
protected StructuredDocumentEvent minimumEvent(CoreNodeList oldNodes, CoreNodeList newNodes) {
    StructuredDocumentEvent event = null;
    CoreNodeList minimalOldNodes = null;
    CoreNodeList minimalNewNodes = null;
    // To minimize nodes, we'll collect all those
    // that are not equal into old and new lists
    // Note: we assume that old and new nodes
    // are basically contiguous -- and we force it to be so,
    // by starting at the beginning to
    // find first difference, and then starting at the end to find
    // last difference. Everything in between we assume is different.
    // 
    // 
    // 
    // startOfDifferences is the index into the core node list where the
    // first difference
    // occurs. But it may point into the old or the new list.
    int startOfDifferences = _computeStartOfDifferences(oldNodes, newNodes);
    int endOfDifferencesOld = -1;
    int endOfDifferencesNew = -1;
    // then some portion of the lists are identical
    if ((startOfDifferences >= oldNodes.getLength()) || (startOfDifferences >= newNodes.getLength())) {
        if (oldNodes.getLength() < newNodes.getLength()) {
            // 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 not in common with the old ones
            // startOfDifferences should equal oldNodes.getLength(),
            // calculated above on _computeStartOfDifferences
            minimalOldNodes = EMPTY_LIST;
            endOfDifferencesNew = newNodes.getLength() - 1;
            minimalNewNodes = _formMinimumList(newNodes, startOfDifferences, endOfDifferencesNew);
        } else {
            if (oldNodes.getLength() > newNodes.getLength()) {
                // delete old
                // 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 should equal newNodes.getLength(),
                // calculated above on _computeStartOfDifferences
                endOfDifferencesOld = oldNodes.getLength() - 1;
                minimalOldNodes = _formMinimumList(oldNodes, startOfDifferences, endOfDifferencesOld);
                minimalNewNodes = EMPTY_LIST;
            } else
                // unlikely event
                event = new NoChangeEvent(fStructuredDocument, fRequester, fChanges, fStart, fLengthToReplace);
        }
    } else {
        // 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 = oldNodes.getLength() - 1;
        int indexNew = newNodes.getLength() - 1;
        // so that the subsequent oldNodes.item(indexOld) is always valid.
        while ((indexOld >= startOfDifferences) && (_greaterThanEffectedRegion(oldNodes.item(indexOld)))) {
            if (!(oldNodes.item(indexOld).sameAs(newNodes.item(indexNew), fLengthDifference))) {
                break;
            } else {
                // if they are equal, then we will be keeping the old one,
                // so
                // we need to be sure its parentDocument is set back to
                // the
                // right instance
                oldNodes.item(indexOld).setParentDocument(fStructuredDocument);
            }
            indexOld--;
            indexNew--;
        }
        endOfDifferencesOld = indexOld;
        endOfDifferencesNew = indexNew;
        minimalOldNodes = _formMinimumList(oldNodes, startOfDifferences, endOfDifferencesOld);
        minimalNewNodes = _formMinimumList(newNodes, startOfDifferences, endOfDifferencesNew);
    }
    // ///////////////////////////////////////
    // 
    IStructuredDocumentRegion firstDownStreamNode = null;
    event = regionCheck(minimalOldNodes, minimalNewNodes);
    if (event != null) {
        firstDownStreamNode = minimalOldNodes.item(0).getNext();
        if (firstDownStreamNode != null && fLengthDifference != 0) {
            // if
            // firstDownStream
            // is
            // null,
            // then
            // we're
            // at
            // the
            // end
            // of
            // the
            // document
            StructuredDocumentRegionIterator.adjustStart(firstDownStreamNode, fLengthDifference);
        }
    // 
    } else {
        event = nodesReplacedCheck(minimalOldNodes, minimalNewNodes);
        // remembered as a tiny optimization.
        if (minimalOldNodes.getLength() == 0 && minimalNewNodes.getLength() > 0) {
            // if no old nodes are being deleted, then use the
            // the newNodes offset (minus one) to find the point to
            // update downstream nodes, and after updating downstream
            // nodes postions, insert the new ones.
            int insertOffset = minimalNewNodes.item(0).getStartOffset();
            IStructuredDocumentRegion lastOldUnchangedNode = null;
            if (insertOffset > 0) {
                lastOldUnchangedNode = fStructuredDocument.getRegionAtCharacterOffset(insertOffset - 1);
                firstDownStreamNode = lastOldUnchangedNode.getNext();
            } else {
                // we're inserting at very beginning
                firstDownStreamNode = fStructuredDocument.getFirstStructuredDocumentRegion();
                // SIDE EFFECT: change the firstNode pointer if we're
                // inserting at beginning
                fStructuredDocument.setFirstDocumentRegion(minimalNewNodes.item(0));
            }
            StructuredDocumentRegionIterator.adjustStart(firstDownStreamNode, fLengthDifference);
            insertNodes(lastOldUnchangedNode, firstDownStreamNode, minimalNewNodes);
            // this (nodes replaced) is the only case where we need to
            // update the cached Node
            reSetCachedNode(minimalOldNodes, minimalNewNodes);
        } else {
            firstDownStreamNode = switchNodeLists(minimalOldNodes, minimalNewNodes);
            // --- adjustment moved to calling method.
            if (firstDownStreamNode != null) {
                // && event != null
                StructuredDocumentRegionIterator.adjustStart(firstDownStreamNode, fLengthDifference);
            }
            // 
            // this (nodes replaced) is the only case where we need to
            // update the cached Node
            reSetCachedNode(minimalOldNodes, minimalNewNodes);
        }
    }
    return event;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)

Example 57 with StructuredDocumentEvent

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

the class StructuredDocumentReParser method _checkBlockNodeList.

public StructuredDocumentEvent _checkBlockNodeList(List blockTagList) {
    StructuredDocumentEvent result = null;
    if (blockTagList != null) {
        for (int i = 0; i < blockTagList.size(); i++) {
            org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker blockTag = (org.eclipse.wst.sse.core.internal.ltk.parser.BlockMarker) blockTagList.get(i);
            String tagName = blockTag.getTagName();
            // $NON-NLS-1$
            final String tagStart = "<" + tagName;
            // $NON-NLS-1$
            result = checkForCriticalName(tagStart);
            if (result != null)
                break;
            // $NON-NLS-1$
            result = checkForCriticalName("</" + tagName);
            if (result != null)
                break;
            result = checkForSelfClosing(tagStart);
            if (result != null)
                break;
            result = checkForTransitionToOpen(tagStart);
            if (result != null)
                break;
        }
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)

Example 58 with StructuredDocumentEvent

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

the class StructuredDocumentReParser method checkHeuristics.

private StructuredDocumentEvent checkHeuristics() {
    StructuredDocumentEvent result = null;
    result = checkForNoChange();
    if (result == null) {
        result = checkForCrossStructuredDocumentRegionBoundryCases();
        if (result == null) {
            result = quickCheck();
        }
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)

Example 59 with StructuredDocumentEvent

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

the class StructuredDocumentReParser method checkForComments.

/**
 * If a comment start or end tag is being added or deleted, we'll rescan
 * the whole document. The reason is that content that is revealed or
 * commented out can effect the interpretation of the rest of the
 * document. Note: for now this is very XML specific, can refactor/improve
 * later.
 */
protected StructuredDocumentEvent checkForComments() {
    StructuredDocumentEvent result = null;
    // $NON-NLS-1$
    result = checkForCriticalKey("<!--");
    if (result == null)
        // $NON-NLS-1$
        result = checkForCriticalKey("-->");
    // we'll also check for these degenerate cases
    if (result == null)
        // $NON-NLS-1$
        result = checkForCriticalKey("<!--->");
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)

Aggregations

StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)59 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)23 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)22 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)20 Document (org.w3c.dom.Document)20 Node (org.w3c.dom.Node)20 NullInputStream (org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)18 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)18 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)18 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)8 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)6 IExecutionDelegate (org.eclipse.wst.sse.core.internal.IExecutionDelegate)3 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)3 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)2 List (java.util.List)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IRegion (org.eclipse.jface.text.IRegion)1