use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class InjectableValidatorTest method testWrongResource.
@Test
public void testWrongResource() throws Exception {
Main main = LangATestLanguageFactory.eINSTANCE.createMain();
XMIResource xmiResource = new XMIResourceImpl();
xmiResource.getContents().add(main);
assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), null));
assertTrue(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
assertFalse(languageSpecificValidator.validate(main, new BasicDiagnostic(), context));
context.clear();
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), null));
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
context.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, xtextResource.getLanguageName());
assertFalse(languageAgnosticValidator.validate(main, new BasicDiagnostic(), context));
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class CrossRefTest method testGetSingleValuedLinkText.
@Test
public void testGetSingleValuedLinkText() throws Exception {
XtextResource r = getResourceFromStringAndExpect("type TypeA extends ^extends type ^extends extends ^type", 1);
Main model = (Main) r.getContents().get(0);
assertEquals(2, model.getTypes().size());
Type type = model.getTypes().get(0);
assertEquals("TypeA", type.getName());
Type superType = type.getExtends();
assertEquals("extends", superType.getName());
String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
assertEquals("^extends", linkText);
type = superType;
superType = type.getExtends();
assertTrue(superType.eIsProxy());
INode node = getCrossReferenceNode(type, GrammarUtil.getReference(grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0()), superType);
linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, node);
assertEquals("^type", linkText);
Adapter adapter = (Adapter) NodeModelUtils.getNode(type);
type.eAdapters().remove(adapter);
linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
assertNull(linkText);
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class CrossRefTest method testOutOfSyncNodeModel.
/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=287813 */
@Test
public void testOutOfSyncNodeModel() throws Exception {
XtextResource r = getResourceFromString("type TypeA extends ^TypeB type TypeB ");
Main model = (Main) r.getContents().get(0);
Type type = model.getTypes().get(0);
Type superType = type.getExtends();
superType.setName("TypeC");
String linkText = crossRefSerializer.serializeCrossRef(type, grammar.getTypeAccess().getExtendsTypeCrossReference_2_1_0(), superType, null);
assertEquals("TypeC", linkText);
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class CrossRefTest method testGetLinkedObjects.
@Test
public void testGetLinkedObjects() throws Exception {
XtextResource r = getResourceFromString("type TypeA extends TypeB type TypeB extends TypeA type AnotherType extends TypeA");
Main model = (Main) r.getParseResult().getRootASTElement();
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(r.getParseResult().getRootNode(), 6);
assertEquals(3, model.getTypes().size());
EObject context = model.getTypes().get(0);
Assignment asExtends = get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
CrossReference xref = (CrossReference) asExtends.getTerminal();
EReference ref = GrammarUtil.getReference(xref, context.eClass());
assertEquals(1, getLinkingService().getLinkedObjects(context, ref, leaf).size());
}
use of org.eclipse.xtext.linking.langATestLanguage.Main in project xtext-core by eclipse.
the class CrossRefTest method testCrossReferenceValueConverter.
/* see https://bugs.eclipse.org/bugs/show_bug.cgi?id=298506 */
@Test
public void testCrossReferenceValueConverter() throws Exception {
Resource r = get(XtextResourceSet.class).createResource(URI.createURI("test." + getCurrentFileExtension()));
Main main = LangATestLanguageFactory.eINSTANCE.createMain();
Type ele = LangATestLanguageFactory.eINSTANCE.createType();
r.getContents().add(main);
main.getTypes().add(ele);
ele.setName("type");
ele.setExtends(ele);
assertEquals("type ^type extends ^type", getSerializer().serialize(main));
}
Aggregations