Search in sources :

Example 1 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-eclipse by eclipse.

the class DocumentLockerTest method addReaderCancelationListener.

private void addReaderCancelationListener(final IXtextDocument document, final List<CancelIndicator> cancelIndicators) {
    final IXtextModelListener _function = (XtextResource it) -> {
        final CancelableUnitOfWork<Boolean, XtextResource> _function_1 = new CancelableUnitOfWork<Boolean, XtextResource>() {

            @Override
            public Boolean exec(final XtextResource state, final CancelIndicator cancelIndicator) throws Exception {
                boolean _xblockexpression = false;
                {
                    Assert.assertFalse(cancelIndicator.isCanceled());
                    _xblockexpression = cancelIndicators.add(cancelIndicator);
                }
                return Boolean.valueOf(_xblockexpression);
            }
        };
        final CancelableUnitOfWork<Boolean, XtextResource> work = _function_1;
        document.<Boolean>readOnly(work);
    };
    document.addModelListener(_function);
}
Also used : CancelableUnitOfWork(org.eclipse.xtext.util.concurrent.CancelableUnitOfWork) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) IXtextModelListener(org.eclipse.xtext.ui.editor.model.IXtextModelListener)

Example 2 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.

the class AbstractXtendTestCase method file.

protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    if (shouldBeSyntacticallyValid) {
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    if (validate) {
        List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {

            @Override
            public boolean apply(Issue issue) {
                return issue.getSeverity() == Severity.ERROR;
            }
        }));
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Predicate(com.google.common.base.Predicate)

Example 3 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-xtend by eclipse.

the class RefactoringIntegrationTest method performRenameTest.

protected void performRenameTest(IFile file, String originalContents, String oldName, String newName, IFile newFile) throws Exception {
    IResourcesSetupUtil.waitForBuild();
    ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
    XtextResource resource = (XtextResource) resourceSet.getResource(testHelper.uri(file), true);
    EObject target = eObjectAtOffsetHelper.resolveElementAt(resource, originalContents.indexOf(oldName));
    doRename(target, newName);
    String contentsAfterRename = WorkbenchTestHelper.getContentsAsString(newFile);
    assertEquals(originalContents.replace(oldName, newName), contentsAfterRename);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 4 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class LanguageServerImpl method afterBuild.

@Override
public void afterBuild(final List<IResourceDescription.Delta> deltas) {
    if ((this.client instanceof LanguageClientExtensions)) {
        final Function1<IResourceDescription.Delta, Boolean> _function = (IResourceDescription.Delta it) -> {
            IResourceDescription _new = it.getNew();
            return Boolean.valueOf((_new != null));
        };
        final Function1<IResourceDescription.Delta, String> _function_1 = (IResourceDescription.Delta it) -> {
            return it.getUri().toString();
        };
        final Consumer<String> _function_2 = (String it) -> {
            final Function<ILanguageServerAccess.Context, Void> _function_3 = (ILanguageServerAccess.Context ctx) -> {
                boolean _isDocumentOpen = ctx.isDocumentOpen();
                if (_isDocumentOpen) {
                    Resource _resource = ctx.getResource();
                    if ((_resource instanceof XtextResource)) {
                        Resource _resource_1 = ctx.getResource();
                        final XtextResource resource = ((XtextResource) _resource_1);
                        final IResourceServiceProvider serviceProvider = this.languagesRegistry.getResourceServiceProvider(resource.getURI());
                        IColoringService _get = null;
                        if (serviceProvider != null) {
                            _get = serviceProvider.<IColoringService>get(IColoringService.class);
                        }
                        final IColoringService coloringService = _get;
                        if ((coloringService != null)) {
                            final Document doc = ctx.getDocument();
                            final List<? extends ColoringInformation> coloringInfos = coloringService.getColoring(resource, doc);
                            boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(coloringInfos);
                            boolean _not = (!_isNullOrEmpty);
                            if (_not) {
                                final String uri = resource.getURI().toString();
                                ColoringParams _coloringParams = new ColoringParams(uri, coloringInfos);
                                ((LanguageClientExtensions) this.client).updateColoring(_coloringParams);
                            }
                        }
                    }
                    return null;
                }
                return null;
            };
            this.access.<Void>doRead(it, _function_3);
        };
        IterableExtensions.<IResourceDescription.Delta, String>map(IterableExtensions.<IResourceDescription.Delta>filter(deltas, _function), _function_1).forEach(_function_2);
    }
}
Also used : LanguageClientExtensions(org.eclipse.lsp4j.services.LanguageClientExtensions) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) XtextResource(org.eclipse.xtext.resource.XtextResource) ColoringParams(org.eclipse.lsp4j.ColoringParams) Document(org.eclipse.xtext.ide.server.Document) Function(java.util.function.Function) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IColoringService(org.eclipse.xtext.ide.server.coloring.IColoringService) ILanguageServerAccess(org.eclipse.xtext.ide.server.ILanguageServerAccess)

Example 5 with XtextResource

use of org.eclipse.xtext.resource.XtextResource in project xtext-core by eclipse.

the class LanguageServerImpl method definition.

protected List<? extends Location> definition(final CancelIndicator cancelIndicator, final TextDocumentPositionParams params) {
    final URI uri = this._uriExtensions.toUri(params.getTextDocument().getUri());
    final IResourceServiceProvider resourceServiceProvider = this.languagesRegistry.getResourceServiceProvider(uri);
    DocumentSymbolService _get = null;
    if (resourceServiceProvider != null) {
        _get = resourceServiceProvider.<DocumentSymbolService>get(DocumentSymbolService.class);
    }
    final DocumentSymbolService documentSymbolService = _get;
    if ((documentSymbolService == null)) {
        return CollectionLiterals.<Location>emptyList();
    }
    final Function2<Document, XtextResource, List<? extends Location>> _function = (Document document, XtextResource resource) -> {
        return documentSymbolService.getDefinitions(document, resource, params, this.resourceAccess, cancelIndicator);
    };
    return this.workspaceManager.<List<? extends Location>>doRead(uri, _function);
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) DocumentSymbolService(org.eclipse.xtext.ide.server.symbol.DocumentSymbolService) XtextResource(org.eclipse.xtext.resource.XtextResource) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) Location(org.eclipse.lsp4j.Location)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)627 Test (org.junit.Test)367 Resource (org.eclipse.emf.ecore.resource.Resource)107 EObject (org.eclipse.emf.ecore.EObject)99 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)67 StringInputStream (org.eclipse.xtext.util.StringInputStream)67 URI (org.eclipse.emf.common.util.URI)62 Diagnostic (org.eclipse.emf.common.util.Diagnostic)55 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)55 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)46 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)40 Grammar (org.eclipse.xtext.Grammar)32 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)31 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)30 IFile (org.eclipse.core.resources.IFile)29 Issue (org.eclipse.xtext.validation.Issue)29 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)28 List (java.util.List)26 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)26 INode (org.eclipse.xtext.nodemodel.INode)23