Search in sources :

Example 1 with XtextDocumentReconcileStrategy

use of org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy in project xtext-eclipse by eclipse.

the class Bug297909Test method testReconcileDocument.

@Test
public void testReconcileDocument() throws Exception {
    Injector injector = doGetSetup().createInjectorAndDoEMFRegistration();
    XtextDocument document = injector.getInstance(XtextDocument.class);
    document.setValidationJob(new Job("Job") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            return Status.OK_STATUS;
        }
    });
    XtextResource resource = injector.getInstance(XtextResource.class);
    XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
    resourceSet.getResources().add(resource);
    resource.load(new StringInputStream(""), Collections.singletonMap(XtextResource.OPTION_ENCODING, Charset.defaultCharset().name()));
    document.setInput(resource);
    document.set("abstract rules firstRule");
    XtextDocumentReconcileStrategy strategy = injector.getInstance(XtextDocumentReconcileStrategy.class);
    strategy.setDocument(document);
    strategy.setResource(resource);
    try {
        strategy.reconcile(new ReconcilerReplaceRegion(0, document.getLength(), document.get()));
        fail("Expected ParseException");
    } catch (ParseException expected) {
        assertTrue(expected.getMessage().contains("Make sure the EPackage has been registered"));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextDocumentReconcileStrategy(org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy) ReconcilerReplaceRegion(org.eclipse.xtext.ui.editor.reconciler.ReconcilerReplaceRegion) Injector(com.google.inject.Injector) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ParseException(org.eclipse.xtext.parser.ParseException) Job(org.eclipse.core.runtime.jobs.Job) Test(org.junit.Test)

Aggregations

Injector (com.google.inject.Injector)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Job (org.eclipse.core.runtime.jobs.Job)1 ParseException (org.eclipse.xtext.parser.ParseException)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)1 ReconcilerReplaceRegion (org.eclipse.xtext.ui.editor.reconciler.ReconcilerReplaceRegion)1 XtextDocumentReconcileStrategy (org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Test (org.junit.Test)1