| /** |
| * <copyright> |
| * |
| * Copyright (c) 2013, 2018 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.Collection; |
| |
| 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.emf.ecore.util.EObjectResolvingEList; |
| import org.eclipse.jdt.annotation.NonNull; |
| import org.eclipse.jdt.annotation.Nullable; |
| import org.eclipse.ocl.pivot.OCLExpression; |
| import org.eclipse.ocl.pivot.Property; |
| import org.eclipse.ocl.pivot.ids.TypeId; |
| import org.eclipse.ocl.pivot.library.classifier.OclTypeConformsToOperation; |
| import org.eclipse.ocl.pivot.library.logical.BooleanNotOperation; |
| import org.eclipse.ocl.pivot.library.oclany.OclAnyOclIsKindOfOperation; |
| 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.InvalidValueException; |
| import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTypedModel; |
| import org.eclipse.qvtd.pivot.qvtimperative.NewStatement; |
| import org.eclipse.qvtd.pivot.qvtimperative.ObservableStatement; |
| 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>New Statement</b></em>'. |
| * <!-- end-user-doc --> |
| * <p> |
| * The following features are implemented: |
| * </p> |
| * <ul> |
| * <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.NewStatementImpl#getObservedProperties <em>Observed Properties</em>}</li> |
| * <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.NewStatementImpl#isIsContained <em>Is Contained</em>}</li> |
| * <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.NewStatementImpl#getReferredTypedModel <em>Referred Typed Model</em>}</li> |
| * <li>{@link org.eclipse.qvtd.pivot.qvtimperative.impl.NewStatementImpl#getOwnedExpression <em>Owned Expression</em>}</li> |
| * </ul> |
| * |
| * @generated |
| */ |
| public class NewStatementImpl extends VariableStatementImpl implements NewStatement { |
| /** |
| * The cached value of the '{@link #getObservedProperties() <em>Observed Properties</em>}' reference list. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getObservedProperties() |
| * @generated |
| * @ordered |
| */ |
| protected EList<Property> observedProperties; |
| |
| /** |
| * The default value of the '{@link #isIsContained() <em>Is Contained</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #isIsContained() |
| * @generated |
| * @ordered |
| */ |
| protected static final boolean IS_CONTAINED_EDEFAULT = false; |
| |
| /** |
| * The cached value of the '{@link #isIsContained() <em>Is Contained</em>}' attribute. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #isIsContained() |
| * @generated |
| * @ordered |
| */ |
| protected boolean isContained = IS_CONTAINED_EDEFAULT; |
| |
| /** |
| * The cached value of the '{@link #getReferredTypedModel() <em>Referred Typed Model</em>}' reference. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getReferredTypedModel() |
| * @generated |
| * @ordered |
| */ |
| protected ImperativeTypedModel referredTypedModel; |
| |
| /** |
| * The cached value of the '{@link #getOwnedExpression() <em>Owned Expression</em>}' containment reference. |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @see #getOwnedExpression() |
| * @generated |
| * @ordered |
| */ |
| protected OCLExpression ownedExpression; |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| protected NewStatementImpl() { |
| super(); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| protected EClass eStaticClass() { |
| return QVTimperativePackage.Literals.NEW_STATEMENT; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public EList<Property> getObservedProperties() { |
| if (observedProperties == null) { |
| observedProperties = new EObjectResolvingEList<Property>(Property.class, this, QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES); |
| } |
| return observedProperties; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean isIsContained() { |
| return isContained; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setIsContained(boolean newIsContained) { |
| boolean oldIsContained = isContained; |
| isContained = newIsContained; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, QVTimperativePackage.NEW_STATEMENT__IS_CONTAINED, oldIsContained, isContained)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public ImperativeTypedModel getReferredTypedModel() { |
| if (referredTypedModel != null && referredTypedModel.eIsProxy()) { |
| InternalEObject oldReferredTypedModel = (InternalEObject)referredTypedModel; |
| referredTypedModel = (ImperativeTypedModel)eResolveProxy(oldReferredTypedModel); |
| if (referredTypedModel != oldReferredTypedModel) { |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.RESOLVE, QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL, oldReferredTypedModel, referredTypedModel)); |
| } |
| } |
| return referredTypedModel; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public ImperativeTypedModel basicGetReferredTypedModel() { |
| return referredTypedModel; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setReferredTypedModel(ImperativeTypedModel newReferredTypedModel) { |
| ImperativeTypedModel oldReferredTypedModel = referredTypedModel; |
| referredTypedModel = newReferredTypedModel; |
| if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL, oldReferredTypedModel, referredTypedModel)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public OCLExpression getOwnedExpression() { |
| return ownedExpression; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| public NotificationChain basicSetOwnedExpression(OCLExpression newOwnedExpression, NotificationChain msgs) { |
| OCLExpression oldOwnedExpression = ownedExpression; |
| ownedExpression = newOwnedExpression; |
| if (eNotificationRequired()) { |
| ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION, oldOwnedExpression, newOwnedExpression); |
| if (msgs == null) msgs = notification; else msgs.add(notification); |
| } |
| return msgs; |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void setOwnedExpression(OCLExpression newOwnedExpression) { |
| if (newOwnedExpression != ownedExpression) { |
| NotificationChain msgs = null; |
| if (ownedExpression != null) |
| msgs = ((InternalEObject)ownedExpression).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION, null, msgs); |
| if (newOwnedExpression != null) |
| msgs = ((InternalEObject)newOwnedExpression).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION, null, msgs); |
| msgs = basicSetOwnedExpression(newOwnedExpression, msgs); |
| if (msgs != null) msgs.dispatch(); |
| } |
| else if (eNotificationRequired()) |
| eNotify(new ENotificationImpl(this, Notification.SET, QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION, newOwnedExpression, newOwnedExpression)); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean validateCompatibleTypeForValue(final DiagnosticChain diagnostics, final Map<Object, Object> context) { |
| try { |
| /** |
| * |
| * inv CompatibleTypeForValue: |
| * let |
| * severity : Integer[1] = 'NewStatement::CompatibleTypeForValue'.getSeverity() |
| * in |
| * if severity <= 0 |
| * then true |
| * else |
| * let result : Boolean[?] = ownedExpression <> null implies |
| * ownedExpression.type.conformsTo(type) |
| * in |
| * 'NewStatement::CompatibleTypeForValue'.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0) |
| * endif |
| */ |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.evaluation.@NonNull Executor executor = PivotUtil.getExecutor(this, context); |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.values.@NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativeTables.STR_NewStatement_c_c_CompatibleTypeForValue); |
| final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTimperativeTables.INT_0).booleanValue(); |
| /*@NonInvalid*/ boolean symbol_0; |
| if (le) { |
| symbol_0 = ValueUtil.TRUE_VALUE; |
| } |
| else { |
| /*@Caught*/ @NonNull Object CAUGHT_result; |
| try { |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.@Nullable OCLExpression ownedExpression = this.getOwnedExpression(); |
| final /*@NonInvalid*/ boolean ne = ownedExpression != null; |
| /*@Thrown*/ boolean result; |
| if (ne) { |
| if (ownedExpression == null) { |
| throw new InvalidValueException("Null source for \'TypedElement::type\'"); |
| } |
| final /*@Thrown*/ org.eclipse.ocl.pivot.@Nullable Type type = ownedExpression.getType(); |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.@Nullable Type type_0 = this.getType(); |
| final /*@Thrown*/ boolean conformsTo = OclTypeConformsToOperation.INSTANCE.evaluate(executor, type, type_0).booleanValue(); |
| result = conformsTo; |
| } |
| else { |
| result = ValueUtil.TRUE_VALUE; |
| } |
| CAUGHT_result = result; |
| } |
| catch (Exception e) { |
| CAUGHT_result = ValueUtil.createInvalidValue(e); |
| } |
| final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, QVTimperativeTables.STR_NewStatement_c_c_CompatibleTypeForValue, this, (Object)null, diagnostics, context, (Object)null, severity_0, CAUGHT_result, QVTimperativeTables.INT_0).booleanValue(); |
| symbol_0 = logDiagnostic; |
| } |
| return Boolean.TRUE == symbol_0; |
| } |
| catch (Throwable e) { |
| return ValueUtil.validationFailedDiagnostic("NewStatement::CompatibleTypeForValue", this, diagnostics, context, e); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean validateNonDataTypeForType(final DiagnosticChain diagnostics, final Map<Object, Object> context) { |
| try { |
| /** |
| * |
| * inv NonDataTypeForType: |
| * let severity : Integer[1] = 'NewStatement::NonDataTypeForType'.getSeverity() |
| * in |
| * if severity <= 0 |
| * then true |
| * else |
| * let result : Boolean[?] = not type.oclIsKindOf(DataType) |
| * in |
| * 'NewStatement::NonDataTypeForType'.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0) |
| * endif |
| */ |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.evaluation.@NonNull Executor executor = PivotUtil.getExecutor(this, context); |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.ids.@NonNull IdResolver idResolver = executor.getIdResolver(); |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.values.@NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTimperativeTables.STR_NewStatement_c_c_NonDataTypeForType); |
| final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTimperativeTables.INT_0).booleanValue(); |
| /*@NonInvalid*/ boolean symbol_0; |
| if (le) { |
| symbol_0 = ValueUtil.TRUE_VALUE; |
| } |
| else { |
| /*@Caught*/ @NonNull Object CAUGHT_oclIsKindOf; |
| try { |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.@NonNull Class TYP_DataType = idResolver.getClass(QVTimperativeTables.CLSSid_DataType, null); |
| final /*@NonInvalid*/ org.eclipse.ocl.pivot.@Nullable Type type = this.getType(); |
| final /*@Thrown*/ boolean oclIsKindOf = OclAnyOclIsKindOfOperation.INSTANCE.evaluate(executor, type, TYP_DataType).booleanValue(); |
| CAUGHT_oclIsKindOf = oclIsKindOf; |
| } |
| catch (Exception e) { |
| CAUGHT_oclIsKindOf = ValueUtil.createInvalidValue(e); |
| } |
| final /*@NonInvalid*/ java.lang.@Nullable Boolean result = BooleanNotOperation.INSTANCE.evaluate(CAUGHT_oclIsKindOf); |
| final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, QVTimperativeTables.STR_NewStatement_c_c_NonDataTypeForType, this, (Object)null, diagnostics, context, (Object)null, severity_0, result, QVTimperativeTables.INT_0).booleanValue(); |
| symbol_0 = logDiagnostic; |
| } |
| return Boolean.TRUE == symbol_0; |
| } |
| catch (Throwable e) { |
| return ValueUtil.validationFailedDiagnostic("NewStatement::NonDataTypeForType", this, diagnostics, context, e); |
| } |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { |
| switch (featureID) { |
| case QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION: |
| return basicSetOwnedExpression(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 QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES: |
| return getObservedProperties(); |
| case QVTimperativePackage.NEW_STATEMENT__IS_CONTAINED: |
| return isIsContained(); |
| case QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL: |
| if (resolve) return getReferredTypedModel(); |
| return basicGetReferredTypedModel(); |
| case QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION: |
| return getOwnedExpression(); |
| } |
| return super.eGet(featureID, resolve, coreType); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @SuppressWarnings("unchecked") |
| @Override |
| public void eSet(int featureID, Object newValue) { |
| switch (featureID) { |
| case QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES: |
| getObservedProperties().clear(); |
| getObservedProperties().addAll((Collection<? extends Property>)newValue); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__IS_CONTAINED: |
| setIsContained((Boolean)newValue); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL: |
| setReferredTypedModel((ImperativeTypedModel)newValue); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION: |
| setOwnedExpression((OCLExpression)newValue); |
| return; |
| } |
| super.eSet(featureID, newValue); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public void eUnset(int featureID) { |
| switch (featureID) { |
| case QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES: |
| getObservedProperties().clear(); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__IS_CONTAINED: |
| setIsContained(IS_CONTAINED_EDEFAULT); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL: |
| setReferredTypedModel((ImperativeTypedModel)null); |
| return; |
| case QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION: |
| setOwnedExpression((OCLExpression)null); |
| return; |
| } |
| super.eUnset(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public boolean eIsSet(int featureID) { |
| switch (featureID) { |
| case QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES: |
| return observedProperties != null && !observedProperties.isEmpty(); |
| case QVTimperativePackage.NEW_STATEMENT__IS_CONTAINED: |
| return isContained != IS_CONTAINED_EDEFAULT; |
| case QVTimperativePackage.NEW_STATEMENT__REFERRED_TYPED_MODEL: |
| return referredTypedModel != null; |
| case QVTimperativePackage.NEW_STATEMENT__OWNED_EXPRESSION: |
| return ownedExpression != null; |
| } |
| return super.eIsSet(featureID); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) { |
| if (baseClass == ObservableStatement.class) { |
| switch (derivedFeatureID) { |
| case QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES: return QVTimperativePackage.OBSERVABLE_STATEMENT__OBSERVED_PROPERTIES; |
| default: return -1; |
| } |
| } |
| return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) { |
| if (baseClass == ObservableStatement.class) { |
| switch (baseFeatureID) { |
| case QVTimperativePackage.OBSERVABLE_STATEMENT__OBSERVED_PROPERTIES: return QVTimperativePackage.NEW_STATEMENT__OBSERVED_PROPERTIES; |
| default: return -1; |
| } |
| } |
| return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass); |
| } |
| |
| /** |
| * <!-- begin-user-doc --> |
| * <!-- end-user-doc --> |
| * @generated |
| */ |
| @Override |
| @SuppressWarnings("unchecked") |
| public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException { |
| switch (operationID) { |
| case QVTimperativePackage.NEW_STATEMENT___VALIDATE_COMPATIBLE_TYPE_FOR_VALUE__DIAGNOSTICCHAIN_MAP: |
| return validateCompatibleTypeForValue((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1)); |
| case QVTimperativePackage.NEW_STATEMENT___VALIDATE_NON_DATA_TYPE_FOR_TYPE__DIAGNOSTICCHAIN_MAP: |
| return validateNonDataTypeForType((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).visitNewStatement(this); |
| } |
| |
| @Override |
| public String toString() { |
| return super.toString(); |
| } |
| |
| } //NewStatementImpl |