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