Search in sources :

Example 1 with EditorResourceAccess

use of org.eclipse.xtext.ui.editor.findrefs.EditorResourceAccess in project xtext-eclipse by eclipse.

the class EditorResourceAccessTest method testAccess.

@Test
public void testAccess() throws Exception {
    EditorResourceAccess access = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(EditorResourceAccess.class);
    IUnitOfWork<Boolean, ResourceSet> isEmpty = new IUnitOfWork<Boolean, ResourceSet>() {

        @Override
        public Boolean exec(ResourceSet state) throws Exception {
            return state.getResources().get(0).getContents().isEmpty();
        }
    };
    assertTrue(access.readOnly(uri, isEmpty));
    XtextEditor editor = openEditor(file);
    runAsyncJobs();
    assertTrue(access.readOnly(uri, isEmpty));
    editor.getDocument().set("A");
    runAsyncJobs();
    waitForReconciler(editor);
    runAsyncJobs();
    assertFalse(access.readOnly(uri, isEmpty));
    editor.close(false);
    runAsyncJobs();
    assertTrue(access.readOnly(uri, isEmpty));
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EditorResourceAccess(org.eclipse.xtext.ui.editor.findrefs.EditorResourceAccess) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 EditorResourceAccess (org.eclipse.xtext.ui.editor.findrefs.EditorResourceAccess)1 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1 Test (org.junit.Test)1