Search in sources :

Example 1 with StructuredDocumentEvent

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

the class CSSModelUpdater method removeText.

/**
 */
private StructuredDocumentEvent removeText(int start, int length) {
    StructuredDocumentEvent result = null;
    IStructuredDocument structuredDocument = fModel.getStructuredDocument();
    if (structuredDocument != null) {
        // $NON-NLS-1$
        result = structuredDocument.replaceText(fModel, start, length, new String(""));
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 2 with StructuredDocumentEvent

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

the class CSSModelUpdater method insertText.

/**
 */
private StructuredDocumentEvent insertText(int start, int oldLength, String text) {
    StructuredDocumentEvent result = null;
    BasicStructuredDocument structuredDocument = (BasicStructuredDocument) fModel.getStructuredDocument();
    if (structuredDocument != null) {
        if (text != null && 0 < oldLength && start + oldLength <= structuredDocument.getLength()) {
            // minimize text change
            String delText = structuredDocument.get(start, oldLength);
            int newLength = text.length();
            int shorterLen = Math.min(oldLength, newLength);
            int stMatchLen;
            for (stMatchLen = 0; stMatchLen < shorterLen && text.charAt(stMatchLen) == delText.charAt(stMatchLen); stMatchLen++) {
            // 
            }
            if (0 < stMatchLen && stMatchLen < shorterLen && text.charAt(stMatchLen - 1) == 0x000d && (text.charAt(stMatchLen) == 0x000a || delText.charAt(stMatchLen) == 0x000a)) {
                // must not divide 0d->0a sequence
                stMatchLen--;
            }
            if (stMatchLen == shorterLen) {
                if (oldLength < newLength) {
                    // just insert
                    oldLength = 0;
                    start += stMatchLen;
                    text = text.substring(stMatchLen);
                } else if (newLength < oldLength) {
                    // just remove
                    oldLength -= stMatchLen;
                    start += stMatchLen;
                    text = null;
                } else {
                    // nothing to do
                    oldLength = 0;
                    text = null;
                }
            } else {
                int edMatchLen;
                for (edMatchLen = 0; stMatchLen + edMatchLen < shorterLen && text.charAt(newLength - edMatchLen - 1) == delText.charAt(oldLength - edMatchLen - 1); edMatchLen++) {
                // 
                }
                if (0 < edMatchLen && text.charAt(newLength - edMatchLen) == 0x000a && ((edMatchLen < newLength && text.charAt(newLength - edMatchLen - 1) == 0x000d) || (edMatchLen < oldLength && delText.charAt(oldLength - edMatchLen - 1) == 0x000d))) {
                    // must not divide 0d->0a sequence
                    edMatchLen--;
                }
                oldLength -= stMatchLen + edMatchLen;
                start += stMatchLen;
                if (stMatchLen + edMatchLen < newLength) {
                    text = text.substring(stMatchLen, newLength - edMatchLen);
                } else {
                    text = null;
                }
            }
        }
        if (0 < oldLength || text != null) {
            // String delText = structuredDocument.get(start, oldLength);
            result = structuredDocument.replaceText(fModel, start, oldLength, text);
        }
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) BasicStructuredDocument(org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument)

Example 3 with StructuredDocumentEvent

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

the class CSSStructuredDocumentReParser method checkForCrossStructuredDocumentRegionSyntax.

/**
 */
// public StructuredDocumentEvent
// checkForCrossStructuredDocumentRegionBoundryCases2() {
// StructuredDocumentEvent result = specialPositionUpdate(fStart, fStart +
// fLengthToReplace - 1);
// if (result == null) {
// result = checkInsideBrace();
// }
// return result;
// }
protected StructuredDocumentEvent checkForCrossStructuredDocumentRegionSyntax() {
    int checkStart = fStart;
    int checkEnd = fStart + fLengthToReplace - 1;
    IStructuredDocumentRegion endRegion = fStructuredDocument.getRegionAtCharacterOffset(checkEnd);
    if (endRegion != null) {
        checkEnd = endRegion.getEndOffset();
    }
    ReparseRange range = new ReparseRange(checkStart, checkEnd);
    range.expand(getUpdateRangeForDelimiter(range.getStart(), range.getEnd()));
    range.expand(getUpdateRangeForUnknownRegion(range.getStart(), range.getEnd()));
    range.expand(getUpdateRangeForQuotes(range.getStart(), range.getEnd()));
    range.expand(getUpdateRangeForComments(range.getStart(), range.getEnd()));
    range.expand(getUpdateRangeForBraces(range.getStart(), range.getEnd()));
    StructuredDocumentEvent result;
    result = checkInsideBrace(range.getStart(), range.getEnd());
    if (result == null) {
        result = reparse(range.getStart(), range.getEnd());
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Example 4 with StructuredDocumentEvent

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

the class BasicStructuredDocument method updateModel.

private StructuredDocumentEvent updateModel(Object requester, int start, int lengthToReplace, String changes) {
    StructuredDocumentEvent result = null;
    IStructuredTextReParser reParser = getReParser();
    // initialize the IStructuredTextReParser with the standard data
    // that's
    // always needed
    reParser.initialize(requester, start, lengthToReplace, changes);
    result = reParser.reparse();
    // if result is null at this point, then there must be an error, since
    // even if there
    // was no change (either disallow due to readonly, or a person pasted
    // the same thing
    // they had selected) then a "NoChange" event should have been fired.
    // $NON-NLS-1$
    Assert.isNotNull(result, "no structuredDocument event was created in IStructuredDocument::updateStructuredDocument");
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) IStructuredTextReParser(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredTextReParser)

Example 5 with StructuredDocumentEvent

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

the class BasicStructuredDocument method internalReplaceText.

/**
 * @param requester
 * @param start
 * @param replacementLength
 * @param changes
 * @param modificationStamp
 * @param ignoreReadOnlySettings
 * @return
 */
private StructuredDocumentEvent internalReplaceText(Object requester, int start, int replacementLength, String changes, long modificationStamp, boolean ignoreReadOnlySettings) {
    StructuredDocumentEvent result = null;
    stopPostNotificationProcessing();
    if (changes == null)
        // $NON-NLS-1$
        changes = "";
    // 
    if (Debug.debugStructuredDocument)
        // $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
        System.out.println(getClass().getName() + "::replaceText(" + start + "," + replacementLength + "," + changes + ")");
    if (Debug.perfTestStructuredDocumentOnly || Debug.perfTest || Debug.perfTestRawStructuredDocumentOnly) {
        startStreamTime = System.currentTimeMillis();
    }
    try {
        // Note: event must be computed before 'fire' method called
        fDocumentEvent = new DocumentEvent(this, start, replacementLength, changes);
        fireDocumentAboutToChanged();
        try {
            acquireLock();
            if (!ignoreReadOnlySettings && (containsReadOnly(start, replacementLength))) {
                NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
                noChangeEvent.reason = NoChangeEvent.READ_ONLY_STATE_CHANGE;
                result = noChangeEvent;
            } else {
                result = updateModel(requester, start, replacementLength, changes);
            }
        } finally {
            releaseLock();
        }
        if (Debug.perfTestRawStructuredDocumentOnly || Debug.perfTest) {
            long stopStreamTime = System.currentTimeMillis();
            // $NON-NLS-1$
            System.out.println("\n\t\t\t\t Time for IStructuredDocument raw replaceText: " + (stopStreamTime - startStreamTime));
        }
        if (Debug.debugStructuredDocument) {
            // $NON-NLS-1$
            System.out.println("event type returned by replaceTextWithNoDebuggingThread: " + result);
        }
    } finally {
        // increment modification stamp if modifications were made
        if (result != null && !(result instanceof NoChangeEvent)) {
            fModificationStamp = modificationStamp;
            fNextModificationStamp = Math.max(fModificationStamp, fNextModificationStamp);
            fDocumentEvent.fModificationStamp = fModificationStamp;
        }
        if (result == null) {
            // result should not be null, but if an exception was thrown,
            // it will be
            // so send a noChangeEvent and log the problem
            NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
            noChangeEvent.reason = NoChangeEvent.NO_EVENT;
            fireStructuredDocumentEvent(noChangeEvent);
            // $NON-NLS-1$
            Logger.log(Logger.ERROR, "Program Error: invalid structured document event");
        } else {
            if (result instanceof RegionChangedEvent) {
                fireStructuredDocumentEvent((RegionChangedEvent) result);
            } else {
                if (result instanceof RegionsReplacedEvent) {
                    fireStructuredDocumentEvent((RegionsReplacedEvent) result);
                } else {
                    if (result instanceof StructuredDocumentRegionsReplacedEvent) {
                        // probably more efficient to mark old regions as
                        // 'deleted' at the time
                        // that are determined to be deleted, but I'll do
                        // here
                        // in then central spot
                        // for programming ease.
                        updateDeletedFields((StructuredDocumentRegionsReplacedEvent) result);
                        fireStructuredDocumentEvent((StructuredDocumentRegionsReplacedEvent) result);
                    } else {
                        if (result instanceof NoChangeEvent) {
                            fireStructuredDocumentEvent((NoChangeEvent) result);
                        } else {
                            // if here, this means a new event was created
                            // and not handled here
                            // just send a no event until this issue is
                            // resolved.
                            NoChangeEvent noChangeEvent = new NoChangeEvent(this, requester, changes, start, replacementLength);
                            noChangeEvent.reason = NoChangeEvent.NO_EVENT;
                            fireStructuredDocumentEvent(noChangeEvent);
                            // $NON-NLS-1$
                            Logger.log(Logger.INFO, "Program Error: unexpected structured document event: " + result);
                        }
                    }
                }
            }
        }
        if (Debug.perfTest || Debug.perfTestStructuredDocumentOnly) {
            long stopStreamTime = System.currentTimeMillis();
            // $NON-NLS-1$
            System.out.println("\n\t\t\t\t Total Time for IStructuredDocument event signaling/processing in replaceText: " + (stopStreamTime - startStreamTime));
        }
        resumePostNotificationProcessing();
    }
    return result;
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent) RegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent) NoChangeEvent(org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent) StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) StructuredDocumentRegionsReplacedEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)

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