Search in sources :

Example 1 with DirtyRegion

use of org.eclipse.jface.text.reconciler.DirtyRegion in project eclipse.platform.text by eclipse.

the class SpellingReconcileStrategy method reconcile.

@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
    try {
        IRegion startLineInfo = fDocument.getLineInformationOfOffset(subRegion.getOffset());
        IRegion endLineInfo = fDocument.getLineInformationOfOffset(subRegion.getOffset() + Math.max(0, subRegion.getLength() - 1));
        if (startLineInfo.getOffset() == endLineInfo.getOffset())
            subRegion = startLineInfo;
        else
            subRegion = new Region(startLineInfo.getOffset(), endLineInfo.getOffset() + Math.max(0, endLineInfo.getLength() - 1) - startLineInfo.getOffset());
    } catch (BadLocationException e) {
        subRegion = new Region(0, fDocument.getLength());
    }
    reconcile(subRegion);
}
Also used : Region(org.eclipse.jface.text.Region) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with DirtyRegion

use of org.eclipse.jface.text.reconciler.DirtyRegion in project eclipse.platform.text by eclipse.

the class AbstractReconcilerTest method setUp.

@Before
public void setUp() {
    fBarrier = new Barrier();
    fCallLog = Collections.synchronizedList(new ArrayList<String>());
    fReconciler = new AbstractReconciler() {

        @Override
        protected void initialProcess() {
            fCallLog.add("initialProcess");
            fBarrier.await();
        }

        @Override
        protected void process(DirtyRegion dirtyRegion) {
            fCallLog.add("process");
            fBarrier.await();
        }

        @Override
        protected void reconcilerDocumentChanged(IDocument newDocument) {
            fCallLog.add("reconcilerDocumentChanged");
        }

        @Override
        protected void aboutToBeReconciled() {
            fCallLog.add("aboutToBeReconciled");
        }

        @Override
        protected void reconcilerReset() {
            fCallLog.add("reconcilerReset");
        }

        @Override
        public IReconcilingStrategy getReconcilingStrategy(String contentType) {
            return null;
        }
    };
    fReconciler.setIsIncrementalReconciler(false);
    // make tests run faster
    fReconciler.setDelay(50);
    fProgressMonitor = new NullProgressMonitor();
    fReconciler.setProgressMonitor(fProgressMonitor);
    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 : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) 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) Before(org.junit.Before)

Example 3 with DirtyRegion

use of org.eclipse.jface.text.reconciler.DirtyRegion in project eclipse.platform.text by eclipse.

the class CodeMiningDemo method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Code Mining demo");
    ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
    sourceViewer.setDocument(new Document("// Type class & new keyword and see references CodeMining\n" + "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n" + "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"), new AnnotationModel());
    // Add AnnotationPainter (required by CodeMining)
    addAnnotationPainter(sourceViewer);
    // Initialize codemining providers
    ((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] { new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
    // Execute codemining in a reconciler
    MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {

        @Override
        public void setDocument(IDocument document) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }

        @Override
        public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
        }

        @Override
        public void reconcile(IRegion partition) {
            ((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
        }
    }, false);
    reconciler.install(sourceViewer);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 4 with DirtyRegion

use of org.eclipse.jface.text.reconciler.DirtyRegion in project eclipse.platform.text by eclipse.

the class InlinedAnnotationDemo method main.

public static void main(String[] args) throws Exception {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.setText("Inlined annotation demo");
    // Create source viewer and initialize the content
    ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
    sourceViewer.setDocument(new Document("\ncolor:rgb(255, 255, 0)"), new AnnotationModel());
    // Initialize inlined annotations support
    InlinedAnnotationSupport support = new InlinedAnnotationSupport();
    support.install(sourceViewer, createAnnotationPainter(sourceViewer));
    // Refresh inlined annotation in none UI Thread with reconciler.
    MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {

        @Override
        public void setDocument(IDocument document) {
            Set<AbstractInlinedAnnotation> annotations = getInlinedAnnotation(sourceViewer, support);
            support.updateAnnotations(annotations);
        }

        @Override
        public void reconcile(IRegion partition) {
            Set<AbstractInlinedAnnotation> anns = getInlinedAnnotation(sourceViewer, support);
            support.updateAnnotations(anns);
        }

        @Override
        public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
        }
    }, false);
    reconciler.setDelay(1);
    reconciler.install(sourceViewer);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) HashSet(java.util.HashSet) Set(java.util.Set) InlinedAnnotationSupport(org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport) FillLayout(org.eclipse.swt.layout.FillLayout) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) MonoReconciler(org.eclipse.jface.text.reconciler.MonoReconciler) IRegion(org.eclipse.jface.text.IRegion) Shell(org.eclipse.swt.widgets.Shell) IReconcilingStrategy(org.eclipse.jface.text.reconciler.IReconcilingStrategy) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) Display(org.eclipse.swt.widgets.Display)

Example 5 with DirtyRegion

use of org.eclipse.jface.text.reconciler.DirtyRegion in project titan.EclipsePlug-ins by eclipse.

the class Reconciler method install.

/*
	 * @see IReconciler#install(ITextViewer)
	 */
@Override
public final void install(final ITextViewer textViewer) {
    Assert.isNotNull(textViewer);
    this.textViewer = textViewer;
    synchronized (this) {
        if (backgroundThread != null) {
            return;
        }
        backgroundThread = new BackgroundThread(getClass().getName());
    }
    // dirtyRegionQueue = new ArrayList<DirtyRegion>();
    dirtyRegionQueue = new LinkedBlockingQueue<DirtyRegion>();
    changeListener = new Listener();
    textViewer.addTextInputListener(changeListener);
    // 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 tmpDocument = textViewer.getDocument();
    if (tmpDocument != null) {
        changeListener.inputDocumentAboutToBeChanged(tmpDocument, tmpDocument);
        changeListener.inputDocumentChanged(tmpDocument, tmpDocument);
    }
}
Also used : ITextInputListener(org.eclipse.jface.text.ITextInputListener) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DirtyRegion(org.eclipse.jface.text.reconciler.DirtyRegion) IDocument(org.eclipse.jface.text.IDocument)

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