Search in sources :

Example 6 with DirtyRegion

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);
    }
}
Also used : Iterator(java.util.Iterator) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with DirtyRegion

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;
}
Also used : DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with DirtyRegion

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);
        }
    }
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion)

Example 9 with DirtyRegion

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);
    }
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion)

Example 10 with DirtyRegion

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);
        }
    }
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ITextSelection(org.eclipse.jface.text.ITextSelection) TextSelection(org.eclipse.jface.text.TextSelection) IBlockTextSelection(org.eclipse.jface.text.IBlockTextSelection) ISelection(org.eclipse.jface.viewers.ISelection) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) DirtyRegionProcessor(org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection)

Aggregations

DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)16 IDocument (org.eclipse.jface.text.IDocument)8 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)5 IRegion (org.eclipse.jface.text.IRegion)4 ArrayList (java.util.ArrayList)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Document (org.eclipse.jface.text.Document)2 ITypedRegion (org.eclipse.jface.text.ITypedRegion)2 Region (org.eclipse.jface.text.Region)2 AbstractReconciler (org.eclipse.jface.text.reconciler.AbstractReconciler)2 MonoReconciler (org.eclipse.jface.text.reconciler.MonoReconciler)2 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 SourceViewer (org.eclipse.jface.text.source.SourceViewer)2 TestTextViewer (org.eclipse.jface.text.tests.TestTextViewer)2 FillLayout (org.eclipse.swt.layout.FillLayout)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 Accessor (org.eclipse.text.tests.Accessor)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2