Search in sources :

Example 11 with DirtyRegion

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;
}
Also used : DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 12 with DirtyRegion

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());
}
Also used : IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) TestTextViewer(org.eclipse.jface.text.tests.TestTextViewer) ArrayList(java.util.ArrayList) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) Accessor(org.eclipse.text.tests.Accessor) IDocument(org.eclipse.jface.text.IDocument) AbstractReconciler(org.eclipse.jface.text.reconciler.AbstractReconciler)

Example 13 with DirtyRegion

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

Example 14 with DirtyRegion

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

Example 15 with DirtyRegion

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;
}
Also used : DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

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