use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class StructuredRegionProcessor method _getOuterRegion.
/**
* Assumes that when this method is called, region1's node start offset >=
* region2's node start offset. Determines if region1 contains region2 or
* vice versa. Returns region1 if:
* <ul>
* <li>region1's node region == region2's node region</li>
* <li>region1's node region contains region2's node region</li>
* </ul>
* Returns region2 if:
* <ul>
* <li>region1's node region and region2's node region starts at same
* offset but region2's node region is longer</li>
* </ul>
* Returns null otherwise.
*
* @param region1
* @param region2
* @param sModel
* @param region1NodeStart
* @param region2NodeStart
* @return outer dirty region or null if none exists.
*/
private DirtyRegion _getOuterRegion(DirtyRegion region1, DirtyRegion region2, IStructuredModel sModel, int region1NodeStart, int region2NodeStart) {
DirtyRegion outer = null;
int region1NodeEnd = -1;
int region2NodeEnd = -1;
// then check if region1's end appears after
// region2's end
IndexedRegion region1EndNode = sModel.getIndexedRegion(region1.getOffset() + region1.getLength());
if (region1EndNode == null) {
// if no end, just assume region spans all the
// way to the end so it includes other region
outer = region1;
} else {
region1NodeEnd = region1EndNode.getEndOffset();
IndexedRegion region2EndNode = sModel.getIndexedRegion(region2.getOffset() + region2.getLength());
region2NodeEnd = region2EndNode != null ? region2EndNode.getEndOffset() : getDocument().getLength();
if (region1NodeEnd >= region2NodeEnd) {
// root contains or is equal to possible
outer = region1;
} else if (region1NodeStart == region2NodeStart && region2NodeEnd >= region1NodeEnd) {
// possible contains root because they
// both start at same place but possible
// is longer
outer = region2;
}
}
if (DEBUG) {
if (outer != null)
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... " + outer.toString());
else
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
System.out.println("checking if [" + region1NodeStart + ":" + region1NodeEnd + "] contains [" + region2NodeStart + ":" + region2NodeEnd + "] ... NO CONTAIN");
}
return outer;
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class AbstractReconcilerTest method setUp.
protected void setUp() {
fBarrier = new Barrier();
fCallLog = Collections.synchronizedList(new ArrayList());
fReconciler = new AbstractReconciler() {
protected void initialProcess() {
fCallLog.add("initialProcess");
fBarrier.await();
}
protected void process(DirtyRegion dirtyRegion) {
fCallLog.add("process");
fBarrier.await();
}
protected void reconcilerDocumentChanged(IDocument newDocument) {
fCallLog.add("reconcilerDocumentChanged");
}
protected void aboutToBeReconciled() {
fCallLog.add("aboutToBeReconciled");
}
protected void reconcilerReset() {
fCallLog.add("reconcilerReset");
}
public IReconcilingStrategy getReconcilingStrategy(String contentType) {
return null;
}
};
fReconciler.setIsIncrementalReconciler(false);
// make tests run faster
fReconciler.setDelay(50);
fViewer = new TestTextViewer();
fReconciler.install(fViewer);
fAccessor = new Accessor(fReconciler, AbstractReconciler.class);
Object object = fAccessor.get("fThread");
fAccessor = new Accessor(object, object.getClass());
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class JavascriptValidationStrategy method reconcile.
/* (non-Javadoc)
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
*/
public void reconcile(IRegion partition) {
ITypedRegion[] partitions = computePartitioning(partition);
// call the validator strategy once for each effected partition
DirtyRegion dirty = null;
for (int i = 0; i < partitions.length; i++) {
dirty = createDirtyRegion(partitions[i], DirtyRegion.INSERT);
// [source]validator (extension) for this partition
if (getValidatorStrategy() != null) {
getValidatorStrategy().reconcile(partitions[i], dirty);
}
}
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class JavascriptValidationStrategy method createDirtyRegion.
protected DirtyRegion createDirtyRegion(int offset, int length, String type) {
DirtyRegion durty = null;
IDocument doc = getDocument();
if (doc != null) {
// safety for BLE
int docLen = doc.getLength();
if (offset > docLen) {
offset = docLen;
length = 0;
} else if (offset + length >= docLen)
length = docLen - offset;
try {
durty = new DirtyRegion(offset, length, type, doc.get(offset, length));
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String info = "dr: [" + offset + ":" + length + "] doc: [" + docLen + "] ";
IStatus status = new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.OK, info, e);
JavaScriptPlugin.getDefault().getLog().log(status);
}
}
return durty;
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class StructuredRegionProcessor method getOuterRegion.
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor#getOuterRegion(org.eclipse.jface.text.reconciler.DirtyRegion,
* org.eclipse.jface.text.reconciler.DirtyRegion)
*/
protected DirtyRegion getOuterRegion(DirtyRegion root, DirtyRegion possible) {
// first try simple region check if one region contains the other
DirtyRegion outer = super.getOuterRegion(root, possible);
if (outer == null && fCurrentDoc != null) {
IStructuredModel sModel = null;
try {
sModel = getStructuredModelForRead(fCurrentDoc);
if (sModel != null) {
// now compare nodes
IndexedRegion rootRegion = sModel.getIndexedRegion(root.getOffset());
IndexedRegion possRegion = sModel.getIndexedRegion(possible.getOffset());
if (rootRegion != null && possRegion != null) {
int rootStart = rootRegion.getStartOffset();
int possStart = possRegion.getStartOffset();
// possregion
if (rootStart <= possStart) {
// check if possregion is inside rootregion
outer = _getOuterRegion(root, possible, sModel, rootStart, possStart);
} else {
// otherwise if rootregion is inside possregion
outer = _getOuterRegion(possible, root, sModel, possStart, rootStart);
}
}
}
} finally {
if (sModel != null) {
sModel.releaseFromRead();
}
}
}
return outer;
}
Aggregations