use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testPrependSpaceToAttributeValue.
public void testPrependSpaceToAttributeValue() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) before).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 6, 0, " ");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertEquals("Node replaced", before, after);
assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
assertEquals("unexpected document content", "<a b= c></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class JSPReParser method reparse.
/**
* The core reparsing method ... after the dirty start and dirty end have
* been calculated elsewhere. - this method overrides, does not extend
* super's method. changes/fixes to super may have to be made here as
* well.
*/
protected StructuredDocumentEvent reparse(IStructuredDocumentRegion dirtyStart, IStructuredDocumentRegion dirtyEnd) {
StructuredDocumentEvent result = null;
int rescanStart = -1;
int rescanEnd = -1;
boolean firstTime = false;
boolean detectedBreakingChange = false;
//
// "save" the oldNodes (that may be replaced) in a list
CoreNodeList oldNodes = formOldNodes(dirtyStart, dirtyEnd);
if (containsBreakingChange(oldNodes) || isBreakingWithNestedTag(dirtyStart, dirtyEnd)) {
if (Debug.debugTaglibs)
// $NON-NLS-1$
System.out.println("reparse: is taglib or include");
detectedBreakingChange = true;
rescanStart = 0;
rescanEnd = fStructuredDocument.getLength() + fLengthDifference;
oldNodes = formOldNodes(fStructuredDocument.getFirstStructuredDocumentRegion(), fStructuredDocument.getLastStructuredDocumentRegion());
clearTaglibInfo();
} else if (dirtyStart == null || dirtyEnd == null) {
// dirtyStart or dirty end are null, then that means we didn't
// have a
// cached node, which means we have an empty document, so we
// just need to rescan the changes
rescanStart = 0;
rescanEnd = fChanges.length();
firstTime = true;
} else {
// set the start of the text to rescan
rescanStart = dirtyStart.getStart();
//
// set the end of the text to rescan
// notice we use the same rationale as for the rescanStart,
// with the added caveat that length has to be added to it,
// to compensate for the new text which has been added or deleted.
// If changes has zero length, then "length" will be negative,
// since
// we are deleting text. Otherwise, use the difference between
// what's selected to be replaced and the length of the new text.
rescanEnd = dirtyEnd.getEnd() + fLengthDifference;
}
// now that we have the old stuff "saved" away, update the document
// with the changes.
fStructuredDocument.updateDocumentData(fStart, fLengthToReplace, fChanges);
// ------------------ now the real work
result = core_reparse(rescanStart, rescanEnd, oldNodes, firstTime);
// everthing, so no need to do again.
if ((!detectedBreakingChange) && (containsBreakingChange(oldNodes))) {
clearTaglibInfo();
// reparse all
oldNodes = formOldNodes(fStructuredDocument.getFirstStructuredDocumentRegion(), fStructuredDocument.getLastStructuredDocumentRegion());
result = core_reparse(0, fStructuredDocument.getLength(), oldNodes, firstTime);
}
// some optimization they can do
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class JSPReParser method checkForJSPEL.
private StructuredDocumentEvent checkForJSPEL() {
StructuredDocumentEvent result = null;
// $NON-NLS-1$
result = checkForCriticalKey("${");
if (result == null)
// $NON-NLS-1$
result = checkForCriticalKey("}");
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class CSSStructuredDocumentReParser method checkInsideBrace.
private StructuredDocumentEvent checkInsideBrace(int start, int end) {
StructuredDocumentEvent result = null;
IStructuredDocumentRegion region = fStructuredDocument.getRegionAtCharacterOffset(start);
if (region == null) {
return null;
}
boolean bDeclaration = false;
String type = region.getType();
if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_LBRACE || type == CSSRegionContexts.CSS_RBRACE) {
bDeclaration = true;
}
if (!bDeclaration) {
IStructuredDocumentRegion prevRegion = CSSUtil.findPreviousSignificantNode(region);
if (prevRegion != null) {
type = prevRegion.getType();
if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_LBRACE) {
bDeclaration = true;
}
}
}
if (!bDeclaration) {
IStructuredDocumentRegion nextRegion = CSSUtil.findNextSignificantNode(region);
if (nextRegion != null) {
type = nextRegion.getType();
if (CSSRegionUtil.isDeclarationType(type) || type == CSSRegionContexts.CSS_RBRACE) {
bDeclaration = true;
}
}
}
if (bDeclaration) {
IStructuredDocumentRegion startRegion = findRuleStart(region);
if (startRegion != null) {
IStructuredDocumentRegion endRegion = fStructuredDocument.getRegionAtCharacterOffset(end);
if (endRegion != null) {
result = reparse(startRegion, endRegion);
}
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent in project webtools.sourceediting by eclipse.
the class UpdaterTestRegionChanged method testModel.
public void testModel() {
IDOMModel model = createXMLModel();
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 5, 1, "");
if (fmEvent instanceof RegionChangedEvent) {
fOutputWriter.writeln("ok: RegionChangedEvent");
} else {
fOutputWriter.writeln("not ok: " + fmEvent.getClass().getName());
}
Node after = document.getFirstChild();
if (before != after) {
fOutputWriter.writeln("not ok: Node replaced");
} else {
fOutputWriter.writeln("ok: Node not replaced");
}
saveAndCompareTestResults();
} finally {
model.releaseFromEdit();
}
}
Aggregations