blob: aa5850cb40d889fb6d5a201982aa8d51f6a9ae6c [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.qvtrelation.impl;
import java.lang.reflect.InvocationTargetException;
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.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.VariableImpl;
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.qvtbase.TypedModel;
import org.eclipse.qvtd.pivot.qvtrelation.QVTrelationPackage;
import org.eclipse.qvtd.pivot.qvtrelation.QVTrelationTables;
import org.eclipse.qvtd.pivot.qvtrelation.SharedVariable;
import org.eclipse.qvtd.pivot.qvtrelation.util.QVTrelationVisitor;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Shared Variable</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.qvtd.pivot.qvtrelation.impl.SharedVariableImpl#getTypedModel <em>Typed Model</em>}</li>
* </ul>
*
* @generated
*/
public class SharedVariableImpl extends VariableImpl implements SharedVariable {
/**
* The number of structural features of the '<em>Shared Variable</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int SHARED_VARIABLE_FEATURE_COUNT = VariableImpl.VARIABLE_FEATURE_COUNT + 1;
/**
* The number of operations of the '<em>Shared Variable</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int SHARED_VARIABLE_OPERATION_COUNT = VariableImpl.VARIABLE_OPERATION_COUNT + 2;
/**
* The cached value of the '{@link #getTypedModel() <em>Typed Model</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getTypedModel()
* @generated
* @ordered
*/
protected TypedModel typedModel;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected SharedVariableImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return QVTrelationPackage.Literals.SHARED_VARIABLE;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public TypedModel getTypedModel() {
if (typedModel != null && typedModel.eIsProxy()) {
InternalEObject oldTypedModel = (InternalEObject)typedModel;
typedModel = (TypedModel)eResolveProxy(oldTypedModel);
if (typedModel != oldTypedModel) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, VariableImpl.VARIABLE_FEATURE_COUNT + 0, oldTypedModel, typedModel));
}
}
return typedModel;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public TypedModel basicGetTypedModel() {
return typedModel;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setTypedModel(TypedModel newTypedModel) {
TypedModel oldTypedModel = typedModel;
typedModel = newTypedModel;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, VariableImpl.VARIABLE_FEATURE_COUNT + 0, oldTypedModel, typedModel));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validateCompatibleTypeForInitializer(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "SharedVariable::CompatibleTypeForInitializer";
try {
/**
*
* inv CompatibleTypeForInitializer:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[?] = ownedInit <> null implies
* ownedInit.type?.conformsTo(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, QVTrelationPackage.Literals.SHARED_VARIABLE___VALIDATE_COMPATIBLE_TYPE_FOR_INITIALIZER__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTrelationTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_result;
try {
final /*@NonInvalid*/ @Nullable OCLExpression ownedInit = this.getOwnedInit();
final /*@NonInvalid*/ boolean ne = ownedInit != null;
final /*@Thrown*/ @Nullable Boolean result;
if (!ne) {
result = ValueUtil.TRUE_VALUE;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_safe_conformsTo_source;
try {
if (ownedInit == null) {
throw new InvalidValueException("Null source for \'TypedElement::type\'");
}
final /*@Thrown*/ @Nullable Type type = ownedInit.getType();
/*@Caught*/ @Nullable Object CAUGHT_type;
try {
CAUGHT_type = type;
}
catch (Exception e) {
CAUGHT_type = ValueUtil.createInvalidValue(e);
}
final /*@NonInvalid*/ @NonNull Object conformsTo = CAUGHT_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");
}
final /*@NonInvalid*/ @Nullable Type type_0 = this.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, QVTrelationTables.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 validateCompatibleNullityForInitializer(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "SharedVariable::CompatibleNullityForInitializer";
try {
/**
*
* inv CompatibleNullityForInitializer:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[?] = ownedInit <> null implies ownedInit.isRequired = isRequired
* 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, QVTrelationPackage.Literals.SHARED_VARIABLE___VALIDATE_COMPATIBLE_NULLITY_FOR_INITIALIZER__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTrelationTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
/*@Caught*/ @Nullable Object CAUGHT_result;
try {
final /*@NonInvalid*/ @Nullable OCLExpression ownedInit = this.getOwnedInit();
final /*@NonInvalid*/ boolean ne = ownedInit != null;
final /*@Thrown*/ @Nullable Boolean result;
if (!ne) {
result = ValueUtil.TRUE_VALUE;
}
else {
/*@Caught*/ @NonNull Object CAUGHT_eq;
try {
if (ownedInit == null) {
throw new InvalidValueException("Null source for \'TypedElement::isRequired\'");
}
final /*@Thrown*/ boolean isRequired = ownedInit.isIsRequired();
final /*@NonInvalid*/ boolean isRequired_0 = this.isIsRequired();
final /*@Thrown*/ boolean eq = isRequired == isRequired_0;
CAUGHT_eq = eq;
}
catch (Exception e) {
CAUGHT_eq = ValueUtil.createInvalidValue(e);
}
if (CAUGHT_eq == ValueUtil.TRUE_VALUE) {
result = ValueUtil.TRUE_VALUE;
}
else {
if (CAUGHT_eq instanceof InvalidValueException) {
throw (InvalidValueException)CAUGHT_eq;
}
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, QVTrelationTables.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 Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case VariableImpl.VARIABLE_FEATURE_COUNT + 0:
if (resolve) return getTypedModel();
return basicGetTypedModel();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case VariableImpl.VARIABLE_FEATURE_COUNT + 0:
setTypedModel((TypedModel)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case VariableImpl.VARIABLE_FEATURE_COUNT + 0:
setTypedModel((TypedModel)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case VariableImpl.VARIABLE_FEATURE_COUNT + 0:
return typedModel != null;
}
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 VariableImpl.VARIABLE_OPERATION_COUNT + 0:
return validateCompatibleTypeForInitializer((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
case VariableImpl.VARIABLE_OPERATION_COUNT + 1:
return validateCompatibleNullityForInitializer((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 QVTrelationVisitor) {
return (R) ((QVTrelationVisitor<?>)visitor).visitSharedVariable(this);
}
else {
return super.accept(visitor);
}
}
} //SharedVariableImpl