Search in sources :

Example 96 with Resource

use of org.eclipse.emf.ecore.resource.Resource 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 97 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.

the class WorkspaceManager method doRead.

public <T extends Object> T doRead(final URI uri, final Function2<? super Document, ? super XtextResource, ? extends T> work) {
    final URI resourceURI = uri.trimFragment();
    final ProjectManager projectMnr = this.getProjectManager(resourceURI);
    Resource _resource = null;
    if (projectMnr != null) {
        _resource = projectMnr.getResource(resourceURI);
    }
    final XtextResource resource = ((XtextResource) _resource);
    if ((resource == null)) {
        return work.apply(null, null);
    }
    Document doc = this.getDocument(resource);
    Resource _resource_1 = projectMnr.getResource(resourceURI);
    return work.apply(doc, ((XtextResource) _resource_1));
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document) URI(org.eclipse.emf.common.util.URI) ProjectManager(org.eclipse.xtext.ide.server.ProjectManager)

Example 98 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.

the class ChangeSerializer method applyModifications.

@Override
public void applyModifications(IAcceptor<IEmfResourceChange> changeAcceptor) {
    monitor.setTaskName("Preparing Text Changes...");
    Set<Resource> resources = Sets.newLinkedHashSet();
    for (Pair<Notifier, IModification<? extends Notifier>> p : modifications) {
        Notifier context = p.getFirst();
        if (context instanceof EObject)
            resources.add(((EObject) context).eResource());
        else if (context instanceof Resource)
            resources.add((Resource) context);
        else if (context instanceof ResourceSet) {
            throw new IllegalStateException("Not supported");
        }
    }
    for (Resource res : resources) {
        // TODO: use the exact context
        beginRecordChanges(res);
    }
    checkCanceled();
    for (Pair<Notifier, IModification<? extends Notifier>> entry : modifications) {
        apply(entry.getFirst(), entry.getSecond());
    }
    checkCanceled();
    endRecordChanges(changeAcceptor);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) RelatedResource(org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Notifier(org.eclipse.emf.common.notify.Notifier)

Example 99 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.

the class ChangeTreeProvider method createChangeTree.

public ResourceSetRecording createChangeTree(ResourceSet resourceSet, Collection<IResourceSnapshot> snapshots, ChangeDescription desc) {
    ResourceSetRecording rs = new ResourceSetRecording(resourceSet);
    Map<Resource, ResourceRecording> result = Maps.newLinkedHashMap();
    Map<EObject, EObjectChange> objectChanges = Maps.newLinkedHashMap();
    for (IResourceSnapshot snap : snapshots) {
        Resource resource = snap.getResource();
        ResourceRecording recording = new ResourceRecording(rs, resource);
        recording.snapshot = snap;
        result.put(resource, recording);
    }
    for (ResourceChange rc : desc.getResourceChanges()) {
        Resource resource = rc.getResource();
        ResourceRecording recording = result.get(resource);
        if (recording == null) {
            recording = new ResourceRecording(rs, resource);
            result.put(resource, recording);
        }
        recording.resourceChange = rc;
    }
    for (Entry<EObject, EList<FeatureChange>> e : desc.getObjectChanges().entrySet()) {
        EList<FeatureChange> featureChange = e.getValue();
        EObject object = e.getKey();
        objectChanges.put(object, new EObjectChange(object, featureChange));
    }
    for (EObjectChange change : Lists.newArrayList(objectChanges.values())) {
        EObjectChange current = change;
        while (true) {
            EObject container = current.eObject.eContainer();
            if (container != null) {
                EObjectChange next = objectChanges.get(container);
                if (next == null) {
                    next = new EObjectChange(container);
                    next.children.add(current);
                    objectChanges.put(container, next);
                } else {
                    if (!next.children.add(current)) {
                        break;
                    }
                }
                current = next;
            } else {
                Resource resource = current.eObject.eResource();
                ResourceRecording resourceChange = result.get(resource);
                if (resourceChange == null) {
                    resourceChange = new ResourceRecording(rs, resource);
                    result.put(resource, resourceChange);
                // TODO: check that only recorded resources contain
                // modification
                }
                resourceChange.roots.add(current);
                break;
            }
        }
    }
    rs.resources = ImmutableList.copyOf(result.values());
    rs.objects = ImmutableMap.copyOf(objectChanges);
    return rs;
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) FeatureChange(org.eclipse.emf.ecore.change.FeatureChange) EList(org.eclipse.emf.common.util.EList) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) EObject(org.eclipse.emf.ecore.EObject) ResourceChange(org.eclipse.emf.ecore.change.ResourceChange)

Example 100 with Resource

use of org.eclipse.emf.ecore.resource.Resource in project xtext-core by eclipse.

the class RecordingXtextResourceUpdater method applyChange.

@Override
public void applyChange(Deltas deltas, IAcceptor<IEmfResourceChange> changeAcceptor) {
    Resource resource = snapshot.getResource();
    ResourceSet rs = resource.getResourceSet();
    ReferenceUpdaterContext ctx = new ReferenceUpdaterContext(deltas, document);
    if (serializer.isUpdateCrossReferences()) {
        referenceUpdater.update(ctx);
        for (Runnable run : ctx.getModifications()) {
            run.run();
        }
    }
    ChangeDescription recording = recorder.endRecording();
    if (recording != null) {
        List<IResourceSnapshot> snapshots = Collections.singletonList(snapshot);
        ResourceSetRecording tree = changeTreeProvider.createChangeTree(rs, snapshots, recording);
        ResourceRecording recordedResource = tree.getRecordedResource(resource);
        partialSerializer.serializeChanges(recordedResource, document);
    }
    List<IUpdatableReference> updatableReferences = ctx.getUpdatableReferences();
    for (IUpdatableReference upd : updatableReferences) {
        referenceUpdater.updateReference(document, upd);
    }
    ITextRegionAccessDiff rewritten = document.create();
    List<ITextReplacement> rep = formatter.format(rewritten);
    URI oldUri = snapshot.getURI();
    TextDocumentChange change = new TextDocumentChange(rewritten, oldUri, rep);
    changeAcceptor.accept(change);
}
Also used : ResourceRecording(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceRecording) ITextRegionAccessDiff(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccessDiff) IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) ResourceSetRecording(org.eclipse.xtext.ide.serializer.impl.ChangeTreeProvider.ResourceSetRecording) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) ChangeDescription(org.eclipse.emf.ecore.change.ChangeDescription)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)448 Test (org.junit.Test)210 XtextResource (org.eclipse.xtext.resource.XtextResource)157 EObject (org.eclipse.emf.ecore.EObject)109 URI (org.eclipse.emf.common.util.URI)85 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)76 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)71 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)66 StringInputStream (org.eclipse.xtext.util.StringInputStream)50 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)45 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)36 IOException (java.io.IOException)26 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)24 List (java.util.List)23 EClass (org.eclipse.emf.ecore.EClass)23 EPackage (org.eclipse.emf.ecore.EPackage)23 InternalEObject (org.eclipse.emf.ecore.InternalEObject)23 DerivedStateAwareResource (org.eclipse.xtext.resource.DerivedStateAwareResource)21 ArrayList (java.util.ArrayList)19 IFile (org.eclipse.core.resources.IFile)18