use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class DocumentLockerTest method testNoUpdateContentProcessOnReentrant.
@Test
public void testNoUpdateContentProcessOnReentrant() {
final ArrayList<String> s = CollectionLiterals.<String>newArrayList();
DocumentTokenSource _createTokenSource = this.createTokenSource();
ITextEditComposer _createTextEditComposer = this.createTextEditComposer();
final XtextDocument document = new XtextDocument(_createTokenSource, _createTextEditComposer, this.outdatedStateManager, this.operationCanceledManager) {
@Override
protected boolean updateContentBeforeRead() {
return s.add("x");
}
};
XtextResource _xtextResource = new XtextResource();
final Procedure1<XtextResource> _function = (XtextResource it) -> {
EList<Resource> _resources = new XtextResourceSet().getResources();
_resources.add(it);
};
XtextResource _doubleArrow = ObjectExtensions.<XtextResource>operator_doubleArrow(_xtextResource, _function);
document.setInput(_doubleArrow);
Assert.assertEquals(0, s.size());
final IUnitOfWork<Object, XtextResource> _function_1 = (XtextResource it) -> {
Assert.assertEquals(1, s.size());
final IUnitOfWork<Object, XtextResource> _function_2 = (XtextResource it_1) -> {
Assert.assertEquals(1, s.size());
final IUnitOfWork<Object, XtextResource> _function_3 = (XtextResource it_2) -> {
Assert.assertEquals(1, s.size());
return null;
};
document.<Object>readOnly(_function_3);
return null;
};
document.<Object>readOnly(_function_2);
return null;
};
document.<Object>readOnly(_function_1);
Assert.assertEquals(1, s.size());
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork 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.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.
the class AbstractOpenHierarchyHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
Object _xblockexpression = null;
{
final XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
Object _xifexpression = null;
if ((editor != null)) {
Object _xblockexpression_1 = null;
{
final ISelection selection = editor.getSelectionProvider().getSelection();
Object _xifexpression_1 = null;
if ((selection instanceof ITextSelection)) {
Object _xblockexpression_2 = null;
{
final IWorkbenchWindow workbenchWindow = editor.getSite().getWorkbenchWindow();
final IUnitOfWork<Object, XtextResource> _function = (XtextResource it) -> {
Object _xblockexpression_3 = null;
{
this.openHierarchy(this._eObjectAtOffsetHelper.resolveElementAt(it, ((ITextSelection) selection).getOffset()), workbenchWindow);
_xblockexpression_3 = null;
}
return _xblockexpression_3;
};
_xblockexpression_2 = editor.getDocument().<Object>priorityReadOnly(_function);
}
_xifexpression_1 = _xblockexpression_2;
}
_xblockexpression_1 = _xifexpression_1;
}
_xifexpression = _xblockexpression_1;
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project dsl-devkit by dsldevkit.
the class FormatQuickfixProvider method removeOverride.
/**
* Semantic quickfix removing the override flag for a rule.
*
* @param issue
* the issue
* @param acceptor
* the acceptor
*/
@Fix(FormatJavaValidator.OVERRIDE_ILLEGAL_CODE)
public void removeOverride(final Issue issue, final IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove override", "Remove override.", null, new IModification() {
@Override
public void apply(final IModificationContext context) throws BadLocationException {
context.getXtextDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(final XtextResource state) {
Rule rule = (Rule) state.getEObject(issue.getUriToProblem().fragment());
rule.setOverride(false);
return null;
}
});
}
});
}
use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project dsl-devkit by dsldevkit.
the class XtextElementSelectionListenerTest method mockNodeAtSelection.
/**
* Mocks a text selection and causes the (mocked) XtextEditor to return an ILeafNode on any read(IUnitOfWork).
*
* @return the mocked ILeafNode
*/
@SuppressWarnings("unchecked")
private ILeafNode mockNodeAtSelection(final XtextEditor mockEditor) {
IXtextDocument mockDocument = mock(IXtextDocument.class);
ILeafNode mockNode = mock(ILeafNode.class);
when(mockEditor.getDocument()).thenReturn(mockDocument);
when(mockDocument.<ILeafNode>priorityReadOnly(any(IUnitOfWork.class))).thenReturn(mockNode);
when(mockDocument.<ILeafNode>readOnly(any(IUnitOfWork.class))).thenReturn(mockNode);
// when(mockDocument.readOnly(any(IUnitOfWork<ILeafNode, XtextResource>.class))).thenReturn(mockLeafNode);
selectionListener.selectionChanged(null, mock(ITextSelection.class));
return mockNode;
}
Aggregations