r= fDirtyRegionQueue.removeNextDirtyRegion(); if (0 == fDirtyRegionQueue.getSize()) { synchronized (this) { fIsDirty= fProgressMonitor.isCanceled();
/** * Suspends the caller of this method until this background thread has * emptied the dirty region queue. */ public void suspendCallerWhileDirty() { boolean isDirty; do { synchronized (fDirtyRegionQueue) { isDirty= fDirtyRegionQueue.getSize() > 0; if (isDirty) { try { fDirtyRegionQueue.wait(); } catch (InterruptedException x) { } } } } while (isDirty); }
@Override public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { if (oldInput == fDocument) { if (fDocument != null) fDocument.removeDocumentListener(this); if (fIsIncrementalReconciler) { synchronized (fDirtyRegionQueue) { fDirtyRegionQueue.purgeQueue(); } if (fDocument != null && fDocument.getLength() > 0 && fThread.isDirty() && fThread.isAlive()) { DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), ""); //$NON-NLS-1$ createDirtyRegion(e); fThread.reset(); fThread.suspendCallerWhileDirty(); } } fDocument= null; } }
/** * Creates a dirty region for a document event and adds it to the queue. * * @param e the document event for which to create a dirty region */ private void createDirtyRegion(DocumentEvent e) { synchronized (fDirtyRegionQueue) { if (e.getLength() == 0 && e.getText() != null) { // Insert fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); } else if (e.getText() == null || e.getText().length() == 0) { // Remove fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); } else { // Replace (Remove + Insert) fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); } } }
@Override public void install(ITextViewer textViewer) { Assert.isNotNull(textViewer); fViewer= textViewer; synchronized (this) { if (fThread != null) return; fThread= new BackgroundThread(getClass().getName()); } fDirtyRegionQueue= new DirtyRegionQueue(); fListener= new Listener(); fViewer.addTextInputListener(fListener); // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=67046 // if the reconciler gets installed on a viewer that already has a document // (e.g. when reusing editors), we force the listener to register // itself as document listener, because there will be no input change // on the viewer. // In order to do that, we simulate an input change. IDocument document= textViewer.getDocument(); if (document != null) { fListener.inputDocumentAboutToBeChanged(fDocument, document); fListener.inputDocumentChanged(fDocument, document); } }
/** * Adds a dirty region to the end of the dirty-region queue. * * @param dr the dirty region to add */ public void addDirtyRegion(DirtyRegion dr) { // If the dirty region being added is directly after the last dirty // region on the queue then merge the two dirty regions together. DirtyRegion lastDR= getLastDirtyRegion(); boolean wasMerged= false; if (lastDR != null) if (lastDR.getType() == dr.getType()) if (lastDR.getType() == DirtyRegion.INSERT) { if (lastDR.getOffset() + lastDR.getLength() == dr.getOffset()) { lastDR.mergeWith(dr); wasMerged= true; } } else if (lastDR.getType() == DirtyRegion.REMOVE) { if (dr.getOffset() + dr.getLength() == lastDR.getOffset()) { lastDR.mergeWith(dr); wasMerged= true; } } if (!wasMerged) // Don't merge- just add the new one onto the queue. fDirtyRegions.add(dr); }
/** * Suspends the caller of this method until this background thread has * emptied the dirty region queue. */ public void suspendCallerWhileDirty() { boolean isDirty; do { synchronized (fDirtyRegionQueue) { isDirty= fDirtyRegionQueue.getSize() > 0; if (isDirty) { try { fDirtyRegionQueue.wait(); } catch (InterruptedException x) { } } } } while (isDirty); }
@Override public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) { if (oldInput == fDocument) { if (fDocument != null) fDocument.removeDocumentListener(this); if (fIsIncrementalReconciler) { synchronized (fDirtyRegionQueue) { fDirtyRegionQueue.purgeQueue(); } if (fDocument != null && fDocument.getLength() > 0 && fThread.isDirty() && fThread.isAlive()) { DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), ""); //$NON-NLS-1$ createDirtyRegion(e); fThread.reset(); fThread.suspendCallerWhileDirty(); } } fDocument= null; } }
/** * Creates a dirty region for a document event and adds it to the queue. * * @param e the document event for which to create a dirty region */ private void createDirtyRegion(DocumentEvent e) { synchronized (fDirtyRegionQueue) { if (e.getLength() == 0 && e.getText() != null) { // Insert fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); } else if (e.getText() == null || e.getText().length() == 0) { // Remove fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); } else { // Replace (Remove + Insert) fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null)); fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText())); } } }
@Override public void install(ITextViewer textViewer) { Assert.isNotNull(textViewer); fViewer= textViewer; synchronized (this) { if (fThread != null) return; fThread= new BackgroundThread(getClass().getName()); } fDirtyRegionQueue= new DirtyRegionQueue(); fListener= new Listener(); fViewer.addTextInputListener(fListener); // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=67046 // if the reconciler gets installed on a viewer that already has a document // (e.g. when reusing editors), we force the listener to register // itself as document listener, because there will be no input change // on the viewer. // In order to do that, we simulate an input change. IDocument document= textViewer.getDocument(); if (document != null) { fListener.inputDocumentAboutToBeChanged(fDocument, document); fListener.inputDocumentChanged(fDocument, document); } }
/** * Adds a dirty region to the end of the dirty-region queue. * * @param dr the dirty region to add */ public void addDirtyRegion(DirtyRegion dr) { // If the dirty region being added is directly after the last dirty // region on the queue then merge the two dirty regions together. DirtyRegion lastDR= getLastDirtyRegion(); boolean wasMerged= false; if (lastDR != null) if (lastDR.getType() == dr.getType()) if (lastDR.getType() == DirtyRegion.INSERT) { if (lastDR.getOffset() + lastDR.getLength() == dr.getOffset()) { lastDR.mergeWith(dr); wasMerged= true; } } else if (lastDR.getType() == DirtyRegion.REMOVE) { if (dr.getOffset() + dr.getLength() == lastDR.getOffset()) { lastDR.mergeWith(dr); wasMerged= true; } } if (!wasMerged) // Don't merge- just add the new one onto the queue. fDirtyRegions.add(dr); }
r= fDirtyRegionQueue.removeNextDirtyRegion(); if (0 == fDirtyRegionQueue.getSize()) { synchronized (this) { fIsDirty= fProgressMonitor.isCanceled();