use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class DirtyRegionProcessor method addRequest.
/**
* Adds the given resource to the set of resources that need refreshing.
* Synchronized in order to protect the collection during add.
*
* @param resource
*/
private synchronized void addRequest(DirtyRegion newDirtyRegion) {
// NOTE: This method is called a lot so make sure it's fast
List dirtyRegionQueue = getDirtyRegionQueue();
synchronized (dirtyRegionQueue) {
for (Iterator it = dirtyRegionQueue.iterator(); it.hasNext(); ) {
// go through list of existing dirty regions and check if any
// dirty regions need to be discarded
DirtyRegion currentExisting = (DirtyRegion) it.next();
DirtyRegion outer = getOuterRegion(currentExisting, newDirtyRegion);
// discard the new request
if (outer == currentExisting)
return;
// remove those
if (outer == newDirtyRegion)
it.remove();
}
dirtyRegionQueue.add(newDirtyRegion);
}
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class DirtyRegionProcessor 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 + "] ";
Logger.logException(info, e);
}
}
return durty;
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class DirtyRegionProcessor method setEntireDocumentDirty.
/**
* Basically means process the entire document.
*
* @param document
*/
protected void setEntireDocumentDirty(IDocument document) {
// this also happens on a "save as"
if (document != null && isInstalled()) {
// since we're marking the entire doc dirty
flushDirtyRegionQueue();
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=199053
*
* Process the strategies for the last known-good partitions to
* ensure all problem annotations are cleared if needed.
*/
if (fLastPartitions != null && document.getLength() == 0) {
for (int i = 0; i < fLastPartitions.length; i++) {
IReconcilingStrategy strategy = getReconcilingStrategy(fLastPartitions[i].getType());
if (strategy != null) {
strategy.reconcile(fLastPartitions[i]);
}
}
} else {
DirtyRegion entireDocument = createDirtyRegion(0, document.getLength(), DirtyRegion.INSERT);
processDirtyRegion(entireDocument);
}
}
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class DocumentRegionProcessor method process.
/**
* @param dirtyRegion
*/
protected void process(DirtyRegion dirtyRegion) {
if (!isInstalled() || isInRewriteSession() || dirtyRegion == null || getDocument() == null)
return;
super.process(dirtyRegion);
ITypedRegion[] partitions = computePartitioning(dirtyRegion);
// 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);
}
}
/* if there is a folding strategy then reconcile it for the
* entire dirty region.
* NOTE: the folding strategy does not care about the sub regions.
*/
if (getFoldingStrategy() != null) {
getFoldingStrategy().reconcile(dirtyRegion, null);
}
}
use of org.eclipse.jface.text.reconciler.DirtyRegion in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method handleElementContentReplaced.
protected void handleElementContentReplaced() {
super.handleElementContentReplaced();
// queue a full revalidation of content
IDocument document = getDocumentProvider().getDocument(getEditorInput());
SourceViewerConfiguration sourceViewerConfiguration = getSourceViewerConfiguration();
if (document != null && sourceViewerConfiguration != null && sourceViewerConfiguration.getReconciler(getSourceViewer()) instanceof DirtyRegionProcessor) {
((DirtyRegionProcessor) sourceViewerConfiguration.getReconciler(getSourceViewer())).processDirtyRegion(new DirtyRegion(0, document.getLength(), DirtyRegion.INSERT, document.get()));
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=129906 - update
* selection to listeners
*/
ISelectionProvider selectionProvider = getSelectionProvider();
ISelection originalSelection = selectionProvider.getSelection();
if (selectionProvider instanceof StructuredSelectionProvider && originalSelection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) originalSelection;
// make sure the old selection is actually still valid
if (!textSelection.isEmpty() && (document == null || textSelection.getOffset() + textSelection.getLength() <= document.getLength())) {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(textSelection.getOffset(), textSelection.getLength()));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
} else {
SelectionChangedEvent syntheticEvent = new SelectionChangedEvent(selectionProvider, new TextSelection(0, 0));
((StructuredSelectionProvider) selectionProvider).handleSelectionChanged(syntheticEvent);
((StructuredSelectionProvider) selectionProvider).handlePostSelectionChanged(syntheticEvent);
}
}
}
Aggregations