| /***************************************************************************** |
| * Copyright (c) 2018 CEA LIST. |
| * |
| * |
| * 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 |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * Ansgar Radermacher ansgar.radermacher@cea.fr |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.robotics.transformation.ros2.library.xtend |
| |
| import org.eclipse.uml2.uml.Package |
| import org.eclipse.papyrus.robotics.transformation.ros2.library.preferences.Ros2PreferenceUtils |
| import org.eclipse.papyrus.robotics.bpc.profile.bpc.Entity |
| import org.eclipse.uml2.uml.util.UMLUtil |
| import org.eclipse.uml2.uml.Element |
| import org.eclipse.papyrus.robotics.bpc.profile.bpc.BPCPackage |
| import org.eclipse.emf.ecore.EAttribute |
| |
| /** |
| * Set of utility functions for package creation |
| */ |
| class PackageXMLUtils { |
| |
| /** |
| * get author name. If authorship is set, assume that it starts with an email address |
| */ |
| def static getAuthorName(Package model) { |
| val author = getField(model, BPCPackage.eINSTANCE.entity_Authorship); |
| if (author !== null) { |
| val idx = author.indexOf(" "); |
| if (idx > 0) { |
| return author.substring(idx + 1); |
| } |
| return author; |
| } |
| return Ros2PreferenceUtils.authorName; |
| } |
| |
| def static getAuthorMail(Package model) { |
| val author = getField(model, BPCPackage.eINSTANCE.entity_Authorship); |
| if (author !== null) { |
| val idx = author.indexOf(" "); |
| if (idx > 0) { |
| return author.substring(0, idx); |
| } |
| return author; |
| } |
| return Ros2PreferenceUtils.authorName; |
| } |
| |
| def static getMaintainerName(Package model) { |
| val maintainer = getField(model, BPCPackage.eINSTANCE.entity_Provenance); |
| if (maintainer !== null) { |
| val idx = maintainer.indexOf(" "); |
| if (idx > 0) { |
| return maintainer.substring(idx + 1); |
| } |
| return maintainer; |
| } |
| return Ros2PreferenceUtils.maintainerName; |
| } |
| |
| def static getMaintainerMail(Package model) { |
| val maintainer = getField(model, BPCPackage.eINSTANCE.entity_Provenance); |
| if (maintainer !== null) { |
| val idx = maintainer.indexOf(" "); |
| if (idx > 0) { |
| return maintainer.substring(0, idx); |
| } |
| return maintainer; |
| } |
| return Ros2PreferenceUtils.maintainerMail; |
| } |
| |
| /** |
| * return the first occurrence of the non-null field (author or maintainer) in the |
| * ownership tree |
| * |
| * @param element |
| * a UML element |
| * @param clazz |
| * The stereotype in form of a class (static profile) |
| * @return the author information |
| */ |
| def static String getField(Element element, EAttribute feature) { |
| val application = UMLUtil.getStereotypeApplication(element, Entity); |
| if (application !== null && application.eGet(feature) !== null) { |
| return application.authorship; |
| } else { |
| val owner = element.getOwner(); |
| if (owner !== null) { |
| return getField(owner, feature); |
| } else { |
| return null; |
| } |
| } |
| } |
| } |