Search in sources :

Example 16 with Entity

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

Example 17 with Entity

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

the class ImportedNamespaceAwareLocalScopeProviderTest method testMultipleFiles.

@Test
public void testMultipleFiles() throws Exception {
    ResourceSetImpl rs = new ResourceSetImpl();
    final Resource res1 = rs.createResource(URI.createURI("file1.indextestlanguage"));
    Resource res2 = rs.createResource(URI.createURI("file2.indextestlanguage"));
    res1.load(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {" + "  }" + "}"), null);
    res2.load(new StringInputStream("bar {" + "  entity Bar{}" + "}"), 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")));
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) ResourceSetReferencingResourceSetImpl(org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) 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 18 with Entity

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

the class LazyLinkingResourceTest method testResolveLazyCrossReferences.

@Test
public void testResolveLazyCrossReferences() throws Exception {
    with(testLangaugeSetup());
    ResourceSetImpl rs = new ResourceSetImpl();
    final Resource res1 = rs.createResource(URI.createURI("file1.indextestlanguage"));
    Resource res2 = rs.createResource(URI.createURI("file2.indextestlanguage"));
    res1.load(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {" + "    Bar a1" + "    Foo a2" + "  }" + "}"), null);
    res2.load(new StringInputStream("bar {" + "  entity Bar{}" + "}"), null);
    res1.eAdapters().add(notificationAlert);
    Entity e = (Entity) find(EcoreUtil2.eAllContents(res1.getContents().get(0)), new Predicate<EObject>() {

        @Override
        public boolean apply(EObject input) {
            return input instanceof Entity;
        }
    });
    assertTrue(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertTrue(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    ((LazyLinkingResource) res1).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertTrue(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertFalse(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    res1.eAdapters().remove(notificationAlert);
    EcoreUtil.resolveAll(res1);
    assertFalse(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertFalse(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Resource(org.eclipse.emf.ecore.resource.Resource) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Example 19 with Entity

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

the class LazyLinkingResourceTest method testResolveLazyCrossReferences_01.

@Test
public void testResolveLazyCrossReferences_01() throws Exception {
    with(testLangaugeSetup());
    ResourceSetImpl rs = new ResourceSetImpl();
    final Resource res1 = rs.createResource(URI.createURI("file1.indextestlanguage"));
    Resource res2 = rs.createResource(URI.createURI("file2.indextestlanguage"));
    res1.load(new StringInputStream("foo { " + "  import bar.Bar" + "  entity Foo {" + "    Bar a1" + "    Foo a2" + "    Unresolvable a2" + "  }" + "}"), null);
    res2.load(new StringInputStream("bar {" + "  entity Bar{}" + "}"), null);
    res1.eAdapters().add(notificationAlert);
    Entity e = (Entity) find(EcoreUtil2.eAllContents(res1.getContents().get(0)), new Predicate<EObject>() {

        @Override
        public boolean apply(EObject input) {
            return input instanceof Entity;
        }
    });
    assertEquals(0, res1.getErrors().size());
    assertTrue(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertTrue(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertTrue(((EObject) e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    ((LazyLinkingResource) res1).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertEquals(1, res1.getErrors().size());
    assertTrue(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertFalse(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertTrue(((EObject) e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    res1.eAdapters().remove(notificationAlert);
    EcoreUtil.resolveAll(res1);
    assertEquals(1, res1.getErrors().size());
    assertFalse(((EObject) e.getProperties().get(0).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertFalse(((EObject) e.getProperties().get(1).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
    assertTrue(((EObject) e.getProperties().get(2).eGet(IndexTestLanguagePackage.Literals.PROPERTY__TYPE, false)).eIsProxy());
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) StringInputStream(org.eclipse.xtext.util.StringInputStream) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Resource(org.eclipse.emf.ecore.resource.Resource) Predicate(com.google.common.base.Predicate) 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