use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class TestRegionChangedEvent method getBasicEvent.
private RegionChangedEvent getBasicEvent() {
IStructuredDocument document = StructuredDocumentFactory.getNewStructuredDocumentInstance(new NullParser());
document.setText(this, testString);
RegionChangedEvent event = new RegionChangedEvent(document, this, null, null, "", 0, 0);
return event;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class TestRegionChangedEvent method testGetStructuredDocumentRegion.
public void testGetStructuredDocumentRegion() {
RegionChangedEvent event = getBasicEvent();
ITextRegion region = event.getRegion();
assertEquals(null, region);
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class TestRegionChangedEvent method testGetRegion.
public void testGetRegion() {
RegionChangedEvent event = getBasicEvent();
IStructuredDocumentRegion structuredDocumentRegion = event.getStructuredDocumentRegion();
assertEquals(null, structuredDocumentRegion);
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class RegionUpdateRule method updateModel.
// need an adjust text length API before this can be used
public static StructuredDocumentEvent updateModel(ITextRegion region, Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
RegionChangedEvent result = null;
// always follow this pattern.)
if (Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("\t\tContextRegion::updateModel");
// $NON-NLS-1$
System.out.println("\t\t\tregion type is " + region.getType());
}
boolean canHandle = false;
// on one region.
if ((changes == null) || (changes.length() == 0)) {
// involving whitespace.
if ((region.getStart() >= region.getTextEnd()) || (Math.abs(lengthToReplace) >= region.getTextEnd() - region.getStart())) {
canHandle = false;
} else {
canHandle = true;
}
} else {
if ((RegionUpdateRule.canHandleAsWhiteSpace(region, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(region, parent, changes, requestStart, lengthToReplace)) {
canHandle = true;
} else {
canHandle = false;
}
}
if (canHandle) {
// updating the text store and down stream flatnodes.
if (Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("change handled by region");
}
int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
// Note: we adjust both end and text end, because for any change
// that is in only the trailing whitespace region, we should not
// do a quick change,
// so 'canHandle' should have been false for those case.
region.adjustLength(lengthDifference);
// the total length is changing.
if (!RegionUpdateRule.canHandleAsWhiteSpace(region, parent, changes, region.getStart(), lengthToReplace)) {
// region.adjustTextLength(lengthDifference);
}
result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, region, changes, requestStart, lengthToReplace);
}
return result;
}
Aggregations