Search in sources :

Example 11 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testRelativeContext.

@Test
public void testRelativeContext() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("stuff { " + "  baz { " + "    datatype String " + "  } " + "  entity Person {}" + "}"), URI.createURI("relative.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Entity entity = filter(allContents, Entity.class).iterator().next();
    IScope scope = scopeProvider.getScope(entity, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("baz.String")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("stuff.baz.String")));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 12 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testUnambiguousImportAreShadowed_02.

@Test
public void testUnambiguousImportAreShadowed_02() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("foo { " + "  entity Foo {}" + "  entity Bar {}" + "}" + "bar {" + "  entity Foo {}" + "}" + "baz {" + "  import foo.Foo" + "  import bar.Foo" + "  entity Baz{}" + "}"), URI.createURI("withoutwildcard.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Entity foo = find(Iterables.filter(allContents, Entity.class), new Predicate<Entity>() {

        @Override
        public boolean apply(Entity input) {
            return input.getName().equals("Baz");
        }
    });
    IScope scope = scopeProvider.getScope(foo, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNull(scope.getSingleElement(nameConverter.toQualifiedName("Bar")));
    assertNull(scope.getSingleElement(nameConverter.toQualifiedName("Foo")));
    ArrayList<IEObjectDescription> list = newArrayList(scope.getAllElements());
    assertEquals(5, list.size());
    assertFalse(any(list, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            return input.getName().equals(QualifiedName.create("Foo"));
        }
    }));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 13 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testImportsWithoutWildcard.

@Test
public void testImportsWithoutWildcard() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {" + "  }" + "}" + "bar {" + "  entity Bar{}" + "}"), URI.createURI("withoutwildcard.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.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")));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 14 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testDuplicateImportsAreIgnored.

@Test
public void testDuplicateImportsAreIgnored() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("foo { " + "  entity Foo {}" + "  entity Bar {}" + "}" + "bar {" + "  entity Foo {}" + "}" + "baz {" + "  import foo.*" + "  import foo.*" + "  entity Baz{}" + "}"), URI.createURI("withoutwildcard.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Entity foo = find(Iterables.filter(allContents, Entity.class), new Predicate<Entity>() {

        @Override
        public boolean apply(Entity input) {
            return input.getName().equals("Baz");
        }
    });
    IScope scope = scopeProvider.getScope(foo, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("Bar")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("Foo")));
    ArrayList<IEObjectDescription> list = newArrayList(scope.getAllElements());
    assertEquals(7, list.size());
    assertTrue(any(list, new Predicate<IEObjectDescription>() {

        @Override
        public boolean apply(IEObjectDescription input) {
            return input.getName().equals(QualifiedName.create("Foo"));
        }
    }));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 15 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity 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)

Aggregations

Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)19 Test (org.junit.Test)16 EObject (org.eclipse.emf.ecore.EObject)13 StringInputStream (org.eclipse.xtext.util.StringInputStream)12 XtextResource (org.eclipse.xtext.resource.XtextResource)10 IScope (org.eclipse.xtext.scoping.IScope)10 Predicate (com.google.common.base.Predicate)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 List (java.util.List)4 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)4 IndexTestLanguageStandaloneSetup (org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 ResourceSetReferencingResourceSetImpl (org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl)3 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Datatype (org.eclipse.xtext.index.indexTestLanguage.Datatype)2 EPackage (org.eclipse.emf.ecore.EPackage)1 Issues (org.eclipse.emf.mwe.core.issues.Issues)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1