/******************************************************************************* * Copyright (c) 2010, 2015 Willink Transformations and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * E.D.Willink - Initial API and implementation *******************************************************************************/ package org.eclipse.ocl.pivot.internal; import java.lang.reflect.InvocationTargetException; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.pivot.CallExp; import org.eclipse.ocl.pivot.CompleteInheritance; import org.eclipse.ocl.pivot.PivotPackage; import org.eclipse.ocl.pivot.StandardLibrary; import org.eclipse.ocl.pivot.TemplateParameter; import org.eclipse.ocl.pivot.TemplateParameters; import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.ids.IdResolver; import org.eclipse.ocl.pivot.ids.TypeId; import org.eclipse.ocl.pivot.util.Visitor; import org.eclipse.ocl.pivot.values.OCLValue; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Type</b></em>'. * <!-- end-user-doc --> * * @generated */ public abstract class TypeImpl extends NamedElementImpl implements Type { /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected TypeImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return PivotPackage.Literals.TYPE; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public org.eclipse.ocl.pivot.Class isClass() { throw new UnsupportedOperationException(); // FIXME Unimplemented http://www.eclipse.org/ocl/2015/Pivot!Type!isClass() } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public TemplateParameter isTemplateParameter() { throw new UnsupportedOperationException(); // FIXME Unimplemented http://www.eclipse.org/ocl/2015/Pivot!Type!isTemplateParameter() } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Type specializeIn(final CallExp expr, final Type selfType) { /** * self */ return this; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Type flattenedType() { /** * self */ return this; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException { switch (operationID) { case PivotPackage.TYPE___ALL_OWNED_ELEMENTS: return allOwnedElements(); case PivotPackage.TYPE___GET_VALUE__TYPE_STRING: return getValue((Type)arguments.get(0), (String)arguments.get(1)); case PivotPackage.TYPE___FLATTENED_TYPE: return flattenedType(); case PivotPackage.TYPE___IS_CLASS: return isClass(); case PivotPackage.TYPE___IS_TEMPLATE_PARAMETER: return isTemplateParameter(); case PivotPackage.TYPE___SPECIALIZE_IN__CALLEXP_TYPE: return specializeIn((CallExp)arguments.get(0), (Type)arguments.get(1)); } return eDynamicInvoke(operationID, arguments); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated NOT */ @Override public String toString() { return super.toString(); } @Override public <R> R accept(@NonNull Visitor<R> visitor) { return visitor.visitType(this); } public @NonNull EObject createInstance() { EObject eTarget = getESObject(); if (eTarget instanceof EClass) { EClass eClass = (EClass) eTarget; @SuppressWarnings("null")@NonNull EObject element = eClass.getEPackage().getEFactoryInstance().create(eClass); // TypeId typeId = IdManager.getTypeId(eClass); return /*ValuesUtil.createObjectValue(typeId, */element;//); } throw new UnsupportedOperationException(); // FIXME do a lazy AS2Ecore } public @Nullable Object createInstance(@NonNull String value) { EObject eTarget = getESObject(); if (eTarget instanceof EDataType) { EDataType eDataType = (EDataType) eTarget; Object element = eDataType.getEPackage().getEFactoryInstance().createFromString(eDataType, value); // TypeId typeId = IdManager.getTypeId(eDataType); return /*ValuesUtil.createObjectValue(typeId, */element;//); // return ValuesUtil.valueOf(element); } throw new UnsupportedOperationException(); // FIXME do a lazy AS2Ecore } @Override public @NonNull Type getCommonType(@NonNull IdResolver idResolver, @NonNull Type type) { if (type == this) { return this; } StandardLibrary standardLibrary = idResolver.getStandardLibrary(); CompleteInheritance thisInheritance = this.getInheritance(standardLibrary); CompleteInheritance thatInheritance = type.getInheritance(standardLibrary); return thisInheritance.getCommonInheritance(thatInheritance).getPivotClass(); } @Override public boolean isEqualTo(@NonNull StandardLibrary standardLibrary, @NonNull Type type) { if (this == type) { return true; } Type thisType = this.getNormalizedType(standardLibrary); Type thatType = type.getNormalizedType(standardLibrary); return thisType == thatType; } @Override public boolean isEqualToUnspecializedType(@NonNull StandardLibrary standardLibrary, @NonNull Type type) { if (this == type) { return true; } return false; } // @Override // public boolean isInvalid() { // return false; // } @Override public boolean oclEquals(@NonNull OCLValue thatValue) { if (!(thatValue instanceof Type)) { return false; } TypeId thisTypeId = getTypeId(); TypeId thatTypeId = ((Type)thatValue).getTypeId(); return thisTypeId.equals(thatTypeId); } @Override public int oclHashCode() { return getTypeId().hashCode(); } // @Override // @NonNull // public List<? extends Constraint> getOwnedRule() { // throw new UnsupportedOperationException(); // FIXME // } public org.eclipse.ocl.pivot.Package getPackage() { throw new UnsupportedOperationException(); // FIXME } public @NonNull TemplateParameters getTypeParameters() { throw new UnsupportedOperationException(); // FIXME } } //TypeImpl