Search in sources :

Example 81 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class EcoreUtil2 method getEReferenceFromExternalForm.

/**
 * looks up the EReference in the passed registry, given the external form. if registry == null this
 */
public static EReference getEReferenceFromExternalForm(EPackage.Registry registry, String externalForm) {
    if (externalForm == null)
        return null;
    List<String> split = Strings.split(externalForm, delim);
    if (split.size() != 3) {
        URI uri = URI.createURI(externalForm);
        URI packURI = uri.trimFragment();
        EPackage ePackage = registry.getEPackage(packURI.toString());
        if (ePackage == null)
            return null;
        EReference result = (EReference) ePackage.eResource().getEObject(uri.fragment());
        return result;
    }
    EPackage ePackage = registry.getEPackage(split.get(0));
    if (ePackage == null)
        return null;
    EClass clazz = (EClass) ePackage.getEClassifier(split.get(1));
    if (clazz == null)
        return null;
    return (EReference) clazz.getEStructuralFeature(Integer.valueOf(split.get(2)));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) URI(org.eclipse.emf.common.util.URI) EReference(org.eclipse.emf.ecore.EReference) EPackage(org.eclipse.emf.ecore.EPackage)

Example 82 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class EClassInfoTest method testChangeable.

public void testChangeable() {
    EcorePackage pack = EcorePackage.eINSTANCE;
    EClass eClass = pack.getEClass();
    EClassInfo objectUnderTest = new EClassifierInfo.EClassInfo(eClass, false, Collections.<String>emptySet(), null);
    EcoreFactory fac = EcoreFactory.eINSTANCE;
    EReference reference = fac.createEReference();
    reference.setName("newReference");
    reference.setEType(eClass);
    reference.setChangeable(true);
    reference.setContainment(true);
    eClass.getEStructuralFeatures().add(reference);
    assertEquals(true, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
    reference.setChangeable(false);
    assertEquals(false, objectUnderTest.containsCompatibleFeature("newReference", false, true, eClass, new StringBuilder()));
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) EcorePackage(org.eclipse.emf.ecore.EcorePackage) EReference(org.eclipse.emf.ecore.EReference)

Example 83 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method addReference.

private EReference addReference(EClassInfo eClass, EClassInfo ref, String name) {
    EReference feature = EcoreFactory.eINSTANCE.createEReference();
    feature.setName(name);
    feature.setEType(ref.getEClassifier());
    eClass.getEClass().getEStructuralFeatures().add(feature);
    return feature;
}
Also used : EReference(org.eclipse.emf.ecore.EReference)

Example 84 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class TypeHierarchyHelperTest method testConfigurationOfLiftedReference.

@Test
public void testConfigurationOfLiftedReference() throws Exception {
    EClassInfo a = addClass("a");
    EClassInfo b = addClass("b");
    EClassInfo c = addClass("c");
    b.addSupertype(a);
    c.addSupertype(a);
    EReference refB = addReference(b, a, "ref");
    refB.setContainment(true);
    EReference refC = addReference(c, a, "ref");
    refC.setContainment(true);
    assertEquals(0, a.getEClass().getEStructuralFeatures().size());
    assertEquals(1, b.getEClass().getEStructuralFeatures().size());
    assertEquals(1, c.getEClass().getEStructuralFeatures().size());
    liftUpFeatures();
    assertEquals(1, a.getEClass().getEStructuralFeatures().size());
    assertEquals(0, b.getEClass().getEStructuralFeatures().size());
    assertEquals(0, c.getEClass().getEStructuralFeatures().size());
    EReference refA = (EReference) a.getEClass().getEStructuralFeatures().get(0);
    assertTrue(refA.isContainment());
}
Also used : EClassInfo(org.eclipse.xtext.xtext.ecoreInference.EClassifierInfo.EClassInfo) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 85 with EReference

use of org.eclipse.emf.ecore.EReference in project xtext-core by eclipse.

the class GrammarUtilTest method testGetReference.

@Test
public void testGetReference() throws Exception {
    this.with(LangATestLanguageStandaloneSetup.class);
    XtextResource resource = this.getResourceFromStringAndExpect("type A extends B", 1);
    Assignment asExtends = this.<LangATestLanguageGrammarAccess>get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
    AbstractElement _terminal = asExtends.getTerminal();
    CrossReference xref = ((CrossReference) _terminal);
    EObject _model = this.getModel(resource);
    Main model = ((Main) _model);
    EObject typeA = model.getTypes().get(0);
    EReference ref = GrammarUtil.getReference(xref, typeA.eClass());
    Assert.assertNotNull(ref);
    Assert.assertEquals("extends", ref.getName());
    Assert.assertFalse(ref.isMany());
    Assert.assertEquals(typeA.eClass(), ref.getEReferenceType());
}
Also used : Assignment(org.eclipse.xtext.Assignment) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) LangATestLanguageGrammarAccess(org.eclipse.xtext.linking.services.LangATestLanguageGrammarAccess) 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