use of org.eclipse.emf.common.util.URI 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);
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class ReferenceUpdater method getRegion.
protected ISemanticRegion getRegion(ITextRegionAccess access, IReferenceSnapshot ref) {
XtextResource resource = access.getResource();
URI objectUri = ref.getSourceEObjectUri();
if (!resource.getURI().equals(objectUri.trimFragment())) {
return null;
}
EObject object = resource.getEObject(objectUri.fragment());
if (object == null) {
return null;
}
ISemanticRegionsFinder finder = access.getExtensions().regionFor(object);
int index = ref.getIndexInList();
if (index < 0) {
return finder.feature(ref.getEReference());
} else {
List<ISemanticRegion> list = finder.features(ref.getEReference());
if (list != null && index < list.size()) {
return list.get(index);
}
}
return null;
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class RelatedResourcesProvider method getRelatedResources.
public List<RelatedResource> getRelatedResources(Collection<IResourceSnapshot> snapshots) {
Map<URI, RelatedResource> result = Maps.newLinkedHashMap();
for (IResourceSnapshot res : snapshots) {
for (IEObjectSnapshot obj : res.getObjects().values()) {
for (IReferenceSnapshot ref : obj.getIncomingReferences()) {
URI source = ref.getSourceEObjectUri().trimFragment();
RelatedResource related = result.get(source);
if (related == null) {
related = new RelatedResource(source);
result.put(source, related);
}
related.outgoingReferences.add(ref);
}
}
}
Set<URI> added = Sets.newHashSet();
Set<URI> removed = Sets.newHashSet();
for (IResourceSnapshot res : snapshots) {
URI oldUri = res.getURI();
URI newUri = res.getResource().getURI();
if (!oldUri.equals(newUri)) {
added.add(newUri);
removed.add(oldUri);
} else {
result.remove(newUri);
}
}
removed.removeAll(added);
for (URI uri : removed) {
result.remove(uri);
}
return ImmutableList.copyOf(result.values());
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class AbstractHierarchyBuilder method getDescription.
protected IEObjectDescription getDescription(final URI objectURI) {
final IResourceDescription resourceDescription = this.getIndexData().getResourceDescription(objectURI.trimFragment());
if ((resourceDescription == null)) {
return null;
}
final Function1<IEObjectDescription, Boolean> _function = (IEObjectDescription it) -> {
URI _eObjectURI = it.getEObjectURI();
return Boolean.valueOf(Objects.equal(_eObjectURI, objectURI));
};
return IterableExtensions.<IEObjectDescription>findFirst(resourceDescription.getExportedObjects(), _function);
}
use of org.eclipse.emf.common.util.URI in project xtext-core by eclipse.
the class MultiProjectTest method testCrossProjectLink.
@Test
public void testCrossProjectLink() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("type Foo {");
_builder.newLine();
_builder.append(" ");
_builder.append("Bar bar");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final URI foo = this.createFile(this.project0, "Foo.testlang", _builder);
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("type Bar {");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
final URI bar = this.createFile(this.project1, "Bar.testlang", _builder_1);
this.workspaceManager.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(foo, bar)), CollectionLiterals.<URI>emptyList(), CancelIndicator.NullImpl);
Assert.assertEquals(2, this.diagnostics.size());
Assert.assertEquals(1, this.diagnostics.get(foo).size());
Assert.assertEquals(Diagnostic.LINKING_DIAGNOSTIC, IterableExtensions.<Issue>head(this.diagnostics.get(foo)).getCode());
Assert.assertTrue(this.diagnostics.get(bar).isEmpty());
this.diagnostics.clear();
List<String> _dependencies = this.workspaceManager.getProjectManager(this.project0.getName()).getProjectDescription().getDependencies();
String _name = this.project1.getName();
_dependencies.add(_name);
this.workspaceManager.doBuild(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(foo, bar)), CollectionLiterals.<URI>emptyList(), CancelIndicator.NullImpl);
Assert.assertEquals(2, this.diagnostics.size());
Assert.assertTrue(this.diagnostics.get(foo).isEmpty());
Assert.assertTrue(this.diagnostics.get(bar).isEmpty());
}
Aggregations