blob: 6c690980160e22b8e13da780532296f8f02c8f2b [file] [log] [blame]
/**
* <copyright>
*
* Copyright (c) 2013, 2020 Willink Transformations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* E.D.Willink - Initial API and implementation
*
* </copyright>
*/
package org.eclipse.qvtd.pivot.qvtimperative.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.OCLExpression;
import org.eclipse.ocl.pivot.Type;
import org.eclipse.ocl.pivot.evaluation.Executor;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.internal.ElementImpl;
import org.eclipse.ocl.pivot.library.classifier.OclTypeConformsToOperation;
import org.eclipse.ocl.pivot.library.oclany.OclComparableLessThanEqualOperation;
import org.eclipse.ocl.pivot.library.string.CGStringGetSeverityOperation;
import org.eclipse.ocl.pivot.library.string.CGStringLogDiagnosticOperation;
import org.eclipse.ocl.pivot.util.Visitor;
import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.ocl.pivot.utilities.ValueUtil;
import org.eclipse.ocl.pivot.values.IntegerValue;
import org.eclipse.ocl.pivot.values.InvalidValueException;
import org.eclipse.qvtd.pivot.qvtimperative.MappingParameter;
import org.eclipse.qvtd.pivot.qvtimperative.QVTimperativePackage;
import org.eclipse.qvtd.pivot.qvtimperative.QVTimperativeTables;
import org.eclipse.qvtd.pivot.qvtimperative.SimpleParameterBinding;
import org.eclipse.qvtd.pivot.qvtimperative.util.QVTimperativeVisitor;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Simple Parameter Binding</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.SimpleParameterBindingImpl#getValue <em>Value</em>}</li>
* <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.SimpleParameterBindingImpl#isIsCheck <em>Is Check</em>}</li>
* </ul>
*
* @generated
*/
public class SimpleParameterBindingImpl extends MappingParameterBindingImpl implements SimpleParameterBinding {
/**
* The number of structural features of the '<em>Simple Parameter Binding</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int SIMPLE_PARAMETER_BINDING_FEATURE_COUNT = MappingParameterBindingImpl.MAPPING_PARAMETER_BINDING_FEATURE_COUNT + 2;
/**
* The number of operations of the '<em>Simple Parameter Binding</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int SIMPLE_PARAMETER_BINDING_OPERATION_COUNT = MappingParameterBindingImpl.MAPPING_PARAMETER_BINDING_OPERATION_COUNT + 2;
/**
* The cached value of the '{@link #getValue() <em>Value</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getValue()
* @generated
* @ordered
*/
protected OCLExpression value;
/**
* The default value of the '{@link #isIsCheck() <em>Is Check</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsCheck()
* @generated
* @ordered
*/
protected static final boolean IS_CHECK_EDEFAULT = false;
/**
* The cached value of the '{@link #isIsCheck() <em>Is Check</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsCheck()
* @generated
* @ordered
*/
protected boolean isCheck = IS_CHECK_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected SimpleParameterBindingImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return QVTimperativePackage.Literals.SIMPLE_PARAMETER_BINDING;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public OCLExpression getValue() {
return value;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetValue(OCLExpression newValue, NotificationChain msgs) {
OCLExpression oldValue = value;
value = newValue;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ElementImpl.ELEMENT_FEATURE_COUNT + 2, oldValue, newValue);
if (msgs == null) msgs = notification; else msgs.add(notification);
}
return msgs;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setValue(OCLExpression newValue) {
if (newValue != value) {
NotificationChain msgs = null;
if (value != null)
msgs = ((InternalEObject)value).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - (ElementImpl.ELEMENT_FEATURE_COUNT + 2), null, msgs);
if (newValue != null)
msgs = ((InternalEObject)newValue).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - (ElementImpl.ELEMENT_FEATURE_COUNT + 2), null, msgs);
msgs = basicSetValue(newValue, msgs);
if (msgs != null) msgs.dispatch();
}
else if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ElementImpl.ELEMENT_FEATURE_COUNT + 2, newValue, newValue));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean isIsCheck() {
return isCheck;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setIsCheck(boolean newIsCheck) {
boolean oldIsCheck = isCheck;
isCheck = newIsCheck;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ElementImpl.ELEMENT_FEATURE_COUNT + 3, oldIsCheck, isCheck));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validateCompatibleTypeForCheckedValue(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "SimpleParameterBinding::CompatibleTypeForCheckedValue";
try {
/**
*
* inv CompatibleTypeForCheckedValue:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[?] = isCheck implies
* boundVariable.type?.conformsTo(value.type)
* in
* constraintName.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
* endif
*/
final /*@NonInvalid*/ @NonNull Executor executor = PivotUtil.getExecutor(this);
final /*@NonInvalid*/ @NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativePackage.Literals.SIMPLE_PARAMETER_BINDING___VALIDATE_COMPATIBLE_TYPE_FOR_CHECKED_VALUE__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTimperativeTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_result;
try {
final /*@NonInvalid*/ boolean isCheck = this.isIsCheck();
final /*@Thrown*/ @Nullable Boolean result;
if (!isCheck) {
result = ValueUtil.TRUE_VALUE;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_safe_conformsTo_source;
try {
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull MappingParameter boundVariable = this.getBoundVariable();
final /*@NonInvalid*/ @Nullable Type type = boundVariable.getType();
final /*@NonInvalid*/ @NonNull Object conformsTo = type == null;
/*@Thrown*/ @Nullable Boolean safe_conformsTo_source;
if (conformsTo == Boolean.TRUE) {
safe_conformsTo_source = null;
}
else {
if (type == null) {
throw new InvalidValueException("Null \'\'Type\'\' rather than \'\'OclVoid\'\' value required");
}
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull OCLExpression value = this.getValue();
final /*@NonInvalid*/ @Nullable Type type_0 = value.getType();
final /*@Thrown*/ boolean conformsTo_0 = OclTypeConformsToOperation.INSTANCE.evaluate(executor, type, type_0).booleanValue();
safe_conformsTo_source = conformsTo_0;
}
CAUGHT_safe_conformsTo_source = safe_conformsTo_source;
}
catch (Exception e) {
CAUGHT_safe_conformsTo_source = ValueUtil.createInvalidValue(e);
}
if (CAUGHT_safe_conformsTo_source == ValueUtil.TRUE_VALUE) {
result = ValueUtil.TRUE_VALUE;
}
else {
if (CAUGHT_safe_conformsTo_source instanceof InvalidValueException) {
throw (InvalidValueException)CAUGHT_safe_conformsTo_source;
}
if (CAUGHT_safe_conformsTo_source == null) {
result = null;
}
else {
result = ValueUtil.FALSE_VALUE;
}
}
}
CAUGHT_result = result;
}
catch (Exception e) {
CAUGHT_result = ValueUtil.createInvalidValue(e);
}
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, severity_0, CAUGHT_result, QVTimperativeTables.INT_0).booleanValue();
symbol_0 = logDiagnostic;
}
return symbol_0;
}
catch (Throwable e) {
return ValueUtil.validationFailedDiagnostic(constraintName, this, diagnostics, context, e);
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validateCompatibleTypeForUncheckedValue(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "SimpleParameterBinding::CompatibleTypeForUncheckedValue";
try {
/**
*
* inv CompatibleTypeForUncheckedValue:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[?] = not isCheck implies
* value.type?.conformsTo(boundVariable.type)
* in
* constraintName.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
* endif
*/
final /*@NonInvalid*/ @NonNull Executor executor = PivotUtil.getExecutor(this);
final /*@NonInvalid*/ @NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativePackage.Literals.SIMPLE_PARAMETER_BINDING___VALIDATE_COMPATIBLE_TYPE_FOR_UNCHECKED_VALUE__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTimperativeTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_result;
try {
final /*@NonInvalid*/ boolean isCheck = this.isIsCheck();
final /*@NonInvalid*/ @Nullable Boolean not;
if (!isCheck) {
not = ValueUtil.TRUE_VALUE;
}
else {
if (isCheck) {
not = ValueUtil.FALSE_VALUE;
}
else {
not = null;
}
}
final /*@Thrown*/ @Nullable Boolean result;
if (not == ValueUtil.FALSE_VALUE) {
result = ValueUtil.TRUE_VALUE;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_safe_conformsTo_source;
try {
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull OCLExpression value = this.getValue();
final /*@NonInvalid*/ @Nullable Type type = value.getType();
final /*@NonInvalid*/ @NonNull Object conformsTo = type == null;
/*@Thrown*/ @Nullable Boolean safe_conformsTo_source;
if (conformsTo == Boolean.TRUE) {
safe_conformsTo_source = null;
}
else {
if (type == null) {
throw new InvalidValueException("Null \'\'Type\'\' rather than \'\'OclVoid\'\' value required");
}
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull MappingParameter boundVariable = this.getBoundVariable();
final /*@NonInvalid*/ @Nullable Type type_0 = boundVariable.getType();
final /*@Thrown*/ boolean conformsTo_0 = OclTypeConformsToOperation.INSTANCE.evaluate(executor, type, type_0).booleanValue();
safe_conformsTo_source = conformsTo_0;
}
CAUGHT_safe_conformsTo_source = safe_conformsTo_source;
}
catch (Exception e) {
CAUGHT_safe_conformsTo_source = ValueUtil.createInvalidValue(e);
}
if (CAUGHT_safe_conformsTo_source == ValueUtil.TRUE_VALUE) {
result = ValueUtil.TRUE_VALUE;
}
else {
if (CAUGHT_safe_conformsTo_source instanceof InvalidValueException) {
throw (InvalidValueException)CAUGHT_safe_conformsTo_source;
}
if ((not == null) || (CAUGHT_safe_conformsTo_source == null)) {
result = null;
}
else {
result = ValueUtil.FALSE_VALUE;
}
}
}
CAUGHT_result = result;
}
catch (Exception e) {
CAUGHT_result = ValueUtil.createInvalidValue(e);
}
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, severity_0, CAUGHT_result, QVTimperativeTables.INT_0).booleanValue();
symbol_0 = logDiagnostic;
}
return symbol_0;
}
catch (Throwable e) {
return ValueUtil.validationFailedDiagnostic(constraintName, this, diagnostics, context, e);
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String toString() {
return super.toString();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case ElementImpl.ELEMENT_FEATURE_COUNT + 2:
return basicSetValue(null, msgs);
}
return super.eInverseRemove(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case ElementImpl.ELEMENT_FEATURE_COUNT + 2:
return getValue();
case ElementImpl.ELEMENT_FEATURE_COUNT + 3:
return isIsCheck();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case ElementImpl.ELEMENT_FEATURE_COUNT + 2:
setValue((OCLExpression)newValue);
return;
case ElementImpl.ELEMENT_FEATURE_COUNT + 3:
setIsCheck((Boolean)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case ElementImpl.ELEMENT_FEATURE_COUNT + 2:
setValue((OCLExpression)null);
return;
case ElementImpl.ELEMENT_FEATURE_COUNT + 3:
setIsCheck(IS_CHECK_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case ElementImpl.ELEMENT_FEATURE_COUNT + 2:
return value != null;
case ElementImpl.ELEMENT_FEATURE_COUNT + 3:
return isCheck != IS_CHECK_EDEFAULT;
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
@SuppressWarnings("unchecked")
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
switch (operationID) {
case ElementImpl.ELEMENT_OPERATION_COUNT + 1:
return validateCompatibleTypeForCheckedValue((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
case ElementImpl.ELEMENT_OPERATION_COUNT + 2:
return validateCompatibleTypeForUncheckedValue((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
}
return super.eInvoke(operationID, arguments);
}
/**
* {@inheritDoc}
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public <R> R accept(@NonNull Visitor<R> visitor) {
if (visitor instanceof QVTimperativeVisitor) {
return (R) ((QVTimperativeVisitor<?>)visitor).visitSimpleParameterBinding(this);
}
else {
return super.accept(visitor);
}
}
} //SimpleParameterBindingImpl