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);
}
}
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));
}
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);
}
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;
}
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);
}
Aggregations