Search in sources :

Example 11 with Type

use of org.eclipse.xtext.linking.lazy.lazyLinking.Type in project xtext-core by eclipse.

the class BasicLazyLinkingTest method testLazyMultiRefDuplicates.

@Test
public void testLazyMultiRefDuplicates() throws Exception {
    XtextResource resource = getResource(new StringInputStream("type A {} type B { A B A a; }"));
    Model m = (Model) resource.getContents().get(0);
    Type t1 = m.getTypes().get(0);
    Type t2 = m.getTypes().get(1);
    Property property = t2.getProperties().get(0);
    EList<Type> types = property.getType();
    assertEquals(t1, types.get(0));
    assertEquals(t2, types.get(1));
    assertEquals(t1, types.get(2));
    assertEquals(t1, types.get(0));
    assertEquals(t2, types.get(1));
    assertEquals(t1, types.get(2));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) XtextResource(org.eclipse.xtext.resource.XtextResource) UnresolvedProxyProperty(org.eclipse.xtext.linking.lazy.lazyLinking.UnresolvedProxyProperty) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Example 12 with Type

use of org.eclipse.xtext.linking.lazy.lazyLinking.Type in project xtext-core by eclipse.

the class BasicLazyLinkingTest method testReferenceWithOpposite.

// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486
// and https://bugs.eclipse.org/bugs/show_bug.cgi?id=303441
@SuppressWarnings("unchecked")
@Test
public void testReferenceWithOpposite() throws Exception {
    XtextResource resource = getResourceAndExpect(new StringInputStream("type foo {} type bar extends foo {}"), 1);
    Model model = (Model) resource.getContents().get(0);
    Type typeFoo = model.getTypes().get(0);
    Type typeBar = model.getTypes().get(1);
    InternalEObject proxy = (InternalEObject) typeBar.eGet(LazyLinkingPackage.Literals.TYPE__EXTENDS, false);
    assertTrue(proxy.eIsProxy());
    assertEquals(typeFoo, typeBar.getExtends());
    List<Type> fooSubtypes = (List<Type>) typeFoo.eGet(LazyLinkingPackage.Literals.TYPE__SUBTYPES, false);
    // the opposite is not automatically set (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=282486)
    assertEquals(0, fooSubtypes.size());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) XtextResource(org.eclipse.xtext.resource.XtextResource) EList(org.eclipse.emf.common.util.EList) List(java.util.List) InternalEList(org.eclipse.emf.ecore.util.InternalEList) InternalEObject(org.eclipse.emf.ecore.InternalEObject) Test(org.junit.Test)

Example 13 with Type

use of org.eclipse.xtext.linking.lazy.lazyLinking.Type in project xtext-core by eclipse.

the class BasicLazyLinkingTest method testBug281775_01.

@Test
public void testBug281775_01() throws Exception {
    String model = "type A {\n" + "  A B a;\n" + "}\n" + "type B {\n" + "  B A b;\n" + "}";
    XtextResource resource = getResource(new StringInputStream(model));
    Model m = (Model) resource.getContents().get(0);
    Type t1 = m.getTypes().get(0);
    assertEquals("A", t1.getName());
    Type t2 = m.getTypes().get(1);
    assertEquals("B", t2.getName());
    Property propA = t1.getProperties().get(0);
    assertEquals(2, propA.getType().size());
    assertEquals(t1, propA.getType().get(0));
    assertEquals(t2, propA.getType().get(1));
    Property propB = t2.getProperties().get(0);
    assertEquals(2, propB.getType().size());
    assertEquals(t2, propB.getType().get(0));
    assertEquals(t1, propB.getType().get(1));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) XtextResource(org.eclipse.xtext.resource.XtextResource) UnresolvedProxyProperty(org.eclipse.xtext.linking.lazy.lazyLinking.UnresolvedProxyProperty) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Example 14 with Type

use of org.eclipse.xtext.linking.lazy.lazyLinking.Type in project xtext-core by eclipse.

the class LazyLinkingResourceTest method testResolveLazyCrossReferences_02.

@Test
public void testResolveLazyCrossReferences_02() throws Exception {
    with(lazyLinkingTestLangaugeSetup());
    ResourceSetImpl rs = new ResourceSetImpl();
    final Resource res1 = rs.createResource(URI.createURI("file1.lazylinkingtestlanguage"));
    Resource res2 = rs.createResource(URI.createURI("file2.lazylinkingtestlanguage"));
    res1.load(new StringInputStream("type Foo { } type Baz { Foo Bar prop; } }"), null);
    res2.load(new StringInputStream("type Bar { }"), null);
    res1.eAdapters().add(notificationAlert);
    Model m = (Model) res1.getContents().get(0);
    Type t = m.getTypes().get(1);
    Property p = t.getProperties().get(0);
    final InternalEList<Type> types = (InternalEList<Type>) p.getType();
    assertEquals(2, types.size());
    for (Iterator<Type> it = types.basicIterator(); it.hasNext(); ) {
        final Type tt = it.next();
        assertTrue(tt.eIsProxy());
    }
    ((LazyLinkingResource) res1).resolveLazyCrossReferences(CancelIndicator.NullImpl);
    assertFalse(types.basicGet(0).eIsProxy());
    assertTrue(types.basicGet(1).eIsProxy());
    res1.eAdapters().remove(notificationAlert);
    EcoreUtil.resolveAll(res1);
    assertFalse(types.basicGet(0).eIsProxy());
    assertFalse(types.basicGet(1).eIsProxy());
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) Type(org.eclipse.xtext.linking.lazy.lazyLinking.Type) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) InternalEList(org.eclipse.emf.ecore.util.InternalEList) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Aggregations

Type (org.eclipse.xtext.linking.lazy.lazyLinking.Type)14 Model (org.eclipse.xtext.linking.lazy.lazyLinking.Model)11 Test (org.junit.Test)9 Property (org.eclipse.xtext.linking.lazy.lazyLinking.Property)6 UnresolvedProxyProperty (org.eclipse.xtext.linking.lazy.lazyLinking.UnresolvedProxyProperty)6 StringInputStream (org.eclipse.xtext.util.StringInputStream)6 StringConcatenationClient (org.eclipse.xtend2.lib.StringConcatenationClient)5 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 EList (org.eclipse.emf.common.util.EList)4 InternalEList (org.eclipse.emf.ecore.util.InternalEList)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 InMemoryFileSystemAccess (org.eclipse.xtext.generator.InMemoryFileSystemAccess)3 AbstractTraceRegion (org.eclipse.xtext.generator.trace.AbstractTraceRegion)3 ITraceRegionProvider (org.eclipse.xtext.generator.trace.ITraceRegionProvider)3 List (java.util.List)1 EPackage (org.eclipse.emf.ecore.EPackage)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Resource (org.eclipse.emf.ecore.resource.Resource)1