Search in sources :

Example 61 with URI

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

Example 62 with URI

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) URI(org.eclipse.emf.common.util.URI) ISemanticRegionsFinder(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegionsFinder)

Example 63 with URI

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());
}
Also used : IEObjectSnapshot(org.eclipse.xtext.ide.serializer.hooks.IEObjectSnapshot) IResourceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IResourceSnapshot) URI(org.eclipse.emf.common.util.URI) IReferenceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot)

Example 64 with URI

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);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 65 with URI

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());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) URI(org.eclipse.emf.common.util.URI) Test(org.junit.Test)

Aggregations

URI (org.eclipse.emf.common.util.URI)305 Resource (org.eclipse.emf.ecore.resource.Resource)85 Test (org.junit.Test)79 EObject (org.eclipse.emf.ecore.EObject)55 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)33 XtextResource (org.eclipse.xtext.resource.XtextResource)32 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)26 BuildRequest (org.eclipse.xtext.build.BuildRequest)23 File (java.io.File)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)19 IOException (java.io.IOException)18 InternalEObject (org.eclipse.emf.ecore.InternalEObject)18 EPackage (org.eclipse.emf.ecore.EPackage)15 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13