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);
}
Aggregations