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