use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class XtextReconciler method run.
@Override
protected IStatus run(final IProgressMonitor monitor) {
if (monitor.isCanceled() || paused)
return Status.CANCEL_STATUS;
if (pendingChanges.isEmpty()) {
return Status.OK_STATUS;
}
long start = System.currentTimeMillis();
final IXtextDocument document = xtextDocumentUtil.getXtextDocument(textViewer);
if (document instanceof XtextDocument) {
((XtextDocument) document).internalModify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
doRun(state, monitor);
}
});
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
if (log.isDebugEnabled())
// $NON-NLS-1$
log.debug("Reconciliation finished. Time required: " + (System.currentTimeMillis() - start));
return Status.OK_STATUS;
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class XbaseDocumentProvider method setDocumentContent.
@Override
protected boolean setDocumentContent(IDocument document, IEditorInput input, String encoding) throws CoreException {
if (input instanceof IClassFileEditorInput && document instanceof XtextDocument) {
IClassFile classFile = ((IClassFileEditorInput) input).getClassFile();
ILocationInEclipseResource source = getClassFileSourceStorage(classFile);
if (source == null) {
return false;
}
InputStream contents = null;
try {
contents = source.getContents();
if (contents != null)
setDocumentContent(document, contents, encoding);
} catch (WrappedCoreException e) {
throw e.getCause();
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, plugin.getBundle().getSymbolicName(), e.getMessage(), e));
} finally {
try {
if (contents != null)
contents.close();
} catch (IOException e1) {
}
}
setDocumentResource((XtextDocument) document, input, encoding);
return true;
}
return super.setDocumentContent(document, input, encoding);
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class XtextOutlineTreeProviderTest method assertNoException.
protected IOutlineNode assertNoException(String model) throws Exception {
try {
XtextResource resource = getResourceAndExpect(new StringInputStream(model), UNKNOWN_EXPECTATION);
XtextDocument document = documentProvider.get();
document.setInput(resource);
IOutlineNode root = treeProvider.createRoot(document);
traverseChildren(root);
return root;
} catch (Exception exc) {
exc.printStackTrace();
fail("Exception in outline tree construction");
}
// unreachable
return null;
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class XtextDocumentModifyTest method createDocument.
private IXtextDocument createDocument(String model) throws Exception {
resource = getResource(new StringInputStream(model));
DocumentTokenSource tokenSource = new DocumentTokenSource();
tokenSource.setLexer(new Provider<Lexer>() {
@Override
public Lexer get() {
return new InternalXtextLexer();
}
});
final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {
@Override
public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
try {
return work.exec((XtextResource) resource);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
document.set(model);
return document;
}
use of org.eclipse.xtext.ui.editor.model.XtextDocument in project xtext-eclipse by eclipse.
the class DocumentLockerTest method testModifySetsOutdatedFalse.
@Test
public void testModifySetsOutdatedFalse() {
XtextDocument document = new XtextDocument(createTokenSource(), createTextEditComposer(), outdatedStateManager, operationCanceledManager);
XtextResource resource = new XtextResource();
new XtextResourceSet().getResources().add(resource);
document.setInput(resource);
document.internalModify((XtextResource it) -> {
Assert.assertFalse(document.getCancelIndicator().isCanceled());
return null;
});
CancelIndicator indicator = document.getCancelIndicator();
Assert.assertFalse(indicator.isCanceled());
document.set("fupp");
Assert.assertTrue(indicator.isCanceled());
document.internalModify((XtextResource it) -> {
Assert.assertFalse(document.getCancelIndicator().isCanceled());
return null;
});
}
Aggregations