Search in sources :

Example 71 with EReference

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());
}
Also used : EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 72 with EReference

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());
}
Also used : EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 73 with EReference

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());
}
Also used : EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 74 with EReference

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());
}
Also used : EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 75 with EReference

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());
}
Also used : Assignment(org.eclipse.xtext.Assignment) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) CrossReference(org.eclipse.xtext.CrossReference) XtextResource(org.eclipse.xtext.resource.XtextResource) Main(org.eclipse.xtext.linking.langATestLanguage.Main) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10