org.eclipse.epsilon.emc.emf.EmfPropertySetter Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2008 The University of York.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* Dimitrios Kolovos - initial API and implementation
******************************************************************************/
package org.eclipse.epsilon.emc.emf;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.epsilon.common.util.CollectionUtil;
import org.eclipse.epsilon.eol.exceptions.EolIllegalPropertyAssignmentException;
import org.eclipse.epsilon.eol.exceptions.EolIllegalPropertyException;
import org.eclipse.epsilon.eol.exceptions.EolRuntimeException;
import org.eclipse.epsilon.eol.execute.introspection.AbstractPropertySetter;
import org.eclipse.epsilon.eol.execute.introspection.IReflectivePropertySetter;
public class EmfPropertySetter extends AbstractPropertySetter implements IReflectivePropertySetter {
public Object coerce(Object value) throws EolIllegalPropertyException {
if (getEStructuralFeature().isMany() && !(value instanceof Collection)) {
return CollectionUtil.asList(value);
}
return value;
}
public boolean conforms(Object value) throws EolIllegalPropertyException {
if (propertyIsFixed())
return false;
if (value instanceof Collection) {
final Collection> collection = ((Collection>)value);
return propertyCanHoldCollections() &&
isConformantSizeForProperty(collection) &&
allAreConformantTypeForProperty(collection);
} else {
return isConformantTypeForProperty(value);
}
}
@SuppressWarnings("unchecked")
public void invoke(Object value) throws EolRuntimeException {
EStructuralFeature sf = getEStructuralFeature();
if (sf.isMany()) {
if (value != null) {
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy