use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class GrammarUtilGetReferenceTest method testGetReference_04.
@Test
public void testGetReference_04() throws Exception {
String grammarAsString = "grammar foo.bar with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: {SubModel1} model=[Model] | {SubModel2} model=[Model];";
Grammar grammar = (Grammar) getModel(grammarAsString);
AbstractRule ruleModel = grammar.getRules().get(0);
Alternatives alternatives = (Alternatives) ruleModel.getAlternatives();
Group group = (Group) alternatives.getElements().get(1);
Assignment assignment = (Assignment) group.getElements().get(1);
CrossReference crossRef = (CrossReference) assignment.getTerminal();
EReference reference = GrammarUtil.getReference(crossRef);
assertEquals("model", reference.getName());
assertEquals("Model", reference.getEContainingClass().getName());
}
use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class GrammarUtilGetReferenceTest method testGetReference_07.
@Test
public void testGetReference_07() throws Exception {
String grammarAsString = "grammar foo.bar with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: model1=[Model] & model2=[Model|STRING];";
Grammar grammar = (Grammar) getModel(grammarAsString);
AbstractRule ruleModel = grammar.getRules().get(0);
UnorderedGroup group = (UnorderedGroup) ruleModel.getAlternatives();
Assignment assignment = (Assignment) group.getElements().get(0);
CrossReference crossRef = (CrossReference) assignment.getTerminal();
EReference reference = GrammarUtil.getReference(crossRef);
assertEquals("model1", reference.getName());
assertEquals("Model", reference.getEContainingClass().getName());
}
use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class GrammarUtilGetReferenceTest method testGetReference_08.
@Test
public void testGetReference_08() throws Exception {
String grammarAsString = "grammar foo.bar with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: {SubModel} (model1=[Model] & model2=[Model|STRING]);";
Grammar grammar = (Grammar) getModel(grammarAsString);
AbstractRule ruleModel = grammar.getRules().get(0);
Group group = (Group) ruleModel.getAlternatives();
UnorderedGroup unorderedGroup = (UnorderedGroup) group.getElements().get(1);
Assignment assignment = (Assignment) unorderedGroup.getElements().get(1);
CrossReference crossRef = (CrossReference) assignment.getTerminal();
EReference reference = GrammarUtil.getReference(crossRef);
assertEquals("model2", reference.getName());
assertEquals("SubModel", reference.getEContainingClass().getName());
}
use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.
the class GrammarUtilGetReferenceTest method testGetReference_02.
@Test
public void testGetReference_02() throws Exception {
String grammarAsString = "grammar foo.bar with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Model: {SubModel} model=[Model];";
Grammar grammar = (Grammar) getModel(grammarAsString);
AbstractRule ruleModel = grammar.getRules().get(0);
Group group = (Group) ruleModel.getAlternatives();
Assignment assignment = (Assignment) group.getElements().get(1);
CrossReference crossRef = (CrossReference) assignment.getTerminal();
EReference reference = GrammarUtil.getReference(crossRef);
assertEquals("model", reference.getName());
assertEquals("SubModel", reference.getEContainingClass().getName());
}
use of org.eclipse.emf.ecore.EReference 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());
}
Aggregations