blob: 622c28ab83aa664f347a3512bf0b7e68a9c194a0 [file] [log] [blame]
/**
* <copyright>
*
* Copyright (c) 2013, 2019 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.List;
import java.util.Map;
import org.eclipse.emf.common.notify.Notification;
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.impl.ENotificationImpl;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.evaluation.Executor;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.library.logical.BooleanNotOperation;
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.qvtbase.impl.TypedModelImpl;
import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTypedModel;
import org.eclipse.qvtd.pivot.qvtimperative.QVTimperativePackage;
import org.eclipse.qvtd.pivot.qvtimperative.QVTimperativeTables;
import org.eclipse.qvtd.pivot.qvtimperative.util.QVTimperativeVisitor;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Imperative Typed Model</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.ImperativeTypedModelImpl#isIsChecked <em>Is Checked</em>}</li>
* <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.ImperativeTypedModelImpl#isIsEnforced <em>Is Enforced</em>}</li>
* <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.ImperativeTypedModelImpl#getAllUsedPackages <em>All Used Packages</em>}</li>
* </ul>
*
* @generated
*/
public class ImperativeTypedModelImpl extends TypedModelImpl implements ImperativeTypedModel {
/**
* The number of structural features of the '<em>Imperative Typed Model</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int IMPERATIVE_TYPED_MODEL_FEATURE_COUNT = TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 3;
/**
* The number of operations of the '<em>Imperative Typed Model</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int IMPERATIVE_TYPED_MODEL_OPERATION_COUNT = TypedModelImpl.TYPED_MODEL_OPERATION_COUNT + 2;
/**
* The default value of the '{@link #isIsChecked() <em>Is Checked</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsChecked()
* @generated
* @ordered
*/
protected static final boolean IS_CHECKED_EDEFAULT = false;
/**
* The cached value of the '{@link #isIsChecked() <em>Is Checked</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsChecked()
* @generated
* @ordered
*/
protected boolean isChecked = IS_CHECKED_EDEFAULT;
/**
* The default value of the '{@link #isIsEnforced() <em>Is Enforced</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsEnforced()
* @generated
* @ordered
*/
protected static final boolean IS_ENFORCED_EDEFAULT = false;
/**
* The cached value of the '{@link #isIsEnforced() <em>Is Enforced</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #isIsEnforced()
* @generated
* @ordered
*/
protected boolean isEnforced = IS_ENFORCED_EDEFAULT;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ImperativeTypedModelImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return QVTimperativePackage.Literals.IMPERATIVE_TYPED_MODEL;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean isIsChecked() {
return isChecked;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setIsChecked(boolean newIsChecked) {
boolean oldIsChecked = isChecked;
isChecked = newIsChecked;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 0, oldIsChecked, isChecked));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean isIsEnforced() {
return isEnforced;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setIsEnforced(boolean newIsEnforced) {
boolean oldIsEnforced = isEnforced;
isEnforced = newIsEnforced;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 1, oldIsEnforced, isEnforced));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EList<org.eclipse.ocl.pivot.Package> getAllUsedPackages() {
/**
* usedPackage
*/
final /*@NonInvalid*/ @NonNull List<org.eclipse.ocl.pivot.Package> usedPackage = this.getUsedPackage();
return (EList<org.eclipse.ocl.pivot.Package>)usedPackage;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validateNameIsNotNull(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "ImperativeTypedModel::NameIsNotNull";
try {
/**
*
* inv NameIsNotNull:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[1] = name <> null
* in
* constraintName.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
* endif
*/
final /*@NonInvalid*/ @NonNull Executor executor = PivotUtil.getExecutor(this, context);
/*@Caught*/ @NonNull Object CAUGHT_severity_0;
try {
final /*@Thrown*/ @NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativePackage.Literals.IMPERATIVE_TYPED_MODEL___VALIDATE_NAME_IS_NOT_NULL__DIAGNOSTICCHAIN_MAP);
CAUGHT_severity_0 = severity_0;
}
catch (Exception e) {
CAUGHT_severity_0 = ValueUtil.createInvalidValue(e);
}
if (CAUGHT_severity_0 instanceof InvalidValueException) {
throw (InvalidValueException)CAUGHT_severity_0;
}
final /*@Thrown*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, CAUGHT_severity_0, QVTimperativeTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = ValueUtil.TRUE_VALUE;
}
else {
final /*@NonInvalid*/ @Nullable String name = this.getName();
final /*@NonInvalid*/ boolean result = name != null;
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, CAUGHT_severity_0, result, QVTimperativeTables.INT_0).booleanValue();
symbol_0 = logDiagnostic;
}
return Boolean.TRUE == symbol_0;
}
catch (Throwable e) {
return ValueUtil.validationFailedDiagnostic(constraintName, this, diagnostics, context, e);
}
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validateNotBothCheckedAndEnforced(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "ImperativeTypedModel::NotBothCheckedAndEnforced";
try {
/**
*
* inv NotBothCheckedAndEnforced:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[?] = not (isChecked and isEnforced)
* in
* constraintName.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
* endif
*/
final /*@NonInvalid*/ @NonNull Executor executor = PivotUtil.getExecutor(this, context);
/*@Caught*/ @NonNull Object CAUGHT_severity_0;
try {
final /*@Thrown*/ @NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativePackage.Literals.IMPERATIVE_TYPED_MODEL___VALIDATE_NOT_BOTH_CHECKED_AND_ENFORCED__DIAGNOSTICCHAIN_MAP);
CAUGHT_severity_0 = severity_0;
}
catch (Exception e) {
CAUGHT_severity_0 = ValueUtil.createInvalidValue(e);
}
if (CAUGHT_severity_0 instanceof InvalidValueException) {
throw (InvalidValueException)CAUGHT_severity_0;
}
final /*@Thrown*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, CAUGHT_severity_0, QVTimperativeTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = ValueUtil.TRUE_VALUE;
}
else {
final /*@NonInvalid*/ boolean isChecked = this.isIsChecked();
/*@NonInvalid*/ boolean and;
if (isChecked) {
final /*@NonInvalid*/ boolean isEnforced = this.isIsEnforced();
and = isEnforced;
}
else {
and = ValueUtil.FALSE_VALUE;
}
final /*@NonInvalid*/ @Nullable Boolean result = BooleanNotOperation.INSTANCE.evaluate(and);
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, CAUGHT_severity_0, result, QVTimperativeTables.INT_0).booleanValue();
symbol_0 = logDiagnostic;
}
return Boolean.TRUE == 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 Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 0:
return isIsChecked();
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 1:
return isIsEnforced();
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 2:
return getAllUsedPackages();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 0:
setIsChecked((Boolean)newValue);
return;
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 1:
setIsEnforced((Boolean)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 0:
setIsChecked(IS_CHECKED_EDEFAULT);
return;
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 1:
setIsEnforced(IS_ENFORCED_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 0:
return isChecked != IS_CHECKED_EDEFAULT;
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 1:
return isEnforced != IS_ENFORCED_EDEFAULT;
case TypedModelImpl.TYPED_MODEL_FEATURE_COUNT + 2:
return !getAllUsedPackages().isEmpty();
}
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 TypedModelImpl.TYPED_MODEL_OPERATION_COUNT + 0:
return validateNameIsNotNull((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
case TypedModelImpl.TYPED_MODEL_OPERATION_COUNT + 1:
return validateNotBothCheckedAndEnforced((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) {
return (R) ((QVTimperativeVisitor<?>)visitor).visitImperativeTypedModel(this);
}
} //ImperativeTypedModelImpl