Search in sources :

Example 1 with LazyLinkingTestLanguageGrammarAccess

use of org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess in project xtext-core by eclipse.

the class CrossRefTest method testGetMultiValuedLinkText.

@Test
public void testGetMultiValuedLinkText() throws Exception {
    with(LazyLinkingTestLanguageStandaloneSetup.class);
    crossRefSerializer = get(ICrossReferenceSerializer.class);
    final LazyLinkingTestLanguageGrammarAccess g = (LazyLinkingTestLanguageGrammarAccess) get(IGrammarAccess.class);
    final XtextResource r = CrossRefTest.this.getResourceFromStringAndExpect("type TypeA {} type TypeB { TypeA TypeC TypeB p1; }", 1);
    LogCapture log = LoggingTester.captureLogging(Level.ERROR, LazyLinkingResource.class, new Runnable() {

        @Override
        public void run() {
            Model model = (Model) r.getContents().get(0);
            assertEquals(2, model.getTypes().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type type = model.getTypes().get(1);
            assertEquals("TypeB", type.getName());
            assertEquals(1, type.getProperties().size());
            Property prop = type.getProperties().get(0);
            assertEquals("p1", prop.getName());
            assertEquals(3, prop.getType().size());
            org.eclipse.xtext.linking.lazy.lazyLinking.Type propType = prop.getType().get(0);
            assertFalse(propType.eIsProxy());
            String linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeA", linkText);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            INode node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, node);
            assertEquals("TypeC", linkText);
            propType = prop.getType().get(2);
            assertFalse(propType.eIsProxy());
            node = getCrossReferenceNode(prop, GrammarUtil.getReference(g.getPropertyAccess().getTypeTypeCrossReference_0_0()), propType);
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertEquals("TypeB", linkText);
            Adapter adapter = (Adapter) NodeModelUtils.getNode(prop);
            prop.eAdapters().remove(adapter);
            propType = prop.getType().get(1);
            assertTrue(propType.eIsProxy());
            linkText = crossRefSerializer.serializeCrossRef(prop, g.getPropertyAccess().getTypeTypeCrossReference_0_0(), propType, null);
            assertNull(linkText);
        }
    });
    log.assertNumberOfLogEntries(2);
}
Also used : ICrossReferenceSerializer(org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.ICrossReferenceSerializer) INode(org.eclipse.xtext.nodemodel.INode) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) XtextResource(org.eclipse.xtext.resource.XtextResource) Adapter(org.eclipse.emf.common.notify.Adapter) Type(org.eclipse.xtext.linking.langATestLanguage.Type) Model(org.eclipse.xtext.linking.lazy.lazyLinking.Model) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) LazyLinkingTestLanguageGrammarAccess(org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess) Property(org.eclipse.xtext.linking.lazy.lazyLinking.Property) Test(org.junit.Test)

Aggregations

Adapter (org.eclipse.emf.common.notify.Adapter)1 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 Type (org.eclipse.xtext.linking.langATestLanguage.Type)1 Model (org.eclipse.xtext.linking.lazy.lazyLinking.Model)1 Property (org.eclipse.xtext.linking.lazy.lazyLinking.Property)1 LazyLinkingTestLanguageGrammarAccess (org.eclipse.xtext.linking.lazy.services.LazyLinkingTestLanguageGrammarAccess)1 INode (org.eclipse.xtext.nodemodel.INode)1 ICrossReferenceSerializer (org.eclipse.xtext.parsetree.reconstr.ITokenSerializer.ICrossReferenceSerializer)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 LogCapture (org.eclipse.xtext.testing.logging.LoggingTester.LogCapture)1 Test (org.junit.Test)1