Search in sources :

Example 1 with ResourceSetReferencingResourceSetImpl

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

the class ImportedNamespaceAwareLocalScopeProviderTest method testResourceSetReferencingResourceSet.

@Test
public void testResourceSetReferencingResourceSet() throws Exception {
    ResourceSetReferencingResourceSetImpl rs = new ResourceSetReferencingResourceSetImpl();
    Resource res = rs.createResource(URI.createURI("file2.indextestlanguage"));
    res.load(new StringInputStream("bar {" + "  entity Bar{}" + "}"), null);
    ResourceSetReferencingResourceSetImpl rs1 = new ResourceSetReferencingResourceSetImpl();
    rs1.getReferencedResourceSets().add(rs);
    final Resource res1 = rs1.createResource(URI.createURI("file1.indextestlanguage"));
    res1.load(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {}" + "}"), null);
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return res1.getAllContents();
        }
    };
    Iterator<Entity> iterator = Iterables.filter(allContents, Entity.class).iterator();
    Entity foo = iterator.next();
    assertEquals("Foo", foo.getName());
    IScope scope = scopeProvider.getScope(foo, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("Bar")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("bar.Bar")));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) ResourceSetReferencingResourceSetImpl(org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) Test(org.junit.Test)

Example 2 with ResourceSetReferencingResourceSetImpl

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

the class ImportedNamespaceAwareLocalScopeProviderTest method testResourceSetReferencingResourceSet2.

@Test
public void testResourceSetReferencingResourceSet2() throws Exception {
    ResourceSetReferencingResourceSetImpl rs = new ResourceSetReferencingResourceSetImpl();
    Resource res = rs.createResource(URI.createURI("file2.indextestlanguage"));
    res.load(new StringInputStream("bar {" + "  entity Bar{}" + "}"), null);
    ResourceSetReferencingResourceSetImpl rs1 = new ResourceSetReferencingResourceSetImpl();
    rs1.getReferencedResourceSets().add(rs);
    final Resource res1 = rs1.createResource(URI.createURI("file1.indextestlanguage"));
    res1.load(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {" + "  }" + "}"), null);
    ResourceSetReferencingResourceSetImpl rs2 = new ResourceSetReferencingResourceSetImpl();
    rs2.getReferencedResourceSets().add(rs1);
    final Resource res2 = rs2.createResource(URI.createURI("file2.indextestlanguage"));
    res2.load(new StringInputStream("baz {" + "  entity Baz{}" + "}"), null);
    Entity baz = getEntityByName(res2, "Baz");
    IScope scope = scopeProvider.getScope(baz, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("foo.Foo")));
    assertNull(scope.getSingleElement(nameConverter.toQualifiedName("bar.Bar")));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) ResourceSetReferencingResourceSetImpl(org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)2 Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)2 ResourceSetReferencingResourceSetImpl (org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 IScope (org.eclipse.xtext.scoping.IScope)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 Test (org.junit.Test)2 EObject (org.eclipse.emf.ecore.EObject)1