use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class DocumentLockerTest method testNoUpdateContentProcessOnReentrant.
@Test
public void testNoUpdateContentProcessOnReentrant() {
List<String> s = new ArrayList<>();
XtextDocument document = new XtextDocument(createTokenSource(), createTextEditComposer(), outdatedStateManager, operationCanceledManager) {
@Override
protected boolean updateContentBeforeRead() {
return s.add("x");
}
};
XtextResource resource = new XtextResource();
new XtextResourceSet().getResources().add(resource);
document.setInput(resource);
Assert.assertEquals(0, s.size());
document.readOnly(r1 -> {
Assert.assertEquals(1, s.size());
document.readOnly(r2 -> {
Assert.assertEquals(1, s.size());
document.readOnly(r3 -> {
Assert.assertEquals(1, s.size());
return null;
});
return null;
});
return null;
});
Assert.assertEquals(1, s.size());
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument 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"));
}
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class StreamContentDocumentProvider method setupDocument.
protected void setupDocument(Object element, IDocument document) {
String content = getString(element);
document.set(content);
IDocumentPartitioner partitioner = documentPartitioner.get();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
XtextResource resource = createResource(element);
loadResource(element, resource);
if (resource != null) {
((XtextDocument) document).setInput(resource);
}
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class StreamContentDocumentProvider method disposeElementInfo.
@Override
protected void disposeElementInfo(Object element, ElementInfo info) {
if (info.fDocument instanceof XtextDocument) {
XtextDocument document = (XtextDocument) info.fDocument;
document.disposeInput();
}
super.disposeElementInfo(element, info);
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project dsl-devkit by dsldevkit.
the class FixedHighlightingReconciler method uninstall.
/**
* Uninstall this reconciler from the editor
*/
@Override
public void uninstall() {
if (presenter != null) {
presenter.setCanceled(true);
}
if (sourceViewer.getDocument() != null) {
if (oldCalculator != null || newCalculator != null) {
XtextDocument document = (XtextDocument) sourceViewer.getDocument();
document.removeModelListener(this);
sourceViewer.removeTextInputListener(this);
}
}
synchronized (fReconcileLock) {
if (reconciling) {
cleanUpAfterReconciliation = true;
} else {
editor = null;
sourceViewer = null;
presenter = null;
}
}
}
Aggregations