| /******************************************************************************* |
| * Copyright (c) 2015 Zeligsoft (2009) Limited 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 |
| *******************************************************************************/ |
| |
| package org.eclipse.papyrusrt.codegen.xtumlrt.trans |
| |
| import java.io.IOException |
| import java.nio.file.Path |
| import java.nio.file.Paths |
| import java.util.Collection |
| import java.util.Collections |
| import java.util.List |
| import java.util.Set |
| |
| import com.google.common.collect.BiMap |
| import com.google.common.collect.HashBiMap |
| import org.eclipse.core.runtime.IStatus |
| import org.eclipse.core.runtime.MultiStatus |
| import org.eclipse.emf.common.util.URI |
| import org.eclipse.emf.ecore.EObject |
| import org.eclipse.emf.ecore.resource.Resource |
| import org.eclipse.emf.ecore.resource.ResourceSet |
| import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl |
| import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl |
| import org.eclipse.papyrus.umlrt.UMLRealTime.RTMessageKind |
| import org.eclipse.papyrusrt.codegen.CodeGenPlugin |
| import org.eclipse.papyrusrt.codegen.utils.UML2CppUtil |
| import org.eclipse.papyrusrt.xtumlrt.common.Attribute |
| import org.eclipse.papyrusrt.xtumlrt.common.Capsule |
| import org.eclipse.papyrusrt.xtumlrt.common.CapsuleKind |
| import org.eclipse.papyrusrt.xtumlrt.common.CapsulePart |
| import org.eclipse.papyrusrt.xtumlrt.common.CommonFactory |
| import org.eclipse.papyrusrt.xtumlrt.common.Connector |
| import org.eclipse.papyrusrt.xtumlrt.common.ConnectorEnd |
| import org.eclipse.papyrusrt.xtumlrt.common.DirectionKind |
| import org.eclipse.papyrusrt.xtumlrt.common.Entity |
| import org.eclipse.papyrusrt.xtumlrt.common.Model |
| import org.eclipse.papyrusrt.xtumlrt.common.MultiplicityElement |
| import org.eclipse.papyrusrt.xtumlrt.common.NamedElement |
| import org.eclipse.papyrusrt.xtumlrt.common.Operation |
| import org.eclipse.papyrusrt.xtumlrt.common.Package |
| import org.eclipse.papyrusrt.xtumlrt.common.Parameter |
| import org.eclipse.papyrusrt.xtumlrt.common.Port |
| import org.eclipse.papyrusrt.xtumlrt.common.PrimitiveType |
| import org.eclipse.papyrusrt.xtumlrt.common.Protocol |
| import org.eclipse.papyrusrt.xtumlrt.common.ProtocolBehaviourFeatureKind |
| import org.eclipse.papyrusrt.xtumlrt.common.RedefinableElement |
| import org.eclipse.papyrusrt.xtumlrt.common.Signal |
| import org.eclipse.papyrusrt.xtumlrt.common.StateMachine |
| import org.eclipse.papyrusrt.xtumlrt.common.StructMember |
| import org.eclipse.papyrusrt.xtumlrt.common.StructType |
| import org.eclipse.papyrusrt.xtumlrt.common.Type |
| import org.eclipse.papyrusrt.xtumlrt.common.TypeDefinition |
| import org.eclipse.papyrusrt.xtumlrt.common.VisibilityKind |
| import org.eclipse.papyrusrt.xtumlrt.umlrt.PortRegistration |
| import org.eclipse.papyrusrt.xtumlrt.umlrt.RTPassiveClass |
| import org.eclipse.papyrusrt.xtumlrt.umlrt.RTPort |
| import org.eclipse.papyrusrt.xtumlrt.umlrt.UmlrtFactory |
| import static extension org.eclipse.papyrusrt.codegen.utils.UMLRealTimeProfileUtil.* |
| import static extension org.eclipse.papyrusrt.codegen.utils.GeneralUtil.* |
| import org.eclipse.emf.common.util.Enumerator |
| |
| /** |
| * This class translates models from the UML2 meta-model (org.eclipse.uml2) into the xtUMLrt |
| * meta-model (org.eclipse.papyrusrt.xtumlrt). |
| * |
| * <p>Each element is mapped to the corresponding element by a method. There are a few cases where |
| * the same input element may be mapped into more than one kind of output element. For example |
| * a UML2 Package may be mapped to an xtUMLrt Package, but a UML2 Package which is a protocol |
| * container, as defined in the UML-RT profile, is mapped to an xtUMLrt protocol. Similarly, |
| * a UML2 Class may be mapped to a Capsule, an rtPassiveClass or a xtClass. In these cases, the |
| * output type of the corresponding method is the least-common ancestor in the (meta-class) |
| * type hierarchy. |
| * |
| * <p>The translation is recursive on the structure of elements, this is, the translation of |
| * composite elements (elements which may contain other elements), also translates its |
| * contained elements. This rule applies not only for "Composition" references: for example, |
| * when translating a capsule, we need to translate its ports, which have a protocol as type, |
| * so we need to get the translation of the protocol as well, even though it is not owned by |
| * neither the port nor the capsule. In order to avoid translating the same elements twice, and |
| * to avoid generation cycles, many of these methods are 'create' methods, which only create |
| * the relevant element the first time and cache the result so that future invocations of the |
| * translate method return the same translated element. |
| * |
| * @author Ernesto Posse |
| */ |
| @SuppressWarnings( "deprecated" ) |
| class UML2xtumlrtModelTranslator extends UML2xtumlrtTranslator |
| { |
| |
| static val XTUMLRT_EXTENSION = "xtumlrt" |
| List<EObject> targets |
| Path outputPath |
| BiMap<EObject, NamedElement> generated |
| Set<EObject> changed |
| UML2xtumlrtSMTranslator stateMachineTranslator |
| static val RTS_MODEL_LIB_CLASSES = |
| #[ |
| "UMLRTSignal", |
| "UMLRTMessage", |
| "UMLRTCommsPort", |
| "UMLRTCapsulePart", |
| "UMLRTCapsuleId", |
| "UMLRTTimerId", |
| "UMLRTTimeSpec" |
| ] |
| static val RTS_MODEL_LIB_PROTOCOLS = |
| #[ |
| "UMLRTBaseCommProtocol", |
| "UMLRTFrameProtocol", |
| "UMLRTLogProtocol", |
| "UMLRTTimerProtocol" |
| ] |
| static val RTS_MODEL_LIB_DATATYPES = |
| #[ |
| "UMLRTCommsPort", |
| "UMLRTCapsulePart" |
| ] |
| static val RTS_MODEL_LIB_ENUMS = |
| #[ |
| "Priorities" |
| ] |
| |
| new () |
| { |
| this.generated = HashBiMap.create |
| this.changed = newHashSet |
| this.stateMachineTranslator = new UML2xtumlrtSMTranslator( this ) |
| init |
| } |
| |
| new ( List<EObject> targets, Path outputPath ) |
| { |
| this() |
| this.targets = targets |
| this.outputPath = outputPath |
| } |
| |
| private static def init() |
| { |
| val registry = Resource.Factory.Registry.INSTANCE |
| registry.extensionToFactoryMap.put( XTUMLRT_EXTENSION, new XMIResourceFactoryImpl ) |
| } |
| |
| def setChangeSet( Collection<EObject> changedElements ) |
| { |
| changed.addAll( changedElements ) |
| } |
| |
| def setTargets( List<EObject> targets ) |
| { |
| this.targets = targets |
| } |
| |
| def setOutputPath( Path outputPath ) |
| { |
| this.outputPath = outputPath |
| } |
| |
| def IStatus generate() |
| { |
| var MultiStatus result = new MultiStatus( CodeGenPlugin.ID, IStatus.INFO, "UML-RT to xtUMLrt translator invoked", null ); |
| try |
| { |
| for (element : changed) |
| { |
| resetTranslateCache( element ) |
| } |
| var start = System.currentTimeMillis(); |
| for (target : targets) |
| { |
| if ( !(target instanceof org.eclipse.uml2.uml.Element) ) |
| { |
| result.add( CodeGenPlugin.info( "Ignoring element " + target.toString() + ": it is not a UML2 element." ) ) |
| } |
| else |
| { |
| generated.put( target, translate( target as org.eclipse.uml2.uml.Element ) as NamedElement ) |
| } |
| } |
| changed = newHashSet |
| result.add( CodeGenPlugin.info("Translated model to xtUMLrt sucessfully " + (System.currentTimeMillis() - start) + "ms") ) |
| } |
| catch (Exception e) |
| { |
| result.add( CodeGenPlugin.error("Error while translating model to xtUMLrt", e) ) |
| } |
| result |
| } |
| |
| def List<EObject> getAllGenerated() |
| { |
| generated.values.map[ it as EObject ].toList |
| } |
| |
| def NamedElement getGenerated( EObject eObject ) |
| { |
| generated.get( eObject ) |
| } |
| |
| def EObject getSource( NamedElement element ) |
| { |
| generated.inverse.get( element ) |
| } |
| |
| def boolean write() |
| { |
| var boolean success = true |
| val ResourceSet resourceSet = new ResourceSetImpl |
| for (target : targets) |
| { |
| val uri = target.eResource().getURI(); |
| val elementPath = Paths.get( uri.path() ); |
| val fileName = elementPath.fileName.toString |
| val fileNameWithoutExt = fileName.substring(0, fileName.lastIndexOf('.')) |
| val newFileName = fileNameWithoutExt + "." + XTUMLRT_EXTENSION |
| val fullPath = outputPath.resolve( newFileName ).toString |
| val resource = resourceSet.createResource( URI.createFileURI( fullPath )) |
| resource.contents.add( generated.get( target ) ) |
| try |
| { |
| resource.save( Collections.EMPTY_MAP ) |
| } |
| catch (IOException e) |
| { |
| success = false |
| } |
| } |
| success |
| } |
| |
| override EObject translateElement( org.eclipse.uml2.uml.Element umlElement ) |
| { |
| val translated = translate( umlElement ) |
| if (!(translated instanceof EObject)) |
| throw new TranslationException( umlElement, "-", org.eclipse.uml2.uml.Element, EObject, umlElement.class, translated.class, "The result of translating this element did not yield an EMF object") |
| translated as EObject |
| } |
| |
| override def Enumerator translateKind( Enum<?> kind ) |
| { |
| val translated = translateEnum( kind ) |
| if (!(translated instanceof Enumerator)) |
| throw new TranslationException( kind, "-", Enum , Enumerator, kind.class, translated?.class, "The result of translating this element did not yield an EMF Enumerator") |
| translated as Enumerator |
| } |
| |
| |
| /** |
| * Sets the 'redefines' reference of a RedefinableElement in the target meta-model to the |
| * translation of the element it redefines (assuming it's only one at most). |
| * |
| * <p>This method does not create the RedefinableElement in the target meta-model. That |
| * instance is created by any of the other {@code translate} methods, and this one just |
| * updates the {@code refines} reference to the (translated) element being refined. |
| */ |
| protected def translateRedefinableElement |
| ( |
| org.eclipse.uml2.uml.RedefinableElement element, |
| RedefinableElement newElement |
| ) |
| { |
| if (element.redefinedElements !== null && !element.redefinedElements.empty) |
| { |
| val redefinedElement = element.redefinedElements.get(0) |
| newElement.redefines = translate( redefinedElement ) as RedefinableElement |
| } |
| } |
| |
| protected def translateMultiplicityElement |
| ( |
| org.eclipse.uml2.uml.MultiplicityElement element, |
| MultiplicityElement newElement |
| ) |
| { |
| newElement.unique = element.unique |
| newElement.ordered = element.ordered |
| newElement.lowerBound = element.lowerBound |
| newElement.upperBound = element.upperBound |
| } |
| |
| /** |
| * Translates a package. |
| * |
| * <p>In UML-RT, protocols are represented as a collection of elements (a collaboration, |
| * some interfaces, etc.) grouped together in a package container. This method decides |
| * whether it is dealing with a "normal" package, or a "protocol container" package, and |
| * invokes the relevant translation. |
| * |
| * @param packge - A {@link org.eclipse.uml2.uml.Package} |
| * @return Either an xtUMLrt {@link Package} or a {@link Protocol} if the input is a |
| * protocol container. |
| */ |
| dispatch def NamedElement |
| create |
| if (packge.isRTSModelLibraryProtocolContainer) |
| translateRTSLibraryProtocolContainer( packge ) |
| else if (packge instanceof org.eclipse.uml2.uml.Model) |
| translateModel( packge ) |
| else if (packge.isProtocolContainer) |
| translateProtocolContainer( packge ) |
| else |
| translatePackage( packge ) |
| translate( org.eclipse.uml2.uml.Package packge ) |
| { |
| name = packge.name |
| UML2xtumlrtCppProfileTranslator.translateStereotypedElement( packge, it ) |
| } |
| |
| def boolean isRTSModelLibraryProtocolContainer( org.eclipse.uml2.uml.Package packge ) |
| { |
| RTS_MODEL_LIB_PROTOCOLS.contains( packge.name ) |
| } |
| |
| protected def Protocol translateRTSLibraryProtocolContainer( org.eclipse.uml2.uml.Package packge ) |
| { |
| val it = CommonFactory.eINSTANCE.createProtocol |
| name = packge.name |
| it |
| } |
| |
| protected def Model translateModel( org.eclipse.uml2.uml.Model model ) |
| { |
| val it = CommonFactory.eINSTANCE.createModel |
| for (element : model.packagedElements) |
| { |
| if (element instanceof org.eclipse.uml2.uml.Class) |
| topEntities.addIfNotPresent( translate(element) as Entity ) |
| else if (element.isProtocolContainer) |
| topProtocols.addIfNotPresent( translate(element) as Protocol ) |
| else if (element instanceof org.eclipse.uml2.uml.DataType) |
| topTypedefinitions.addIfNotPresent( translateTypeDefinition(element) ) |
| else if (element instanceof org.eclipse.uml2.uml.Package) |
| rootPackages.addIfNotPresent( translate(element) as Package ) |
| } |
| it |
| } |
| |
| protected def Protocol translateProtocolContainer( org.eclipse.uml2.uml.Package packge ) |
| { |
| translate( packge.protocolCollaboration ) as Protocol |
| } |
| |
| protected def Package translatePackage( org.eclipse.uml2.uml.Package packge ) |
| { |
| val it = CommonFactory.eINSTANCE.createPackage |
| for (element : packge.packagedElements) |
| { |
| if (element instanceof org.eclipse.uml2.uml.Class) |
| entities.addIfNotPresent( translate(element) as Entity ) |
| else if (element.isProtocolContainer) |
| protocols.addIfNotPresent( translate(element) as Protocol ) |
| else if (element instanceof org.eclipse.uml2.uml.DataType) |
| typedefinitions.addIfNotPresent( translateTypeDefinition(element) ) |
| else if (element instanceof org.eclipse.uml2.uml.Package) |
| packages.addIfNotPresent( translate(element) as Package ) |
| } |
| it |
| } |
| |
| /** |
| * @param collaboration - A {@link org.eclipse.uml2.uml.Collaboration} |
| * @return A {@link Protocol} if the collaboration is a protocol, {@code null} otherwise |
| */ |
| dispatch def Protocol |
| create |
| if (collaboration.isRTSModelLibraryProtocol) |
| translateRTSModelLibraryProtocol( collaboration ) |
| else if (collaboration.isProtocol) |
| translateProtocol( collaboration ) |
| translate( org.eclipse.uml2.uml.Collaboration collaboration ) |
| { |
| name = collaboration.name |
| translateRedefinableElement( collaboration, it ) |
| } |
| |
| def boolean isRTSModelLibraryProtocol( org.eclipse.uml2.uml.Collaboration collaboration ) |
| { |
| RTS_MODEL_LIB_PROTOCOLS.contains( collaboration.name ) |
| } |
| |
| protected def translateRTSModelLibraryProtocol( org.eclipse.uml2.uml.Collaboration collaboration ) |
| { |
| translateProtocol( collaboration ) |
| } |
| |
| protected def Protocol translateProtocol( org.eclipse.uml2.uml.Collaboration collaboration ) |
| { |
| val it = CommonFactory.eINSTANCE.createProtocol |
| name = collaboration.name |
| for (iface : collaboration.allRealizedInterfaces) // Q: what's the difference between this and allImplementedInterfaces? |
| { |
| if (iface.isRTMessageSet) |
| { |
| val rtMsgKind = iface.getRTMessageSet.rtMsgKind |
| if (rtMsgKind == RTMessageKind.IN || rtMsgKind == RTMessageKind.IN_OUT) |
| { |
| for (operation : iface.ownedOperations) |
| { |
| protocolBehaviourFeatures.add( translate(operation) as Signal ) |
| } |
| } |
| } |
| } |
| for (iface : collaboration.allUsedInterfaces()) |
| { |
| if (iface.isRTMessageSet) |
| { |
| val rtMsgKind = iface.getRTMessageSet.rtMsgKind |
| if (rtMsgKind == RTMessageKind.OUT || rtMsgKind == RTMessageKind.IN_OUT) |
| { |
| for (operation : iface.ownedOperations) |
| { |
| protocolBehaviourFeatures.add( translate(operation) as Signal ) |
| } |
| } |
| } |
| } |
| it |
| } |
| |
| /** |
| * @param operation - A {@link org.eclipse.uml2.uml.Operation} |
| * @return A {@link Operation} |
| */ |
| dispatch def NamedElement |
| create |
| if (operation.interface.isRTMessageSet) |
| translateSignal( operation ) |
| else |
| translateOperation( operation ) |
| translate( org.eclipse.uml2.uml.Operation operation ) |
| { |
| name = operation.name |
| UML2xtumlrtCppProfileTranslator.translateStereotypedElement( operation, it ) |
| } |
| |
| protected def Operation translateOperation( org.eclipse.uml2.uml.Operation operation ) |
| { |
| val it = CommonFactory.eINSTANCE.createOperation |
| for (parameter : operation.ownedParameters) |
| { |
| parameters.add( translate(parameter) as Parameter ) |
| } |
| returnType = translateFeature( operation, "type", org.eclipse.uml2.uml.Type, Type ) as Type |
| val actionCode = CommonFactory.eINSTANCE.createActionCode |
| actionCode.source = UML2CppUtil.getCppCode( operation ) |
| body = actionCode |
| it |
| } |
| |
| protected def translateSignal( org.eclipse.uml2.uml.Operation operation ) |
| { |
| val it = CommonFactory.eINSTANCE.createSignal |
| for (parameter : operation.ownedParameters) |
| { |
| parameters.add( translate(parameter) as Parameter ) |
| } |
| if (operation.interface.isRTMessageSet) |
| { |
| val rtMsgKind = operation.interface.getRTMessageSet.rtMsgKind |
| switch (rtMsgKind) |
| { |
| case RTMessageKind.IN: kind = ProtocolBehaviourFeatureKind.IN |
| case RTMessageKind.OUT: kind = ProtocolBehaviourFeatureKind.OUT |
| case RTMessageKind.IN_OUT: kind = ProtocolBehaviourFeatureKind.INOUT |
| } |
| } |
| it |
| } |
| |
| /** |
| * @param klass - A {@link org.eclipse.uml2.uml.Class} |
| * @return An {@link Entity}: either a {@link Capsule}, {@link RTPassiveClass} or |
| * {@link xtClass}. |
| */ |
| dispatch def Type |
| create |
| if (klass.isRTSModelLibraryClass) |
| translateRTSModelLibraryClass( klass ) as PrimitiveType |
| else if (klass.isCapsule) |
| translateCapsule( klass ) as Entity |
| else |
| translateRTPassiveClass( klass ) as Entity |
| translate( org.eclipse.uml2.uml.Class klass ) |
| { |
| name = klass.name |
| UML2xtumlrtCppProfileTranslator.translateStereotypedElement( klass, it ) |
| } |
| |
| protected def boolean isRTSModelLibraryClass( org.eclipse.uml2.uml.Class klass ) |
| { |
| RTS_MODEL_LIB_CLASSES.contains( klass.name ) |
| } |
| |
| protected def translateRTSModelLibraryClass( org.eclipse.uml2.uml.Class klass ) |
| { |
| val it = CommonFactory.eINSTANCE.createPrimitiveType |
| name = klass.name |
| it |
| } |
| |
| protected def translateBasicClass( org.eclipse.uml2.uml.Class klass, Entity newClass ) |
| { |
| for (attribute : klass.ownedAttributes) |
| { |
| if (!attribute.isRTPort && !attribute.isCapsulePart) |
| newClass.attributes.add( translate(attribute) as Attribute ) |
| } |
| for (operation : klass.ownedOperations) |
| { |
| newClass.operations.add( translate(operation) as Operation ) |
| } |
| if (klass.ownedBehaviors !== null |
| && !klass.ownedBehaviors.empty |
| && klass.ownedBehaviors.get(0) instanceof org.eclipse.uml2.uml.StateMachine) |
| { |
| var org.eclipse.uml2.uml.StateMachine stateMachine = |
| klass.ownedBehaviors.get(0) as org.eclipse.uml2.uml.StateMachine |
| newClass.behaviour = translate( stateMachine ) as StateMachine |
| } |
| } |
| |
| protected def Capsule translateCapsule( org.eclipse.uml2.uml.Class klass ) |
| { |
| val it = CommonFactory.eINSTANCE.createCapsule |
| translateBasicClass( klass, it ) |
| translateRedefinableElement( klass, it ) |
| for (part : klass.capsuleParts) |
| { |
| parts.add( translate(part) as CapsulePart ) |
| } |
| for (port : klass.RTPorts) |
| { |
| ports.add( translate(port) as Port ) |
| } |
| for (connector : klass.RTConnectors) |
| { |
| connectors.add( translate(connector) as Connector ) |
| } |
| it |
| } |
| |
| protected def RTPassiveClass translateRTPassiveClass( org.eclipse.uml2.uml.Class klass ) |
| { |
| val it = UmlrtFactory.eINSTANCE.createRTPassiveClass |
| translateBasicClass( klass, it ) |
| translateRedefinableElement( klass, it ) |
| it |
| } |
| |
| /** |
| * @param property - A {@link org.eclipse.uml2.uml.Property} |
| * @return An {@link Attribute} or {@link CapsulePart} |
| */ |
| dispatch def NamedElement |
| create |
| { |
| val newProperty = |
| if (property.isCapsulePart) |
| translateCapsulePart( property ) |
| else if (property.isRTPort) |
| translateRTPort( property ) |
| else |
| translateAttribute( property ) |
| newProperty as NamedElement |
| } |
| translate( org.eclipse.uml2.uml.Property property ) |
| { |
| name = property.name |
| translateMultiplicityElement( property, it as MultiplicityElement ) |
| UML2xtumlrtCppProfileTranslator.translateStereotypedElement( property, it ) |
| } |
| |
| protected def Attribute translateAttribute( org.eclipse.uml2.uml.Property property ) |
| { |
| val it = CommonFactory.eINSTANCE.createAttribute |
| type = translateFeature( property, "type", org.eclipse.uml2.uml.Type, Type ) as Type |
| visibility = translateEnumFeature( property, "visibility", org.eclipse.uml2.uml.VisibilityKind, VisibilityKind ) as VisibilityKind |
| it |
| } |
| |
| protected def CapsulePart translateCapsulePart( org.eclipse.uml2.uml.Property property ) |
| { |
| val it = CommonFactory.eINSTANCE.createCapsulePart |
| type = translateFeature( property, "type", org.eclipse.uml2.uml.Class, Capsule ) as Capsule |
| if (property.lower == 0) |
| { |
| if (property.aggregation == org.eclipse.uml2.uml.AggregationKind.SHARED_LITERAL) |
| { |
| kind = CapsuleKind.PLUGIN |
| } |
| else |
| { |
| kind = CapsuleKind.OPTIONAL |
| } |
| } |
| else |
| { |
| kind = CapsuleKind.FIXED |
| } |
| it |
| } |
| |
| protected def Port translatePort( org.eclipse.uml2.uml.Property property ) |
| { |
| val it = CommonFactory.eINSTANCE.createPort |
| type = translateFeature( property, "type", org.eclipse.uml2.uml.Collaboration, Protocol ) as Protocol |
| conjugate = (property as org.eclipse.uml2.uml.Port).conjugated |
| it |
| } |
| |
| protected def RTPort translateRTPort( org.eclipse.uml2.uml.Property property ) |
| { |
| val it = UmlrtFactory.eINSTANCE.createRTPort |
| type = translateFeature( property, "type", org.eclipse.uml2.uml.Collaboration, Protocol ) as Protocol |
| conjugate = (property as org.eclipse.uml2.uml.Port).conjugated |
| val rtPort = property.getRTPort |
| if (rtPort !== null) |
| { |
| notification = rtPort.notification |
| publish = rtPort.publish |
| wired = rtPort.wired |
| switch ( rtPort.registration ) |
| { |
| case AUTOMATIC: registration = PortRegistration.AUTOMATIC |
| case APPLICATION: registration = PortRegistration.APPLICATION |
| case AUTOMATIC_LOCKED: registration = PortRegistration.APPLICATIONLOCKED |
| } |
| } |
| it |
| } |
| |
| /** |
| * @param connector - A {@link org.eclipse.uml2.uml.Connector} |
| * @return A {@link Connector} |
| */ |
| dispatch def Connector translate( org.eclipse.uml2.uml.Connector connector ) |
| { |
| val it = CommonFactory.eINSTANCE.createConnector |
| name = connector.name |
| for (end : connector.ends) |
| { |
| ends.add( translate(end) as ConnectorEnd ) |
| } |
| it |
| } |
| |
| /** |
| * @param connectorEnd - A {@link org.eclipse.uml2.uml.ConnectorEnd} |
| * @return A {@link ConnectorEnd} |
| */ |
| dispatch def ConnectorEnd translate( org.eclipse.uml2.uml.ConnectorEnd connectorEnd ) |
| { |
| val it = CommonFactory.eINSTANCE.createConnectorEnd |
| role = translateFeature( connectorEnd, "role", org.eclipse.uml2.uml.Port, Port ) as Port |
| partWithPort = |
| if (connectorEnd.partWithPort === null) |
| null |
| else |
| translateFeature( connectorEnd, "partWithPort", org.eclipse.uml2.uml.Property, CapsulePart ) as CapsulePart |
| it |
| } |
| |
| /** |
| * @param parameter - A {@link org.eclipse.uml2.uml.Parameter} |
| * @return A {@link Parameter} |
| */ |
| dispatch def Parameter |
| create CommonFactory.eINSTANCE.createParameter |
| translate( org.eclipse.uml2.uml.Parameter parameter ) |
| { |
| name = parameter.name |
| type = translateFeature( parameter, "type", org.eclipse.uml2.uml.Type, Type ) as Type |
| direction = translateEnumFeature( parameter, "direction", org.eclipse.uml2.uml.ParameterDirectionKind, DirectionKind ) as DirectionKind |
| UML2xtumlrtCppProfileTranslator.translateStereotypedElement( parameter, it ) |
| } |
| |
| /** |
| * @param type - A {@link org.eclipse.uml2.uml.DataType} |
| * @return A {@link StructType} or {@link PrimitiveType} |
| */ |
| dispatch def Type |
| create |
| if (dataType.isRTSModelLibraryDataType) |
| translateRTSModelLibraryDataType( dataType ) |
| else if (dataType instanceof org.eclipse.uml2.uml.PrimitiveType) |
| translatePrimitiveType( dataType ) |
| else |
| translateStructType( dataType ) |
| translate( org.eclipse.uml2.uml.DataType dataType ) |
| { |
| name = dataType.name |
| // Do not translate unknown types |
| } |
| |
| def boolean isRTSModelLibraryDataType( org.eclipse.uml2.uml.DataType dataType ) |
| { |
| RTS_MODEL_LIB_DATATYPES.contains( dataType ) |
| } |
| |
| protected def translateRTSModelLibraryDataType( org.eclipse.uml2.uml.DataType dataType ) |
| { |
| val it = CommonFactory.eINSTANCE.createPrimitiveType |
| name = dataType.name |
| it |
| } |
| |
| protected def PrimitiveType translatePrimitiveType |
| ( |
| org.eclipse.uml2.uml.PrimitiveType primitiveType |
| ) |
| { |
| val newType = CommonFactory.eINSTANCE.createPrimitiveType |
| switch (primitiveType) |
| { |
| case org.eclipse.uml2.types.TypesPackage.eINSTANCE.boolean: newType.name = "Boolean" |
| case org.eclipse.uml2.types.TypesPackage.eINSTANCE.integer: newType.name = "Integer" |
| case org.eclipse.uml2.types.TypesPackage.eINSTANCE.string: newType.name = "String" |
| case org.eclipse.uml2.types.TypesPackage.eINSTANCE.real: newType.name = "Real" |
| case org.eclipse.uml2.types.TypesPackage.eINSTANCE.unlimitedNatural: newType.name = "UnlimitedNatural" |
| default: newType.name = primitiveType.name |
| } |
| newType |
| } |
| |
| protected def StructType translateStructType |
| ( |
| org.eclipse.uml2.uml.DataType dataType |
| ) |
| { |
| val newType = CommonFactory.eINSTANCE.createStructType |
| for ( attr : dataType.getAllAttributes ) |
| { |
| newType.structMembers.add( translateStructMember( attr ) ) |
| } |
| newType |
| } |
| |
| protected def StructMember translateStructMember |
| ( |
| org.eclipse.uml2.uml.Property attribute |
| ) |
| { |
| val member = CommonFactory.eINSTANCE.createStructMember |
| member.name = attribute.name |
| member.type = translateFeature( attribute ,"type", org.eclipse.uml2.uml.Type, Type ) as Type |
| member |
| } |
| |
| /** |
| * @param type - A {@link org.eclipse.uml2.uml.Type} |
| * @return A {@link Type} |
| */ |
| dispatch def Type translate( org.eclipse.uml2.uml.Type type ) |
| { |
| // Do not translate unknown types |
| } |
| |
| protected def |
| create CommonFactory.eINSTANCE.createTypeDefinition |
| translateTypeDefinition( org.eclipse.uml2.uml.DataType dataType ) |
| { |
| type = translate( dataType ) as Type |
| } |
| |
| |
| /** |
| * @param stateMachine - A {@link org.eclipse.uml2.uml.StateMachine} |
| * @return A {@link StateMachine} |
| */ |
| dispatch def StateMachine translate( org.eclipse.uml2.uml.StateMachine stateMachine ) |
| { |
| stateMachineTranslator.translateStateMachine( stateMachine ) |
| } |
| |
| /** |
| * @param visibilityKind - A {@link org.eclipse.uml2.uml.VisibilityKind} |
| * @return The corresponding {@link VisibilityKind} |
| */ |
| dispatch def translateEnum( org.eclipse.uml2.uml.VisibilityKind visibilityKind ) |
| { |
| switch (visibilityKind) |
| { |
| case org.eclipse.uml2.uml.VisibilityKind.PUBLIC_LITERAL: VisibilityKind.PUBLIC |
| case org.eclipse.uml2.uml.VisibilityKind.PRIVATE_LITERAL: VisibilityKind.PRIVATE |
| case org.eclipse.uml2.uml.VisibilityKind.PROTECTED_LITERAL: VisibilityKind.PROTECTED |
| default: VisibilityKind.PUBLIC |
| } |
| } |
| |
| /** |
| * @param directionKind - A {@link org.eclipse.uml2.uml.ParameterDirectionKind} |
| * @return The corresponding {@link DirectionKind} |
| */ |
| dispatch def translateEnum |
| ( |
| org.eclipse.uml2.uml.ParameterDirectionKind directionKind |
| ) |
| { |
| switch (directionKind) |
| { |
| case org.eclipse.uml2.uml.ParameterDirectionKind.IN_LITERAL: DirectionKind.IN |
| case org.eclipse.uml2.uml.ParameterDirectionKind.OUT_LITERAL: DirectionKind.OUT |
| } |
| } |
| |
| /** |
| * @param behavior - A {@link org.eclipse.uml2.uml.Behavior} |
| * @return An {@link ActionCode} instance. |
| */ |
| protected def translateActionCode( org.eclipse.uml2.uml.Behavior behavior ) |
| { |
| val it = CommonFactory.eINSTANCE.createActionCode |
| source = UML2CppUtil.getCppCode( behavior ) |
| it |
| } |
| |
| |
| def resetTranslateCache( EObject element ) |
| { |
| val key = newArrayList( element ) |
| _createCache_translate.remove( key ) |
| } |
| |
| } |