blob: 056b3152ebf72c435a0ab7ec1967f25df198ee68 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2011, 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
*******************************************************************************/
package org.eclipse.qvtd.pivot.qvttemplate.impl;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
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.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.pivot.Property;
import org.eclipse.ocl.pivot.Type;
import org.eclipse.ocl.pivot.evaluation.Executor;
import org.eclipse.ocl.pivot.ids.IdResolver;
import org.eclipse.ocl.pivot.ids.TypeId;
import org.eclipse.ocl.pivot.internal.ElementImpl;
import org.eclipse.ocl.pivot.internal.LiteralExpImpl;
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.SetValue;
import org.eclipse.ocl.pivot.values.SetValue.Accumulator;
import org.eclipse.qvtd.pivot.qvttemplate.ObjectTemplateExp;
import org.eclipse.qvtd.pivot.qvttemplate.PropertyTemplateItem;
import org.eclipse.qvtd.pivot.qvttemplate.QVTtemplatePackage;
import org.eclipse.qvtd.pivot.qvttemplate.QVTtemplateTables;
import org.eclipse.qvtd.pivot.qvttemplate.util.QVTtemplateVisitor;
/**
* <!-- begin-user-doc -->
* An implementation of the model object '<em><b>Object Template Exp</b></em>'.
* <!-- end-user-doc -->
* <p>
* The following features are implemented:
* </p>
* <ul>
* <li>{@link org.eclipse.qvtd.pivot.qvttemplate.impl.ObjectTemplateExpImpl#getPart <em>Part</em>}</li>
* <li>{@link org.eclipse.qvtd.pivot.qvttemplate.impl.ObjectTemplateExpImpl#getReferredClass <em>Referred Class</em>}</li>
* </ul>
*
* @generated
*/
public class ObjectTemplateExpImpl extends TemplateExpImpl implements ObjectTemplateExp {
/**
* The number of structural features of the '<em>Object Template Exp</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int OBJECT_TEMPLATE_EXP_FEATURE_COUNT = TemplateExpImpl.TEMPLATE_EXP_FEATURE_COUNT + 2;
/**
* The number of operations of the '<em>Object Template Exp</em>' class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
public static final int OBJECT_TEMPLATE_EXP_OPERATION_COUNT = TemplateExpImpl.TEMPLATE_EXP_OPERATION_COUNT + 2;
/**
* The cached value of the '{@link #getPart() <em>Part</em>}' containment reference list.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getPart()
* @generated
* @ordered
*/
protected EList<PropertyTemplateItem> part;
/**
* The cached value of the '{@link #getReferredClass() <em>Referred Class</em>}' reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getReferredClass()
* @generated
* @ordered
*/
protected org.eclipse.ocl.pivot.Class referredClass;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
protected ObjectTemplateExpImpl() {
super();
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return QVTtemplatePackage.Literals.OBJECT_TEMPLATE_EXP;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EList<PropertyTemplateItem> getPart() {
if (part == null) {
part = new EObjectContainmentWithInverseEList<PropertyTemplateItem>(PropertyTemplateItem.class, this, LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2, ElementImpl.ELEMENT_FEATURE_COUNT + 0);
}
return part;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public org.eclipse.ocl.pivot.Class getReferredClass() {
if (referredClass != null && referredClass.eIsProxy()) {
InternalEObject oldReferredClass = (InternalEObject)referredClass;
referredClass = (org.eclipse.ocl.pivot.Class)eResolveProxy(oldReferredClass);
if (referredClass != oldReferredClass) {
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.RESOLVE, LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3, oldReferredClass, referredClass));
}
}
return referredClass;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public org.eclipse.ocl.pivot.Class basicGetReferredClass() {
return referredClass;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void setReferredClass(org.eclipse.ocl.pivot.Class newReferredClass) {
org.eclipse.ocl.pivot.Class oldReferredClass = referredClass;
referredClass = newReferredClass;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3, oldReferredClass, referredClass));
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean validatePartPropertyIsUnique(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "ObjectTemplateExp::PartPropertyIsUnique";
try {
/**
*
* inv PartPropertyIsUnique:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let
* result : Boolean[1] = part->isUnique(resolvedProperty)
* in
* constraintName.logDiagnostic(self, null, diagnostics, context, null, severity, result, 0)
* endif
*/
final /*@NonInvalid*/ @NonNull Executor executor = PivotUtil.getExecutor(this);
final /*@NonInvalid*/ @NonNull IdResolver idResolver = executor.getIdResolver();
final /*@NonInvalid*/ @NonNull IntegerValue severity_0 = CGStringGetSeverityOperation.INSTANCE.evaluate(executor, QVTtemplatePackage.Literals.OBJECT_TEMPLATE_EXP___VALIDATE_PART_PROPERTY_IS_UNIQUE__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTtemplateTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull List<PropertyTemplateItem> part = this.getPart();
final /*@NonInvalid*/ @NonNull SetValue BOXED_part = idResolver.createSetOfAll(QVTtemplateTables.SET_CLSSid_PropertyTemplateItem, part);
/*@Thrown*/ @NonNull Accumulator accumulator = ValueUtil.createSetAccumulatorValue(QVTtemplateTables.SET_CLSSid_PropertyTemplateItem);
@NonNull Iterator<Object> ITERATOR__1 = BOXED_part.iterator();
/*@NonInvalid*/ boolean result;
while (true) {
if (!ITERATOR__1.hasNext()) {
result = true;
break;
}
@SuppressWarnings("null")
/*@NonInvalid*/ @NonNull PropertyTemplateItem _1 = (@NonNull PropertyTemplateItem)ITERATOR__1.next();
/**
* resolvedProperty
*/
@SuppressWarnings("null")
final /*@NonInvalid*/ @NonNull Property resolvedProperty = _1.getResolvedProperty();
//
if (accumulator.includes(resolvedProperty) == ValueUtil.TRUE_VALUE) {
result = false;
break; // Abort after second find
}
else {
accumulator.add(resolvedProperty);
}
}
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, severity_0, result, QVTtemplateTables.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 validateTypeisObjectType(final DiagnosticChain diagnostics, final Map<Object, Object> context) {
final @NonNull String constraintName = "ObjectTemplateExp::TypeisObjectType";
try {
/**
*
* inv TypeisObjectType:
* let severity : Integer[1] = constraintName.getSeverity()
* in
* if severity <= 0
* then true
* else
* let result : Boolean[1] = type = referredClass
* 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, QVTtemplatePackage.Literals.OBJECT_TEMPLATE_EXP___VALIDATE_TYPEIS_OBJECT_TYPE__DIAGNOSTICCHAIN_MAP);
final /*@NonInvalid*/ boolean le = OclComparableLessThanEqualOperation.INSTANCE.evaluate(executor, severity_0, QVTtemplateTables.INT_0).booleanValue();
/*@NonInvalid*/ boolean symbol_0;
if (le) {
symbol_0 = true;
}
else {
final /*@NonInvalid*/ @Nullable Type type = this.getType();
@SuppressWarnings("null")
final /*@NonInvalid*/ org.eclipse.ocl.pivot.@NonNull Class referredClass = this.getReferredClass();
final /*@NonInvalid*/ boolean result = (type != null) ? (type.getTypeId() == referredClass.getTypeId()) : false;
final /*@NonInvalid*/ boolean logDiagnostic = CGStringLogDiagnosticOperation.INSTANCE.evaluate(executor, TypeId.BOOLEAN, constraintName, this, (Object)null, diagnostics, context, (Object)null, severity_0, result, QVTtemplateTables.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
*/
@SuppressWarnings("unchecked")
@Override
public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
return ((InternalEList<InternalEObject>)(InternalEList<?>)getPart()).basicAdd(otherEnd, msgs);
}
return super.eInverseAdd(otherEnd, featureID, msgs);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
switch (featureID) {
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
return ((InternalEList<?>)getPart()).basicRemove(otherEnd, 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 LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
return getPart();
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3:
if (resolve) return getReferredClass();
return basicGetReferredClass();
}
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 LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
getPart().clear();
getPart().addAll((Collection<? extends PropertyTemplateItem>)newValue);
return;
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3:
setReferredClass((org.eclipse.ocl.pivot.Class)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
getPart().clear();
return;
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3:
setReferredClass((org.eclipse.ocl.pivot.Class)null);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 2:
return part != null && !part.isEmpty();
case LiteralExpImpl.LITERAL_EXP_FEATURE_COUNT + 3:
return referredClass != 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 LiteralExpImpl.LITERAL_EXP_OPERATION_COUNT + 2:
return validatePartPropertyIsUnique((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
case LiteralExpImpl.LITERAL_EXP_OPERATION_COUNT + 3:
return validateTypeisObjectType((DiagnosticChain)arguments.get(0), (Map<Object, Object>)arguments.get(1));
}
return super.eInvoke(operationID, arguments);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@SuppressWarnings("unchecked")
@Override
public <R> R accept(@NonNull Visitor<R> visitor) {
if (visitor instanceof QVTtemplateVisitor) {
return (R) ((QVTtemplateVisitor<?>)visitor).visitObjectTemplateExp(this);
}
else {
return super.accept(visitor);
}
}
} //ObjectTemplateExpImpl