Search in sources :

Example 1 with EFactory

use of org.eclipse.emf.ecore.EFactory in project Palladio-Editors-Sirius by PalladioSimulator.

the class PCMServices method setParameterValue.

/**
 * Sets the value of the {@link EStructuralFeature} on the given {@link EObject} to the parsed
 * value literal.
 *
 * @param parameter
 *            the feature to set
 * @param owningEObject
 *            the object for which the feature will be set
 * @param valueLiteral
 *            the literal representing the new value
 */
public void setParameterValue(final EStructuralFeature parameter, final EObject owningEObject, final String valueLiteral) {
    final EClassifier eType = parameter.getEType();
    Object value = null;
    if (valueLiteral == null && eType != null) {
        value = parameter.isMany() ? null : eType.getDefaultValue();
    } else if (eType instanceof EDataType) {
        final EFactory factory = eType.getEPackage().getEFactoryInstance();
        final EDataType eDataType = (EDataType) eType;
        if (eDataType.isSerializable()) {
            try {
                value = factory.createFromString(eDataType, valueLiteral);
            } catch (final Throwable e) {
            // At development time, the real factory may not be
            // available. Just return null.
            // 
            }
        }
    }
    owningEObject.eSet(parameter, value);
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier) EObject(org.eclipse.emf.ecore.EObject)

Example 2 with EFactory

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

the class SimpleAttributeResolverTest method testGetUnknownValue.

@Test
public void testGetUnknownValue() {
    EFactory fact = factory.createEFactory();
    String name = nameResolver.getValue(fact);
    assertNull(name);
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) Test(org.junit.Test)

Example 3 with EFactory

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

the class SerializationUtilTest method testFillIdToEObjectMap.

@Test
public void testFillIdToEObjectMap() {
    EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
    EClass root = createEClass(pack, "Root");
    EClass someType = createEClass(pack, "SomeType");
    EReference ref1 = addEReference(root, someType, "ref1", false);
    EReference ref2 = addEReference(root, someType, "ref2", true);
    EFactory factory = pack.getEFactoryInstance();
    EObject rootObject = factory.create(root);
    EObject someTypeObject1 = factory.create(someType);
    EObject someTypeObject2 = factory.create(someType);
    rootObject.eSet(ref1, someTypeObject1);
    rootObject.eSet(ref2, someTypeObject2);
    List<EObject> map = new ArrayList<>();
    SerializationUtil.fillIdToEObjectMap(rootObject, map);
    assertTrue(map.contains(rootObject));
    assertTrue(map.contains(someTypeObject1));
    assertFalse(map.contains(someTypeObject2));
    assertEquals(2, map.size());
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EReference(org.eclipse.emf.ecore.EReference) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Aggregations

EFactory (org.eclipse.emf.ecore.EFactory)3 EObject (org.eclipse.emf.ecore.EObject)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 EDataType (org.eclipse.emf.ecore.EDataType)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EReference (org.eclipse.emf.ecore.EReference)1