Search in sources :

Example 11 with IUnitOfWork

use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.

the class XtextGrammarRefactoringIntegrationTest method checkConsistenceOfGrammar.

private void checkConsistenceOfGrammar(XtextEditor editor) {
    waitForBuild();
    assertEquals(REFACTOREDCLASSIFIERNAME, editor.getDocument().readOnly(new IUnitOfWork<String, XtextResource>() {

        @Override
        public String exec(XtextResource state) throws Exception {
            String renamedRuleFragment = greetingParserRuleUri.fragment().replaceFirst(CLASSIFIERNAME, REFACTOREDCLASSIFIERNAME);
            EObject renamedRule = state.getEObject(renamedRuleFragment);
            assertNotNull(renamedRule);
            return SimpleAttributeResolver.NAME_RESOLVER.apply(renamedRule);
        }
    }));
    editor.getDocument().readOnly(new IUnitOfWork<Boolean, XtextResource>() {

        @Override
        public Boolean exec(XtextResource state) throws Exception {
            AbstractRule rule = ((RuleCall) ((Assignment) ((ParserRule) state.getEObject(modelParserRuleUri.fragment())).getAlternatives()).getTerminal()).getRule();
            assertFalse(rule.eIsProxy());
            assertEquals(REFACTOREDCLASSIFIERNAME, rule.getName());
            return true;
        }
    });
}
Also used : Assignment(org.eclipse.xtext.Assignment) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) AbstractRule(org.eclipse.xtext.AbstractRule) IOException(java.io.IOException)

Example 12 with IUnitOfWork

use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.

the class XtextElementLinksTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    modelAsText = "stuff mystuff\nstuff yourstuff";
    IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText);
    editor = openEditor(file);
    document = editor.getDocument();
    elementLinks = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(XtextElementLinks.class);
    f = document.readOnly(new IUnitOfWork<File, XtextResource>() {

        @Override
        public File exec(XtextResource state) throws Exception {
            return (File) state.getContents().get(0);
        }
    });
}
Also used : XtextElementLinks(org.eclipse.xtext.ui.editor.hover.html.XtextElementLinks) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) IFile(org.eclipse.core.resources.IFile) XtextResource(org.eclipse.xtext.resource.XtextResource) File(org.eclipse.xtext.ui.tests.foo.File) IFile(org.eclipse.core.resources.IFile)

Example 13 with IUnitOfWork

use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.

the class OutlineNodeTest method testStateAccess.

@Test
public void testStateAccess() {
    DocumentRootNode rootNode = createRootNode();
    EObjectNode parentNode = new EObjectNode(parentElement, rootNode, (ImageDescriptor) null, "parent", false);
    EStructuralFeatureNode featureNode = new EStructuralFeatureNode(parentElement, OutlineTestPackage.Literals.ELEMENT__XREFS, parentNode, (ImageDescriptor) null, "eClassifiers", true);
    IUnitOfWork<Boolean, EObject> work = new IUnitOfWork<Boolean, EObject>() {

        @Override
        public Boolean exec(EObject state) throws Exception {
            return state != null;
        }
    };
    assertTrue(rootNode.readOnly(work));
    assertTrue(parentNode.readOnly(work));
    assertTrue(featureNode.readOnly(work));
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) DocumentRootNode(org.eclipse.xtext.ui.editor.outline.impl.DocumentRootNode) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeatureNode(org.eclipse.xtext.ui.editor.outline.impl.EStructuralFeatureNode) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode) Test(org.junit.Test)

Example 14 with IUnitOfWork

use of org.eclipse.xtext.util.concurrent.IUnitOfWork in project xtext-eclipse by eclipse.

the class XbaseQuickfixProvider method fixObsoletCast.

@Fix(IssueCodes.OBSOLETE_CAST)
public void fixObsoletCast(final Issue issue, IssueResolutionAcceptor acceptor) {
    String fixup = "Remove unnecessary cast";
    acceptor.accept(issue, fixup, fixup, null, new IModification() {

        @Override
        public void apply(IModificationContext context) throws Exception {
            final IXtextDocument document = context.getXtextDocument();
            ReplaceRegion replacement = document.tryReadOnly(new IUnitOfWork<ReplaceRegion, XtextResource>() {

                @Override
                public ReplaceRegion exec(XtextResource state) throws Exception {
                    EObject type = state.getEObject(issue.getUriToProblem().fragment());
                    XCastedExpression cast = EcoreUtil2.getContainerOfType(type, XCastedExpression.class);
                    INode castNode = NodeModelUtils.findActualNodeFor(cast);
                    INode targetNode = NodeModelUtils.findActualNodeFor(cast.getTarget());
                    return new ReplaceRegion(castNode.getTotalTextRegion(), targetNode.getText());
                }
            });
            if (replacement != null) {
                document.replace(replacement.getOffset(), replacement.getLength(), replacement.getText());
            }
        }
    });
}
Also used : XCastedExpression(org.eclipse.xtext.xbase.XCastedExpression) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) INode(org.eclipse.xtext.nodemodel.INode) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) EObject(org.eclipse.emf.ecore.EObject) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) XtextResource(org.eclipse.xtext.resource.XtextResource) WrappedException(org.eclipse.emf.common.util.WrappedException) BadLocationException(org.eclipse.jface.text.BadLocationException) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Aggregations

IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)14 XtextResource (org.eclipse.xtext.resource.XtextResource)7 EObject (org.eclipse.emf.ecore.EObject)5 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)5 IModification (org.eclipse.xtext.ui.editor.model.edit.IModification)4 IModificationContext (org.eclipse.xtext.ui.editor.model.edit.IModificationContext)4 IFile (org.eclipse.core.resources.IFile)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 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 IEditorPart (org.eclipse.ui.IEditorPart)2 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Consumer (java.util.function.Consumer)1 IPath (org.eclipse.core.runtime.IPath)1