Search in sources :

Example 1 with IUnitOfWork

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());
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EList(org.eclipse.emf.common.util.EList) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) AbstractXtextDocumentTest(org.eclipse.xtext.ui.tests.editor.model.AbstractXtextDocumentTest) Test(org.junit.Test)

Example 2 with IUnitOfWork

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;
}
Also used : OutdatedStateManager(org.eclipse.xtext.resource.OutdatedStateManager) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ITextEditComposer(org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) StringInputStream(org.eclipse.xtext.util.StringInputStream) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) InternalXtextLexer(org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer)

Example 3 with IUnitOfWork

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) ISelection(org.eclipse.jface.viewers.ISelection) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 4 with IUnitOfWork

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;
                }
            });
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtextResource(org.eclipse.xtext.resource.XtextResource) Rule(com.avaloq.tools.ddk.xtext.format.format.Rule) BadLocationException(org.eclipse.jface.text.BadLocationException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 5 with IUnitOfWork

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;
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ITextSelection(org.eclipse.jface.text.ITextSelection) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Aggregations

IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)17 XtextResource (org.eclipse.xtext.resource.XtextResource)10 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)7 EObject (org.eclipse.emf.ecore.EObject)6 IFile (org.eclipse.core.resources.IFile)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)4 IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)4 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)4 Test (org.junit.Test)4 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Fix (org.eclipse.xtext.ui.editor.quickfix.Fix)3 Rule (com.avaloq.tools.ddk.xtext.format.format.Rule)2 URI (org.eclipse.emf.common.util.URI)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 IEditorPart (org.eclipse.ui.IEditorPart)2 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)2 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)2 ITextEditComposer (org.eclipse.xtext.ui.editor.model.edit.ITextEditComposer)2