diff options
Diffstat (limited to 'sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse')
34 files changed, 0 insertions, 6734 deletions
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/Activator.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/Activator.java deleted file mode 100644 index c71297b931b..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/Activator.java +++ /dev/null @@ -1,172 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2008 CEA LIST. - * - * - * 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: - * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.utils; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.papyrus.infra.core.log.LogHelper; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle. - */ -public class Activator extends Plugin { - - // The plug-in ID - /** - * - */ - public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.tools.utils"; - - // The shared instance - /** - * - */ - private static Activator plugin; - - // Resource bundle. - /** - * - */ - private ResourceBundle resourceBundle; - - public static LogHelper log; - - /** - * The constructor. - */ - public Activator() { - plugin = this; - try { - resourceBundle = ResourceBundle.getBundle("com.cea.papyrus.umlutils.PluginManagerResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) - */ - /** - * - * - * @param context - * - * @throws Exception - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - log = new LogHelper(this); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) - */ - /** - * - * - * @param context - * - * @throws Exception - */ - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance. - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - /** - * Returns the string from the plugin's resource bundle, or 'key' if not found. - * - * @param key - * - * @return - */ - public static String getResourceString(String key) { - ResourceBundle bundle = Activator.getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key) : key; - } catch (MissingResourceException e) { - return key; - } - } - - /** - * Returns the plugin's resource bundle,. - * - * @return - */ - public ResourceBundle getResourceBundle() { - return resourceBundle; - } - - /** - * Logs a warning message in the plugin log - * - * @param message - * the message to log - */ - public static void logWarning(String message) { - getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an error message in the plugin log - * - * @param message - * the message to log - */ - public static void logError(String message) { - getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an information message in the plugin log - * - * @param message - * the message to log - */ - public static void logInfo(String message) { - getDefault().getLog().log(new Status(IStatus.INFO, Activator.PLUGIN_ID, message)); - } - - /** - * Logs an error message in the plugin log - * - * @param exception - * the exception to log - */ - public static void logException(Exception exception) { - getDefault().getLog().log( - new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getLocalizedMessage(), exception)); - } -} diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityUtil.java deleted file mode 100644 index ef4bf5e1620..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ActivityUtil.java +++ /dev/null @@ -1,69 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Activity;
-import org.eclipse.uml2.uml.ActivityEdge;
-import org.eclipse.uml2.uml.ActivityNode;
-import org.eclipse.uml2.uml.ControlFlow;
-import org.eclipse.uml2.uml.InitialNode;
-
-/**
- * This class encapsulates an <code>org.eclipse.uml2.uml.Activity</code><BR>
- */
-
-public class ActivityUtil {
-
- /**
- * Returns the uml2Activity's initial node. We consider that there is at most one initial node
- * in an activity.
- *
- * @param uml2Activity
- * investigated
- * @return the initial node of uml2Activity, null otherwise.
- */
- // @unused
- public static InitialNode getInitialNode(Activity uml2Activity) {
- Iterator<ActivityNode> nodesIter = uml2Activity.getNodes().iterator();
- while(nodesIter.hasNext()) {
- ActivityNode currentNode = nodesIter.next();
- if(currentNode instanceof InitialNode)
- return (InitialNode)currentNode;
- }
- return null;
- }
-
- /**
- * Returns the activity node that is connected to uml2ActivityNode by a control flow. We
- * consider that there is at most one outgoing control flow from an activity node (first one
- * found is returned).
- *
- * @param uml2ActivityNode
- * origin node
- * @return next node of uml2ActivityNode, null otherwise.
- */
- // @unused
- public static ActivityNode getNextNode(ActivityNode uml2ActivityNode) {
- Iterator<ActivityEdge> edgeIter = uml2ActivityNode.getOutgoings().iterator();
- while(edgeIter.hasNext()) {
- ActivityEdge currentEdge = edgeIter.next();
- if(currentEdge instanceof ControlFlow)
- return currentEdge.getTarget();
- }
- return null;
- }
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java deleted file mode 100644 index 3f256a7d23c..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CollaborationUseUtil.java +++ /dev/null @@ -1,85 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.CollaborationUse;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.CollaborationUse</code><BR>
- */
-public class CollaborationUseUtil {
-
- public final static String UNDEFINED_TYPE_NAME = "<Undefined>";
-
- /**
- * return the full label of the CollaborationUse, given UML2 specification.
- *
- * @return the string corresponding to the label of the CollaborationUse
- */
- public static String getLabel(CollaborationUse collaborationUse) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse));
-
- // name
- buffer.append(" ");
- buffer.append(collaborationUse.getName());
-
- // type
- if(collaborationUse.getType() != null) {
- buffer.append(": " + collaborationUse.getType().getName());
- } else {
- buffer.append(": " + UNDEFINED_TYPE_NAME);
- }
-
- return buffer.toString();
- }
-
- /**
- * return the custom label of the CollaborationUse, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the CollaborationUse
- */
- public static String getCustomLabel(CollaborationUse collaborationUse, int style) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(collaborationUse));
- }
-
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(" ");
- buffer.append(collaborationUse.getName());
- }
-
- if((style & ICustomAppearence.DISP_TYPE) != 0) {
- // type
- if(collaborationUse.getType() != null) {
- buffer.append(": " + collaborationUse.getType().getName());
- } else {
- buffer.append(": " + UNDEFINED_TYPE_NAME);
- }
- }
-
- return buffer.toString();
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java deleted file mode 100644 index 786a3eea939..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ControlFlowUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.Activity;
-import org.eclipse.uml2.uml.ActivityNode;
-import org.eclipse.uml2.uml.ControlFlow;
-import org.eclipse.uml2.uml.InitialNode;
-import org.eclipse.uml2.uml.ObjectFlow;
-
-
-/**
- * Utility class for {@link ObjectFlow}
- */
-public class ControlFlowUtil {
-
- /**
- * Check condition on control flows
- * @param container container of the object flow
- * @param linkInstance object flow itself
- * @param source
- * @param target
- * @return
- */
- public static boolean canExistControlFlow(Activity container, ControlFlow linkInstance, ActivityNode source, ActivityNode target) {
- try {
- if(target instanceof InitialNode) {
- return false;
- }
- return true;
- } catch (Exception e) {
- Activator.log.error(e);
- return false;
- }
- }
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/DataTypeUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/DataTypeUtil.java deleted file mode 100644 index 1452b39bdec..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/DataTypeUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.util.UMLUtil;
-
-
-/**
- * this class contains util methods about UML DataType
- *
- */
-public class DataTypeUtil {
-
- /**
- * test if the eclass is a definition of a dataType
- * @param eclass the eclass that will be tested
- * @return true if this is a definition of a DataType else false
- */
- public static boolean isDataTypeDefinition(EClass eclass){
- if(eclass.getEAnnotations().size() > 0) {
- UMLPackage.eINSTANCE.getNsURI();
- EAnnotation eAnnotation = eclass.getEAnnotation(UMLUtil.UML2_UML_PACKAGE_2_0_NS_URI);
- if(eAnnotation!=null) {
- if((eAnnotation.getReferences().get(0) instanceof org.eclipse.uml2.uml.DataType)) {
- return true;
- }
- }
-
- }
- return false;
-
- }
-}
\ No newline at end of file diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java deleted file mode 100644 index f2d17196218..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ElementUtil.java +++ /dev/null @@ -1,411 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2009 CEA LIST. - * - * - * 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: - * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.utils; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.emf.common.util.BasicEList; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.common.util.WrappedException; -import org.eclipse.emf.ecore.EClass; -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.util.EcoreUtil; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.ElementImport; -import org.eclipse.uml2.uml.Image; -import org.eclipse.uml2.uml.Package; -import org.eclipse.uml2.uml.PackageImport; -import org.eclipse.uml2.uml.Stereotype; -import org.eclipse.uml2.uml.Type; -import org.eclipse.uml2.uml.UMLPackage; -import org.eclipse.uml2.uml.resource.UMLResource; -import org.eclipse.uml2.uml.util.UMLUtil; - -public class ElementUtil { - - - /** - * Check if the StereotypedElement has the given stereotype, or if one of - * its stereotype is inherits from the stereotype passed in parameter. This - * method currently exists in UMLUtils, this one is a copy created to avoid - * some dependencies propagated by UMLUtils (jface...). Current UMLUtils - * plug-in should probably be separated into two parts one depending on UML2 - * plug-in only, and the other bringing ui related features; - * - * @deprecated prefer using {@link UMLUtil#getStereotypeApplication(Element, Class)} - */ - @Deprecated - public static EObject hasStereotype(Element elt, EClass stereotypeClass) { - return UMLUtil.getStereotypeApplication(elt, stereotypeClass.getClass()); - } - - /** - * Convenient method to retrieve the StereotypeApplication by passing an - * element of the static profile. - * - * @deprecated prefer using {@link UMLUtil#getStereotypeApplication(Element, Class)} - */ - @Deprecated - public static <T extends EObject> T getStereotypeApplication(Element element, java.lang.Class<T> clazz) { - return UMLUtil.getStereotypeApplication(element, clazz); - } - - /** - * Getter to select an image for a stereotyped element (based on 1st applied stereotype) - * - * @param element - * the element for which we are looking the icon - * @param stereotype - * the stereotype that should have the icon - * @param kind - * kind of display, should be <code>"icon"</code> or <code>"shape"</code> - * @return the image corresponding to the stereotype or <code>null</code> if no image can be - * found - */ - public static Image getStereotypeImage(Element element, Stereotype stereotype, String kind) { - if(stereotype == null || element.getAppliedStereotypes() == null) { - return null; - } - - Image image = null; - - // Try to retrieve image based on getter implemented in static profile - image = ElementUtil.getStereotypeImageFromGetter(element, stereotype, kind); - - if(image == null) { - // No image found by getters - // Search for the image verifying expressions - EList<Image> availableImages = new BasicEList<Image>(); - if("icon".equals(kind)) { - availableImages = StereotypeUtil.getIcons(stereotype); - } else if("shape".equals(kind)) { - availableImages = StereotypeUtil.getShapes(stereotype); - } - - if(!(availableImages).isEmpty()) { - // Retrieve first image verifying expression or - // first image if no expression is verified - image = ImageUtil.findImageVerifyingExpression(element, availableImages); - - if(image == null) { - image = availableImages.get(0); - } - } - } - - return image; - } - - /** - * Getter to select an image for a stereotyped element (based on 1st applied stereotype) - * - * @param element - * to check - * @param kind - * of image ("icon" | "shape") - * @return {@link Image} or null - */ - public static Image getStereotypeImage(Element element, String kind) { - // Get first stereotype - if(element.getAppliedStereotypes() == null || element.getAppliedStereotypes().isEmpty()) { - return null; // null - } - - // The image is one of the 1st stereotype - Stereotype stereotype = element.getAppliedStereotypes().get(0); - - return getStereotypeImage(element, stereotype, kind); - } - - /** - * Find the image using a getter implemented in a static profile - * - * @param element - * the stereotyped element - * @param stereotype - * the applied stereotype - * @param kind - * the kind of searched image ("icon" | "shape") - * @return {@link Image} or null - */ - public static Image getStereotypeImageFromGetter(Element element, Stereotype stereotype, String kind) { - - // Prepare getter method name - String getterName = ""; - if("icon".equals(kind)) { - getterName += "getIcon"; - - } else if("shape".equals(kind)) { - getterName += "getShape"; - - } else { - // Unknown kind : abort and return null (no image) - return null; - } - - // If the getter is implemented, it is implemented by the - // StereotypeApplication class - EObject stApp = element.getStereotypeApplication(stereotype); - Method getter = null; - try { - getter = stApp.getClass().getDeclaredMethod(getterName); - } catch (Exception e) { - // Implementation not found - } - - // If the getter exists, invoke - if(getter != null) { - try { - - // Retrieve image via getter in static profile - Image image = (Image)getter.invoke(stApp); - - return image; - - } catch (Exception e) { - // Invoke getter has failed - return null; - } - } - - return null; - } - - /** - * Test if the element has stereotype icons to display - * - * @param element - * the element for which icon are searched - * @return <code>true</code> if icons were found - */ - public static boolean hasIcons(Element element) { - if(!element.getAppliedStereotypes().isEmpty()) { - return hasIcons(element, element.getAppliedStereotypes().get(0)); - } - return false; - } - - /** - * Test if the element has icons for the given stereotype - * - * @param stereotype - * the stereotype we check to see if it has icon or not - * @param element - * the stereotyped element - * @return <code>true</code> if icons were found - */ - public static boolean hasIcons(Element element, Stereotype stereotype) { - return stereotype != null && !StereotypeUtil.getIcons(stereotype).isEmpty(); - } - - /** - * Test if the element has stereotype shape to display - * - * @param element - * the element for which shape are searched - * @return <code>true</code> if shape were found - */ - // @unused - public static boolean hasShapes(Element element) { - if(!element.getAppliedStereotypes().isEmpty()) { - return hasShapes(element, element.getAppliedStereotypes().get(0)); - } - return false; - } - - /** - * Test if the stereotype has shapes - * - * @param stereotype - * @return true if shapes were found - */ - public static boolean hasShapes(Element element, Stereotype stereotype) { - return stereotype != null && !StereotypeUtil.getShapes(stereotype).isEmpty(); - } - - /** - * look for all metaclasses of the meta model UML2 for a profile. - * - * @param element - * the profile which needs the metaclasses list - * @return the possible metaclasses - */ - // @unused - public static List<org.eclipse.uml2.uml.Class> getPossibleMetaclasses(Element element) { - List<org.eclipse.uml2.uml.Class> metaList = new ArrayList<org.eclipse.uml2.uml.Class>(); - List<Type> metaclasses = getMetaclasses(element); // get all type of the - // metaclass - - for(int i = 0; i < metaclasses.size(); i++) { - if(metaclasses.get(i) instanceof org.eclipse.uml2.uml.Class) { - metaList.add((org.eclipse.uml2.uml.Class)metaclasses.get(i)); - } - } - - return metaList; - } - - /** - * return all type contained in the metamodel UML2. Elements in the list are the UML2 - * representation of the concepts of the metamodel. each element of the list must be casted with - * org.eclipse.uml2.Classifier - * - * @return list of metaclasses of the metamodel UML2 - */ - public static List<Type> getMetaclasses(Element element) { - if(element == null) { - System.err.println("element should not be null to retrieve metaclasses"); - } - org.eclipse.uml2.uml.Package uml2Metamodel = contentload(URI.createURI(UMLResource.UML_METAMODEL_URI), element); - - return uml2Metamodel.getOwnedTypes(); - } - - /** - * Loads content for the given URI, and returns the top package of this content. - * - * @param uri - * the uri of the content to load - * @param element - * the Element used to retrieve ResourceSet - * @return the top package of the loaded content - */ - public static org.eclipse.uml2.uml.Package contentload(URI uri, Element element) { - ResourceSet resourceSet = element.eResource().getResourceSet(); - org.eclipse.uml2.uml.Package package_ = null; - try { - Resource resource = resourceSet.getResource(uri, true); - - package_ = (org.eclipse.uml2.uml.Package)EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.eINSTANCE.getPackage()); - } catch (WrappedException we) { - Activator.logError("impossible to load content for URI: " + uri); - } - - return package_; - } - - /** - * Retrieve an list of all instances in the model that are instances of - * the java.lang.Class metaType or with a stereotype applied - * - * @param <T> - * - * @param metaType - * selected classes - * @param model - * to check - * @param appliedStereotype - * may be null, metatype is ignored if not null - * @return a list containing the selected instances - */ - //duplicated code from /org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/Util.java - //+add template to this method - @SuppressWarnings("unchecked") - public static final <T extends EObject> List<T> getInstancesFilteredByType(final Package topPackage, final java.lang.Class<T> metaType, final Stereotype appliedStereotype) { - // retrieve parent element - // Package topPackage = Util.topPackage(element); - // Assert.isNotNull(topPackage, - // "Top package should not be null for element " + element); - Iterator<EObject> iter = topPackage.eAllContents(); - List<T> filteredElements = new ArrayList<T>(); - - while(iter.hasNext()) { - EObject currentElt = iter.next(); - - // If currentElt is an ElementImport, it is replaced by the imported - // Element. - if(currentElt instanceof ElementImport) { - ElementImport elementImport = (ElementImport)currentElt; - currentElt = elementImport.getImportedElement(); - } - - /* package imports treatment */ - else if(currentElt instanceof PackageImport) { - Iterator<EObject> piIter = ((PackageImport)currentElt).getImportedPackage().eAllContents(); - while(piIter.hasNext()) { - EObject piCurrentElt = piIter.next(); - if(piCurrentElt instanceof Element) { - if(appliedStereotype != null) { - - Iterator<Stereotype> appStIter = ((Element)piCurrentElt).getAppliedStereotypes().iterator(); - while(appStIter.hasNext()) { - Stereotype currentSt = (Stereotype)appStIter.next(); - - if(currentSt.conformsTo(appliedStereotype)) { - filteredElements.add((T)piCurrentElt); - } - } - - } else { // if (appliedStereotype == null) - if(metaType.isInstance(piCurrentElt)) { - filteredElements.add((T)piCurrentElt); - } - - /** add imported meta elements */ - else if(piCurrentElt instanceof ElementImport) { - Iterator<EObject> eIter = ((ElementImport)piCurrentElt).getImportedElement().eAllContents(); - while(eIter.hasNext()) { - EObject currentEIelt = eIter.next(); - if(metaType.isInstance(currentEIelt)) - filteredElements.add((T)currentEIelt); - } - } - } - } - - } - } - - // Filtering elements - if(currentElt instanceof Element) { - - if(appliedStereotype != null) { - - Iterator<Stereotype> appStIter = ((Element)currentElt).getAppliedStereotypes().iterator(); - while(appStIter.hasNext()) { - Stereotype currentSt = (Stereotype)appStIter.next(); - - if(currentSt.conformsTo(appliedStereotype)) { - filteredElements.add((T)currentElt); - } - } - - } else { // if (appliedStereotype == null) - if(metaType.isInstance(currentElt)) { - filteredElements.add((T)currentElt); - } - - /** add imported meta elements */ - else if(currentElt instanceof ElementImport) { - Iterator<EObject> eIter = ((ElementImport)currentElt).getImportedElement().eAllContents(); - while(eIter.hasNext()) { - EObject currentEIelt = eIter.next(); - if(metaType.isInstance(currentEIelt)) - filteredElements.add((T)currentEIelt); - } - } - } - } - } - - return filteredElements; - } - -} diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java deleted file mode 100644 index 6a7e31f10c2..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/EnumerationUtil.java +++ /dev/null @@ -1,118 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.common.util.Enumerator;
-import org.eclipse.emf.ecore.EEnum;
-import org.eclipse.emf.ecore.EEnumLiteral;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.uml2.uml.Enumeration;
-import org.eclipse.uml2.uml.EnumerationLiteral;
-
-/**
- *
- * This class provides utilities for Enum
- *
- */
-public class EnumerationUtil {
-
-
- private EnumerationUtil() {
- // to prevent instanciation
- }
-
- /**
- *
- * @param enumeration
- * the uml enumeration
- * @param enumerator
- * the enumerator to adapt to a uml EnumerationLiteral
- * @return
- */
- public static final EnumerationLiteral findEnumerationLiteral(final Enumeration enumeration, final Enumerator enumerator) {
- final EnumerationLiteral lit = enumeration.getOwnedLiteral(enumerator.getLiteral());
- if(lit != null) {
- return lit;
- }
- Activator.log.error(NLS.bind("The EnumerationLiteral for {0} has not been found", enumerator), new NullPointerException()); //$NON-NLS-1$
- return null;
- }
-
-
- /**
- *
- * @param enumeration
- * the uml enumeration
- * @param toAdapt
- * the list of the element to adapt to UML EnumerationLiteral
- * @return
- */
- public static final List<EnumerationLiteral> adaptToEnumerationLiteralList(final Enumeration enumeration, final Collection<?> toAdapt) {
- final List<EnumerationLiteral> returnedValue = new ArrayList<EnumerationLiteral>();
- for(Object object : toAdapt) {
- if(object instanceof EnumerationLiteral) {
- returnedValue.add((EnumerationLiteral)object);
- } else if(object instanceof Enumerator) {
- returnedValue.add(EnumerationUtil.findEnumerationLiteral(enumeration, (Enumerator)object));
- }
- }
- assert returnedValue.size() == toAdapt.size();
- return returnedValue;
- }
-
- /**
- *
- * @param eenum
- * an eemf enumeration
- * @param toConvert
- * a list of enumeration literal to convert
- * @return
- * the list of the converted element (/!\ in case of fail, the returned list contains less elements than the initial list)
- */
- public static final List<Enumerator> adaptToEnumeratorList(final EEnum eenum, final Collection<?> toConvert) {
- final List<Enumerator> convertedvalues = new ArrayList<Enumerator>();
- for(final Object object : toConvert) {
- if(object instanceof EnumerationLiteral) {
- final EEnumLiteral literal = eenum.getEEnumLiteral(((EnumerationLiteral)object).getName());
- if(literal != null) {
- convertedvalues.add(literal.getInstance());
- }
- }
- }
- return convertedvalues;
-
- }
-
- /**
- *
- * @param eenum
- * an emf enumeration
- * @param umlLiteral
- * a uml literal
- * @return
- * the enumerator to use for this enumeration literal (/!\ can be null in case of fail)
- */
- public static final Enumerator adaptToEnumerator(final EEnum eenum, final EnumerationLiteral umlLiteral) {
- final EEnumLiteral literal = eenum.getEEnumLiteral(umlLiteral.getName());
- if(literal != null) {
- return literal.getInstance();
- }
- return null;
- }
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExecutionSpecificationUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExecutionSpecificationUtil.java deleted file mode 100644 index 912376d6bdd..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExecutionSpecificationUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.Lifeline;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Executionspecification</code><BR>
- */
-public class ExecutionSpecificationUtil {
-
- /**
- * Retrieve the Lifeline associated with an ExecutionSpecification.
- * According to the UML Specification, an ExecutionSpecification must have a start and a finish.
- *
- * In Papyrus, an ExecutionSpecification may not have a start and finish.
- * To handle this specific case, we return the first Lifeline that the ES covered.
- *
- * @param es
- * the targeted execution specification
- * @return the associated Lifeline, or null if the ES has no start, no finish, no covered Lifeline.
- */
- public static Lifeline getExecutionSpecificationLifeline(ExecutionSpecification es) {
- Lifeline lifeline = null;
- if(es.getStart() != null) {
- lifeline = es.getStart().getCovereds().get(0);
- } else if(es.getFinish() != null) {
- lifeline = es.getFinish().getCovereds().get(0);
- }
-
- if(lifeline == null) {
- if(!es.getCovereds().isEmpty()) {
- lifeline = es.getCovereds().get(0);
- }
- }
- return lifeline;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java deleted file mode 100644 index c63a0829680..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ExtensionPointUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.ExtensionPoint;
-
-/**
- * Utility class for {@link ExtensionPoint}
- */
-// @unused
-public class ExtensionPointUtil {
-
- /**
- * Returns the explanation for the extension point element
- *
- * @return the string defining explanation for the extension point element
- */
- // @unused
- public static String getExplanation(ExtensionPoint extensionPoint) {
- String explanation = "";
- final String name = ((extensionPoint.getName() != null) ? extensionPoint.getName() : "");
- int startIndexOfExplanation = name.lastIndexOf(":");
- if((startIndexOfExplanation > 0) && (startIndexOfExplanation != name.length())) {
- explanation = name.substring(startIndexOfExplanation + 1).trim();
- }
- return explanation;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ICustomAppearence.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ICustomAppearence.java deleted file mode 100644 index 53a2a785a6c..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ICustomAppearence.java +++ /dev/null @@ -1,173 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-/**
- * Interface that manages display constants for custom labels (ex: operations label in a class
- * diagram).
- */
-public interface ICustomAppearence {
-
- /**
- * key for the appearance property of graph nodes.
- */
- // @unused
- public final static String CUSTOM_APPEARENCE_KEY = "custom_disp";
-
- // /////////////////////////////////////////////////////////////////////////
- // Style constants
- // /////////////////////////////////////////////////////////////////////////
- /**
- * Style constant for visibility display in labels.
- */
- public final static int DISP_VISIBILITY = 1 << 1;
-
- /**
- * Style constant for isDerive display in labels.
- */
- public final static int DISP_DERIVE = 1 << 2;
-
- /**
- * Style constant for name display in labels.
- */
- public final static int DISP_NAME = 1 << 3;
-
- /**
- * Style constant for type display in labels.
- */
- public final static int DISP_TYPE = 1 << 4;
-
- /**
- * Style constant for multiplicity display in labels.
- */
- public final static int DISP_MULTIPLICITY = 1 << 5;
-
- /**
- * Style constant for default value display in labels.
- */
- public final static int DISP_DFLT_VALUE = 1 << 6;
-
- /**
- * Style constant for modifiers display in labels.
- */
- public final static int DISP_MOFIFIERS = 1 << 7;
-
- /**
- * Style constant for parameters display in labels.
- *
- * @deprecated
- * @see #DISP_PARAMETER_TYPE
- */
- @Deprecated
- // @unused
- public final static int DISP_PARAMETERS = 1 << 8;
-
- /**
- * Style constant for return parameters display in labels.
- *
- * @deprecated
- * @see #DISP_RT_TYPE
- */
- @Deprecated
- // @unused
- public final static int DISP_RETURN_PARAMETERS = 1 << 9;
-
- /** Style constant for carriage return in labels */
- public final static int DISP_MULTI_LINE = 1 << 10;
-
- /**
- * Style constant for opaque action body display in labels.
- */
- // @unused
- public final static int DISP_BODY = 1 << 11;
-
- /** Style constant for parameter direction display in labels */
- public final int DISP_PARAMETER_DIRECTION = 1 << 11;
-
- /** Style constant for parameter name display in labels */
- public final int DISP_PARAMETER_NAME = 1 << 12;
-
- /** Style constant for parameter type display in labels */
- public final int DISP_PARAMETER_TYPE = 1 << 8;
-
- /** Style constant for parameter multiplicity display in labels */
- public final int DISP_PARAMETER_MULTIPLICITY = 1 << 14;
-
- /** Style constant for parameter default value display in labels */
- public final int DISP_PARAMETER_DEFAULT = 1 << 15;
-
- /** Style constant for parameter modifiers display in labels */
- public final int DISP_PARAMETER_MODIFIERS = 1 << 16;
-
- /** Style constant for return parameter type display in labels */
- public final int DISP_RT_TYPE = 1 << 9;
-
- /** Style constant for return parameter multiplicity display in labels */
- public final int DISP_RT_MULTIPLICITY = 1 << 18;
-
- /** Style constant for conjugated labels */
- public final int DISP_CONJUGATED = 1 << 19;
-
- // /////////////////////////////////////////////////////////////////////////
- // UML DEFAULT DISPLAY
- // /////////////////////////////////////////////////////////////////////////
- /**
- * default uml property display in classes edit part.
- */
- public final static int DEFAULT_UML_PROPERTY = DISP_VISIBILITY | DISP_DERIVE | DISP_NAME | DISP_TYPE | DISP_MULTIPLICITY;
-
- /**
- * default uml property display in classes edit part.
- */
- public final static int DEFAULT_UML_ROLE = DISP_VISIBILITY | DISP_DERIVE | DISP_NAME | DISP_TYPE;
-
- /**
- * default uml operation display.
- */
- public final static int DEFAULT_UML_OPERATION = DISP_VISIBILITY | DISP_NAME | DISP_PARAMETER_DIRECTION | DISP_PARAMETER_TYPE | DISP_RT_TYPE | DISP_PARAMETER_NAME;
-
- /**
- * default uml Property in composite diagrams.
- */
- // @unused
- public final static int DEFAULT_UML_COMPO_PROPERTY = DISP_NAME | DISP_TYPE;
-
- /**
- * default uml Property in class diagrams as association ends.
- */
- // @unused
- public final static int DEFAULT_UML_RELATIONEND_PROPERTY = DISP_VISIBILITY | DISP_DERIVE | DISP_NAME | DISP_MOFIFIERS | DISP_MULTI_LINE;
-
- /**
- * default uml Port ins composite diagrams.
- */
- public final static int DEFAULT_UML_PORT = DISP_VISIBILITY | DISP_DERIVE | DISP_NAME | DISP_TYPE | DISP_MULTIPLICITY|DISP_CONJUGATED;
-
- /**
- * default uml OpaqueAction in activity diagrams.
- */
- // @unused
- public final static int DEFAULT_UML_OPAQUE_ACTION = DISP_NAME;
-
- /**
- * default uml Parameter in composite diagrams.
- */
- // @unused
- public final static int DEFAULT_UML_PARAMETER = DISP_PARAMETER_DIRECTION | DISP_PARAMETER_NAME | DISP_PARAMETER_TYPE;
-
- /**
- * default uml instancespecification .
- */
- public final static int DEFAULT_UML_INSTANCESPECIFICATION = DISP_NAME | DISP_TYPE;
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ImageUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ImageUtil.java deleted file mode 100644 index af5afbdd6f9..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ImageUtil.java +++ /dev/null @@ -1,473 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Added support for Image's name
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Iterator;
-import java.util.StringTokenizer;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.common.util.EMap;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.EnumerationLiteral;
-import org.eclipse.uml2.uml.Image;
-import org.eclipse.uml2.uml.Stereotype;
-
-// TODO: Auto-generated Javadoc
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Image</code><BR>
- */
-public class ImageUtil {
-
- /**
- * ID of the EAnnotation where "expression" (used to select stereotype icon) is stored on image.
- */
- public static String IMAGE_PAPYRUS_EA = "image_papyrus";
-
- /**
- * KEY of the EAnnotation where "expression" (used to select stereotype icon) is stored on
- * image.
- */
- public static String IMAGE_EXPR_KEY = "image_expr_key";
-
- /**
- * KEY of the EAnnotation where "kind" (kind = icon/shape) is stored on image.
- */
- public static String IMAGE_KIND_KEY = "image_kind_key";
-
- /**
- * KEY of the EAnnotation where the image's name is stored
- *
- * @see {@link #getName(Image)}
- * @see {@link #setName(Image, String)}
- */
- public static String IMAGE_NAME_KEY = "image_name_key";
-
- /**
- * Set the content of an {@link Image} with a file (containing an image).
- *
- * @param image
- * the UML {@link Image} to set
- * @param imageFile
- * the icon
- */
- // @unused
- public static void setContent(Image image, File imageFile) {
-
- try {
- String rawImageData = "";
- if(imageFile != null) {
- byte[] byteFlow = getBytesFromFile(imageFile);
-
- rawImageData = "";
-
- // file reading
- for(byte element : byteFlow) {
- rawImageData = rawImageData + element + "%";
- }
- } else {
- rawImageData = null;
- }
-
- image.setContent(rawImageData);
-
- } catch (Exception ex) {
- Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, ex.getLocalizedMessage(), ex));
- }
- }
-
- /**
- * Get the content of an {@link Image} as {@link org.eclipse.swt.graphics.Image}
- *
- * @param image
- * the UML {@link Image} to set
- *
- * @return {@link org.eclipse.swt.graphics.Image} content
- */
- public static org.eclipse.swt.graphics.Image getContent(Image image) throws Exception {
-
- if(image == null) {
- // null parameter
- return null;
- }
-
- if(image.getContent() == null) {
- // null image
- return null;
- }
-
- // else
- String rawData = image.getContent();
- StringTokenizer strToken = new StringTokenizer(rawData, "%");
- byte[] target = new byte[strToken.countTokens()];
-
- // decoding image
- int j = 0;
- while(strToken.hasMoreTokens()) {
- target[j] = (new Byte(strToken.nextToken()).byteValue());
- j++;
- }
-
- org.eclipse.swt.graphics.Image decodedImage = new org.eclipse.swt.graphics.Image(null, new ByteArrayInputStream(target));
-
- return decodedImage;
- }
-
- /**
- * Get the image specified by the location property of an {@link Image} as {@link org.eclipse.swt.graphics.Image}
- *
- * @param image
- * the UML {@link Image} to set
- *
- * @return {@link org.eclipse.swt.graphics.Image} image
- */
- public static org.eclipse.swt.graphics.Image getImageFromLocation(Image image) {
-
- org.eclipse.swt.graphics.Image swtImage = null;
-
- // Try to instantiate an SWT image from the path stored
- // in UML Image location property
- String location = image.getLocation();
- if((location != null) && !("".equals(location))) {
-
- URI iconURI = URI.createURI(location);
- if(iconURI.isRelative()) {
- String err_msg = "Incorrect implementation of relative location." + location;
- Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, err_msg, new Exception(err_msg)));
- URI pluginURI = URI.createPlatformPluginURI(location, true); // <- TODO : fix this to retrieve the related plug-in URI
- iconURI = iconURI.resolve(pluginURI);
- }
-
- try {
- ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(new URL(iconURI.toString()));
- swtImage = imageDescriptor.createImage();
-
- } catch (Exception e) {
- Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, "Could not create image from location : " + location, e));
- }
- }
-
- return swtImage;
- }
-
- /**
- * Read an image file content.
- *
- * @param file
- * the file
- *
- * @return a table of bytes of the file content
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- public static byte[] getBytesFromFile(File file) throws IOException {
-
- InputStream is = new FileInputStream(file);
-
- // Get the size of the file
- long length = file.length();
-
- // You cannot create an array using a long type.
- // It needs to be an int type.
- // Before converting to an int type, check
- // to ensure that file is not larger than Integer.MAX_VALUE.
- if(length > Integer.MAX_VALUE) {
- is.close();
- throw new IOException("Image too big to encode");
- }
-
- // Create the byte array to hold the data
- byte[] bytes = new byte[(int)length];
-
- // Read in the bytes
- int offset = 0;
- int numRead = 0;
- while((offset < bytes.length) && ((numRead = is.read(bytes, offset, bytes.length - offset)) >= 0)) {
- offset += numRead;
- }
-
- // Ensure all the bytes have been read in
- if(offset < bytes.length) {
- is.close();
- throw new IOException("Could not completely read file " + file.getName());
- }
-
- // Close the input stream and return bytes
- is.close();
-
- return bytes;
- }
-
- /**
- * Associates an expression to an image.
- *
- * @param image
- * the image
- * @param expression
- * the expression
- */
- public static void setExpression(Image image, String expression) {
-
- EAnnotation ea_Image = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- // Create annotation for icon selection if it does not exist
- if(ea_Image == null) {
- ea_Image = image.createEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- }
-
- // If expression == "" remove the EAnnotation
- if("".equals(expression)) {
- ea_Image.getDetails().removeKey(IMAGE_EXPR_KEY);
- } else {
- ea_Image.getDetails().put(ImageUtil.IMAGE_EXPR_KEY, expression);
- }
-
- cleanImageAnnotation(ea_Image);
- }
-
- /**
- * Returns the expression associated to the image.
- *
- * @param image
- * the image
- *
- * @return the expression associated to the image
- */
- public static String getExpression(org.eclipse.uml2.uml.Image image) {
- EAnnotation ea_ImageExpr = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
-
- String expr = null;
- if((ea_ImageExpr != null) && (ea_ImageExpr.getDetails().containsKey(ImageUtil.IMAGE_EXPR_KEY))) {
- expr = ea_ImageExpr.getDetails().get(ImageUtil.IMAGE_EXPR_KEY);
- }
- return expr;
- }
-
- /**
- * Associates a name to an Image.
- *
- * The UML Image is not a NamedElement : the name is stored as an
- * EAnnotation, and is not mandatory. The name should only be used for
- * displaying the image's label : this is *not* an identifier.
- *
- * @param image
- * The image
- * @param name
- * The name
- */
- public static void setName(Image image, String name) {
- EAnnotation ea_Image = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- // Create annotation for icon selection if it does not exist
- if(ea_Image == null) {
- ea_Image = image.createEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- }
-
- // If expression == "" remove the EAnnotation
- if("".equals(name)) {
- ea_Image.getDetails().removeKey(IMAGE_NAME_KEY);
- } else {
- ea_Image.getDetails().put(ImageUtil.IMAGE_NAME_KEY, name);
- }
-
- cleanImageAnnotation(ea_Image);
- }
-
- /**
- * Returns the name associated to the image
- *
- * The UML Image is not a NamedElement : the name is stored as an
- * EAnnotation, and is not mandatory. The name should only be used for
- * displaying the image's label : this is *not* an identifier.
- *
- * @param image
- * the image
- * @return
- * the name associated to the image
- */
- public static String getName(Image image) {
- EAnnotation ea_Image = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
-
- String name = null;
- if((ea_Image != null) && (ea_Image.getDetails().containsKey(IMAGE_NAME_KEY))) {
- name = ea_Image.getDetails().get(IMAGE_NAME_KEY);
- }
- return name;
- }
-
- /**
- * Removes the EAnnotation from the Image if the annotation doesn't contain any valid key
- *
- * @param annotation
- */
- private static void cleanImageAnnotation(EAnnotation annotation) {
- EMap<String, String> details = annotation.getDetails();
- if(details.isEmpty()) {
- //if(!(details.containsKey(IMAGE_NAME_KEY)) && !(details.containsKey(IMAGE_KIND_KEY) && !(details.containsKey(IMAGE_NAME_KEY)))) {
- annotation.setEModelElement(null);
- }
-
- }
-
- /**
- * Associates kind to an image.
- *
- * @param image
- * the image
- * @param kind
- * of image (icon / shape)
- */
- // @unused
- public static void setKind(org.eclipse.uml2.uml.Image image, String kind) {
-
- EAnnotation ea_Image = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- // Create annotation for icon selection if it does not exist
- if(ea_Image == null) {
- ea_Image = image.createEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
- }
-
- // If expression == "" remove the EAnnotation
- if("".equals(kind)) {
- ea_Image.getDetails().removeKey(IMAGE_KIND_KEY);
- } else {
- ea_Image.getDetails().put(ImageUtil.IMAGE_KIND_KEY, kind);
- }
-
- cleanImageAnnotation(ea_Image);
- }
-
- /**
- * Returns the kind of the image (icon or shape for Papyrus).
- *
- * @param image
- * the image
- *
- * @return kind of image
- */
- public static String getKind(org.eclipse.uml2.uml.Image image) {
- EAnnotation ea_ImageExpr = image.getEAnnotation(ImageUtil.IMAGE_PAPYRUS_EA);
-
- String kind = null;
- if((ea_ImageExpr != null) && (ea_ImageExpr.getDetails().containsKey(ImageUtil.IMAGE_KIND_KEY))) {
- kind = ea_ImageExpr.getDetails().get(ImageUtil.IMAGE_KIND_KEY);
- }
- return kind;
- }
-
- /**
- * Evaluates the "Expression" EAnnotation associated to the image.
- *
- * @param element
- * on which the stereotype (owning current image) is applied
- * @param image
- * the image
- *
- * @return true if the expression is correct
- */
- public static boolean evalExpression(Image image, Element element) {
- /*
- * Expression has the form : propName = Literal
- */
-
- /* Firstly we extract the propertyName and the literal */
-
- String propName = null;
- String literal = null;
- Stereotype st = (Stereotype)image.getOwner();
-
- // Retrieve Expression
- String expression = ImageUtil.getExpression(image);
- if(expression == null) {
- // No expression to check
- return false;
- }
-
- // Parse and test expression
- StringTokenizer sToken = new StringTokenizer(expression.replace(" ", ""), "=");
- if(sToken.countTokens() == 2) {
- propName = sToken.nextToken();
- literal = sToken.nextToken();
-
- } else {
- // Bad formed expression --> ignore
- return false;
- }
-
- if(element.getValue(st, propName) != null) {
- /* extract property value from applied stereotype */
- Object val = element.getValue(st, propName);
-
- if(val instanceof EnumerationLiteral) {
- if(((EnumerationLiteral)val).getLabel().equals(literal)) {
- return true;
- }
- }
- }
- // In any other case (bad expression, not property found...)
- return false;
- }
-
- /**
- * Test expression on every image, stop on first verified expression.
- *
- * @param element
- * the element to check
- * @param images
- * the list of images to check
- *
- * @return first image verifying its expression
- */
- public static Image findImageVerifyingExpression(Element element, EList<Image> images) {
-
- Image image = null;
- Iterator<Image> it = images.iterator();
- while((image == null) && it.hasNext()) {
- Image current = it.next();
- if(ImageUtil.evalExpression(current, element)) {
- image = current;
- }
- }
-
- return image;
- }
-
- /**
- * Create an Id to store and retrieve image (SWT) In registry.
- *
- * @param image
- * the image
- *
- * @return the image id
- */
- public static String getImageId(Image image) {
- String id = "";
-
- Stereotype owner = (Stereotype)image.getOwner();
- id += owner.getQualifiedName() + "_img_" + owner.getIcons().indexOf(image);
-
- return id;
-
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java deleted file mode 100644 index 44b48829ed4..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java +++ /dev/null @@ -1,76 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- */
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.InstanceSpecification;
-
-/**
- * util class to display name of instancespecification
- *
- */
-public class InstanceSpecificationUtil {
- /**
- * return the custom label of the operation, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the operation
- */
- public static String getCustomLabel(InstanceSpecification instance, int style) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" "); // adds " " first for correct display considerations
-
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(NamedElementUtil.getName(instance));
- }
-
- // classifier
- if((style & ICustomAppearence.DISP_TYPE) != 0) {
- if( !getTypesAsString(instance, style).equals("")){
- buffer.append(": ");
- buffer.append(getTypesAsString(instance, style));}
- }
-
-
- return buffer.toString();
- }
- /**
- * Returns the list of classifier for an instance specification as a string
- *
- * @return a string containing all classifier separated by commas
- */
- private static String getTypesAsString(InstanceSpecification instance, int style) {
- StringBuffer typeString = new StringBuffer();
- Iterator<Classifier> classifierIterator = instance.getClassifiers().iterator();
- boolean firstParameter = true;
- while(classifierIterator.hasNext()) {
- Classifier classifier = classifierIterator.next();
-
- // get the label for this Classifier
- String classifierName = NamedElementUtil.getName(classifier);
- if (!classifierName.trim().equals("")) {
- if (!firstParameter) {
- typeString.append(", ");
- }
- typeString.append(classifierName);
- firstParameter = false;
- }
- }
- return typeString.toString();
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java deleted file mode 100644 index 570c7b845a4..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/MultiplicityElementUtil.java +++ /dev/null @@ -1,106 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2009 CEA LIST. - * - * - * 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: - * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.utils; - -import org.eclipse.uml2.uml.MultiplicityElement; - -/** - * Utility class for <code>org.eclipse.uml2.uml.MultiplicityElement</code><BR> - */ -public class MultiplicityElementUtil { - - /** - * Return the multiplicity of the element "[x..y]" - * - * @return the string representing the multiplicity - */ - public static String getMultiplicityAsString(MultiplicityElement element) { - StringBuffer buffer = new StringBuffer(); - String multiplicityStr = getMultiplicityAsStringWithoutSquareBrackets(element); - if(multiplicityStr != null && !"".equals(multiplicityStr)) { - buffer.append(" ["); - buffer.append(multiplicityStr); - buffer.append("]"); - } - return buffer.toString(); - } - - /** - * Returns the String corresponding to the multiplicity without square brackets - * - * @return the string representing the multiplicity, without square brackets - */ - public static String getMultiplicityAsStringWithoutSquareBrackets(MultiplicityElement element) { - StringBuffer buffer = new StringBuffer(); - // special case for [1] and [*] - int lower = element.getLower(); - int upper = element.getUpper(); - - if(lower == upper) { - buffer.append(lower); - } else if((lower == 0) && (upper == -1)) { - buffer.append("*"); - } else if(upper == -1) { - buffer.append(lower); - buffer.append("..*"); - } else { - buffer.append(lower); - buffer.append(".."); - buffer.append(upper); - } - - return buffer.toString(); - } - - /** - * Parses the given String and returns the value of the multiplicity. - * <P> - * a lower bound with value infinite (<code>*</code>) will be set at <code>-1</code>. - * </P> - * - * @param value - * the string representing the multiplicity. it can be <code>1</code>, <code>1..2</code> or <code>1..*</code> - * @return a 2-size integer table, with the first element corresponding to the lower bound, the second corresponds to the upper bound - */ - public static int[] parseMultiplicity(String value) throws NumberFormatException { - int lower = 0; - int upper = 0; - int firstIndex = value.indexOf(".."); - - // ".." was not found => this should be an integer, for example a multiplicity ~ [1] - if(firstIndex == -1) { - // this should be directly an integer or a star - if("*".equals(value)) { - lower = 0; - upper = -1; - } else { - lower = Integer.parseInt(value); - upper = lower; - } - } else { - String lowerValue = value.substring(0, firstIndex); - String upperValue = value.substring(firstIndex + "..".length()); - - lower = Integer.parseInt(lowerValue); - upper = -2; - if("*".equals(upperValue)) { - upper = -1; - } else { - upper = Integer.parseInt(upperValue); - } - } - return new int[]{ lower, upper }; - } - -} diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionHelper.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionHelper.java deleted file mode 100644 index e969c8c717d..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionHelper.java +++ /dev/null @@ -1,160 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * Arnaud Cuccuru (CEA LIST) - Initial API and implementation
- * Vincent Lorenzo (CEA LIST)
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.uml2.uml.Model;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.resource.UMLResource;
-
-
-public class NameResolutionHelper {
-
- protected Namespace scope;
-
- protected EClass filter;
-
- protected Map<String, List<NamedElement>> allNames;
-
- public NameResolutionHelper(Namespace scope, EClass filter) {
- this.scope = scope;
- this.filter = filter;
- }
-
- public List<NamedElement> getNamedElements(String name) {
- if(this.allNames == null) {
- this.allNames = new HashMap<String, List<NamedElement>>();
- this.computeAllNames();
- }
- List<NamedElement> namedElements = this.allNames.get(name);
- return namedElements != null ? namedElements : new ArrayList<NamedElement>();
- }
-
- /**
- * TODO
- */
- protected void computeAllNames() {
-
- // compute names directly available in the scope
- computeNames("", scope, true);
-
- // compute names related to enclosing namepaces of scope
- Namespace enclosingNamespace = scope.getNamespace();
- String prefix = "";
- while(enclosingNamespace != null) {
-// prefix += enclosingNamespace.getName() + NamedElementUtil.QUALIFIED_NAME_SEPARATOR;
- prefix="";
- computeNames(prefix, enclosingNamespace, false);
- enclosingNamespace = enclosingNamespace.getNamespace();
- }
-
- // Compute names related to the root context model
- Namespace model = scope.getModel();
- if(model==null){
- model = scope;
- }
- if(filter != null) {
- if(filter.isSuperTypeOf(model.eClass())) {
- List<NamedElement> l = this.allNames.get(model.getName());
- if(l == null) { // i.e. no names have already been resolved in enclosed namespaces
- l = new ArrayList<NamedElement>();
- l.add(model);
- this.allNames.put(model.getName(), l);
- }
- }
- } else {
- List<NamedElement> l = this.allNames.get(model.getName());
- if(l == null) { // i.e. no names have already been resolved in enclosed namespaces
- l = new ArrayList<NamedElement>();
- l.add(model);
- this.allNames.put(model.getName(), l);
- }
- }
- computeNames(model.getName() + "::", model, false);
-
- // Build names corresponding to other available UML resources in the workspace
- List<Resource> resources = scope.eResource().getResourceSet().getResources();
- for(Resource resource : resources) {
- if(resource != scope.eResource() && resource instanceof UMLResource) {
- UMLResource umlResource = (UMLResource)resource;
- Model root = null;
- for(Iterator<EObject> i = umlResource.getAllContents(); i.hasNext() && root == null;) {
- EObject next = i.next();
- if(next instanceof Model)
- root = (Model)next;
- }
- if(root != null) {
- if(filter != null) {
- if(filter.isSuperTypeOf(root.eClass())) {
- List<NamedElement> l = this.allNames.get(root.getName());
- if(l == null) { // i.e. no names have already been resolved in enclosed namespaces
- l = new ArrayList<NamedElement>();
- l.add(root);
- this.allNames.put(root.getName(), l);
- }
- }
- } else {
- List<NamedElement> l = this.allNames.get(root.getName());
- if(l == null) { // i.e. no names have already been resolved in enclosed namespaces
- l = new ArrayList<NamedElement>();
- l.add(root);
- this.allNames.put(root.getName(), l);
- }
- }
- computeNames(root.getName() + NamedElementUtil.QUALIFIED_NAME_SEPARATOR, root, false);
- }
- }
- }
- }
-
-
- /**
- * TODO
- */
- protected void computeNames(String prefix, Namespace scope, boolean ignoreAlreadyFoundNames) {
- Set<String> preExistingKeys;
- if(ignoreAlreadyFoundNames)
- preExistingKeys = new HashSet<String>();
- else
- preExistingKeys = this.allNames.keySet();
- // iterates members of the scope
- for(NamedElement member : scope.getMembers()) {
- List<String> memberNames = scope.getNamesOfMember(member);
- // iterates other names given to the current member in the context of this scope
- for(String memberName : memberNames) {
- // Checks if the name must be considered or not
- if(!preExistingKeys.contains(prefix + memberName)) {
- List<NamedElement> l = this.getNamedElements(prefix + memberName);
- l.add(member);
- this.allNames.put(prefix + memberName, l);
- }
- if(member instanceof Namespace) { // Recursive call on the current member
- computeNames(prefix + memberName + NamedElementUtil.QUALIFIED_NAME_SEPARATOR, (Namespace)member, true);
- }
- }
- }
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionUtils.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionUtils.java deleted file mode 100644 index b348d6513bd..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NameResolutionUtils.java +++ /dev/null @@ -1,386 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * Arnaud Cuccuru (CEA LIST) - Initial API and implementation
- * Vincent Lorenzo (CEA LIST)
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Model;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.resource.UMLResource;
-
-public class NameResolutionUtils {
-
-
- private NameResolutionUtils() {
- // to prevent instanciation
- }
-
- /**
- * From a given (potentially qualified) name and a scope, retrieves a list of NamedElement, filter by the filter metaclass (which can be null).
- * If there are more than one element in the returned list, the name is ambiguous
- * If the list is empty, the name does not correspond to any available named element in the context of the model resource set
- *
- * @param name
- * , the potentially/partially qualified name of the NamedElement to be resolved
- * @param scope
- * , the namespace defining the scope for the name resolution
- * @param filter
- * , the potential "filter" metaclass (can be null)
- * @return the list of NamedElement found by applying the resolution process
- */
- public static final List<NamedElement> getNamedElements(final String name, final Element scope, final EClass filter) {
- final List<NamedElement> resolvedNamedElements = new ArrayList<NamedElement>();
- // In practice, a scope can only be a Namespace
- if(!(scope instanceof Namespace)) {
- return resolvedNamedElements;
- }
- return NameResolutionUtils.getNamedElements(name, (Namespace)scope, filter);
- }
-
- /**
- * From a given (potentially qualified) name and a scope, retrieves a list of NamedElement, filter by the filter metaclass (which can be null).
- * If there are more than one element in the returned list, the name is ambiguous
- * If the list is empty, the name does not correspond to any available named element in the context of the model resource set
- *
- * @param name
- * , the potentially/partially qualified name of the NamedElement to be resolved
- * @param scope
- * , the namespace defining the scope for the name resolution
- * @param filter
- * , the potential "filter" metaclass (can be null)
- * @return the list of NamedElement found by applying the resolution process
- */
- public static final List<NamedElement> getNamedElements(final String name, final Namespace scope, final EClass filter) {
- final List<NamedElement> resolvedNamedElements = new ArrayList<NamedElement>();
-
- // extracts name fragments for the given (potentially qualified) name
- final List<String> nameFragments = NameResolutionUtils.computeNameFragments(name);
- // tries to resolve the name
- resolvedNamedElements.addAll(NameResolutionUtils.getNamedElements(nameFragments, scope, filter));
-
- // If no named elements have been found, tries to restart the process on the enclosing namespace of the scope, if any
- if(resolvedNamedElements.isEmpty()) {
- Namespace enclosingNamespace = scope.getNamespace();
- while(resolvedNamedElements.isEmpty() && (enclosingNamespace != null)) {
- resolvedNamedElements.addAll(NameResolutionUtils.getNamedElements(nameFragments, enclosingNamespace, filter));
- enclosingNamespace = enclosingNamespace.getNamespace();
- }
- }
-
- // If no named elements have been found, tries to evaluate the name using the root context model has a root of the qualified name
- if(resolvedNamedElements.isEmpty()) {
- Namespace model = scope.getModel();
- if(model==null){
- model = scope;
- }
- if(model.getName().equals(nameFragments.get(0))) {
- if(nameFragments.size() == 1) {
- if(filter != null) {
- if(filter.isSuperTypeOf(model.eClass())) {
- resolvedNamedElements.add(model);
- }
- } else {
- resolvedNamedElements.add(model);
- }
- } else {
- final List<String> remainingNameFragments = nameFragments.subList(1, nameFragments.size());
- resolvedNamedElements.addAll(NameResolutionUtils.getNamedElements(remainingNameFragments, model, filter));
- }
- }
- }
-
- // If no named elements have been found, tries to evaluate the name as a fully qualified name
- // This requires analysis of available UML resources in the context of scope resource set
- if(resolvedNamedElements.isEmpty()) {
- final List<Resource> resources = scope.eResource().getResourceSet().getResources();
- for(final Resource resource : resources) {
- if((resource != scope.eResource()) && (resource instanceof UMLResource)) {
- final UMLResource umlResource = (UMLResource)resource;
- Model root = null;
- for(final Iterator<EObject> i = umlResource.getAllContents(); i.hasNext() && (root == null);) {
- final EObject next = i.next();
- if(next instanceof Model) {
- root = (Model)next;
- }
- }
- if(root != null) {
- if(root.getName().equals(nameFragments.get(0))) {
- if(nameFragments.size() == 1) {
- if(filter != null) {
- if(filter.isSuperTypeOf(root.eClass())) {
- resolvedNamedElements.add(root);
- }
- } else {
- resolvedNamedElements.add(root);
- }
- } else {
- final List<String> remainingNameFragments = nameFragments.subList(1, nameFragments.size());
- resolvedNamedElements.addAll(NameResolutionUtils.getNamedElements(remainingNameFragments, root, filter));
- }
- }
- }
- }
- }
- }
-
- return resolvedNamedElements;
- }
-
- /**
- * From a given list of name fragments representing a (potentially qualified name),
- * retrieves a list of NamedElement.
- * The basic principle of the algorithm is to try to match the first element of nameFragments with
- * members of the scope.
- * When a match is found, this method is called a recursively on a sublist of a nameFragments
- * (i.e., the first element is omitted) and on the matched member.
- * The stop condition for recursivity is that the size of nameFragments is 1.
- *
- * @param nameFragments
- * , the potentially/partially qualified name of the NamedElement to be resolved
- * @param scope
- * , the namespace defining the scope for the name resolution
- * @param clazz
- * , the potential "filter" metaclass (can be null)
- * @return the list of NamedElement found by applying the resolution process
- */
- private static final List<NamedElement> getNamedElements(final List<String> nameFragments, final Namespace scope, final EClass clazz) {
- final List<NamedElement> resolvedNamedElements = new ArrayList<NamedElement>();
- // Tries to match the first name fragment with members of the scope
- for(final NamedElement member : scope.getMembers()) {
- final List<String> memberNames = scope.getNamesOfMember(member);
- final String firstNameFragment = nameFragments.get(0);
- // iterates other names given to the current member in the context of this scope
- for(final String memberName : memberNames) {
- if(memberName.equals(firstNameFragment)) {
- // the first fragment matches with this member
- if(nameFragments.size() == 1) { // Stop condition for recursivity
- if(clazz != null) {
- if(clazz.isSuperTypeOf(member.eClass())) {
- resolvedNamedElements.add(member);
- }
- } else {
- resolvedNamedElements.add(member);
- }
- } else {
- if(member instanceof Namespace) { // Recursive call on the sublist and the matching member
- final List<String> remainingNameFragments = nameFragments.subList(1, nameFragments.size());
- resolvedNamedElements.addAll(NameResolutionUtils.getNamedElements(remainingNameFragments, (Namespace)member, clazz));
- }
- }
- }
- }
- }
- return resolvedNamedElements;
- }
-
- /**
- * Computes a List<String> containing the various "name fragments" of parameter "name".
- * The string "name" is simply splitted according to qualifiedNameSeparator ("::").
- *
- * @param name
- * The name to be "fragmented"
- * @return The list of name fragments
- */
- private static final List<String> computeNameFragments(final String name) {
- final String[] nameFragmentsArray = name.split(NamedElementUtil.QUALIFIED_NAME_SEPARATOR);
- final List<String> nameFragments = new ArrayList<String>();
- for(final String element : nameFragmentsArray) {
- nameFragments.add(element);
- }
- return nameFragments;
- }
-
- /**
- * Computes the shortest qualified names for a named element, in the context of a scope.
- * The shortest qualified names are the shortest name in terms of qualification depth which unambiguously
- * resolve to the researched element.
- * In the case where the returned list is empty, there is no unambiguous name that could be found,
- * including the fully qualified name of the element. This typically means that there are problems in the
- * context model in terms of organization of element imports and package imports and named element
- * definitions, or conflict in loaded UML resources.
- * In the case where the list contains more than one name, all these names are all valid, all have the same
- * qualification depth, and can be used indifferently.
- *
- * @param element
- * , the named element for which we try to determine the shortest qualified name
- * @param scope
- * , the scope in which we try to determine the shortest qualified name for element
- * @return the shortest qualified names for element
- */
- public static final List<String> getShortestQualifiedNames(final NamedElement element, final Element scope) {
- final List<String> shortestNames = new ArrayList<String>();
- // In practice, a scope can only be a Namespace
- if(!(scope instanceof Namespace)) {
- return shortestNames;
- }
- return NameResolutionUtils.getShortestQualifiedNames(element, (Namespace)scope);
- }
-
- /**
- * Computes the shortest qualified names for a named element, in the context of a scope.
- * The shortest qualified names are the shortest name in terms of qualification depth which unambiguously
- * resolve to the researched element.
- * In the case where the returned list is empty, there is no unambiguous name that could be found,
- * including the fully qualified name of the element. This typically means that there are problems in the
- * context model in terms of organization of element imports and package imports and named element
- * definitions, or conflict in loaded UML resources.
- * In the case where the list contains more than one name, all these names are all valid, all have the same
- * qualification depth, and can be used indifferently.
- *
- * @param element
- * , the named element for which we try to determine the shortest qualified name
- * @param scope
- * , the scope in which we try to determine the shortest qualified name for element
- * @return the shortest qualified names for element
- */
- public static final List<String> getShortestQualifiedNames(final NamedElement element, final Namespace scope) {
- final List<String> shortestNames = new ArrayList<String>();
-
- // Tries to compute
- shortestNames.addAll(NameResolutionUtils.getShortestQualifiedNamesOmittingFullyQualifiedName(element, scope));
-
- // if no short name have been found, returns the fully qualified name, if it is itself unambiguous
- if(shortestNames.isEmpty()) {
- final String fullyQualifiedNameOfElement = element.getQualifiedName();
- if((fullyQualifiedNameOfElement != null) && !(fullyQualifiedNameOfElement.length() == 0)) {
- shortestNames.add(fullyQualifiedNameOfElement);
- shortestNames.removeAll(NameResolutionUtils.findAmbiguousNames(shortestNames, element, scope));
- }
- }
- return shortestNames;
- }
-
- /**
- * Computes the shortest qualified names for a named element in the context of a scope, omitting
- * fully qualified name of the named element (The fully qualified name is handled as a special case of
- * getShortestQualifiedName, in the case where this method was not able to produce a non-ambiguous qualified
- * name).
- * The basic principle is the following (each step is applied if the previous one did not succeed.
- * "Evaluates" means assuring that computed names are not ambiguous):
- * 1. if element and scope are the same, directly evaluates the name of the element.
- * 2. if element is a member of scope, evaluates member names for this element,
- * 3. Iterate over enclosing namespaces of scope, and if element is a member of an enclosing namespace,
- * evaluate member names for element in the context of this enclosing namespace
- * 4. Recursively call this method using the enclosing namespace of element as the reasearched named element,
- * build partially qualified names from the obtained list, and evaluate the computed names
- *
- * @param element
- * , the named element for which we try to determine the shortest qualified name
- * @param scope
- * , the scope in which we try to determine the shortest qualified name for element
- * @return the shortest qualified names for element (omitting the fully qualified name element)
- */
- private static final List<String> getShortestQualifiedNamesOmittingFullyQualifiedName(final NamedElement element, final Namespace scope) {
- boolean continueResearch = true;
- final List<String> shortestNames = new ArrayList<String>();
- // if element and scope are the same, the shortest name is the name of the element
- if(element == scope) {
- shortestNames.add(element.getName());
- shortestNames.removeAll(NameResolutionUtils.findAmbiguousNames(shortestNames, element, scope));
- if(!shortestNames.isEmpty()) {
- continueResearch = false;
- }
- }
- // if element is part of the scope members, the shortest names are the names given to this member in the context of this scope
- if(continueResearch && scope.getMembers().contains(element)) {
- shortestNames.addAll(scope.getNamesOfMember(element));
- shortestNames.removeAll(NameResolutionUtils.findAmbiguousNames(shortestNames, element, scope));
- if(!shortestNames.isEmpty()) {
- continueResearch = false;
- }
- }
- if(continueResearch) {
- // tries to find element in the enclosing namespaces of scope
- Namespace enclosingNamespaceOfScope = scope.getNamespace();
- while((enclosingNamespaceOfScope != null) && shortestNames.isEmpty()) {
- if(enclosingNamespaceOfScope.getMembers().contains(element)) {
- shortestNames.addAll(enclosingNamespaceOfScope.getNamesOfMember(element));
- shortestNames.removeAll(NameResolutionUtils.findAmbiguousNames(shortestNames, element, scope));
- }
- enclosingNamespaceOfScope = enclosingNamespaceOfScope.getNamespace();
- }
- if(shortestNames.isEmpty()) {
- // tries to find the shortest name for the enclosing namespace in the context of scope
- final Namespace enclosingNamespaceOfElement = element.getNamespace();
- if(enclosingNamespaceOfElement != null) {
- final List<String> shortestNamesForEnclosingNamespace = new ArrayList<String>();
- shortestNamesForEnclosingNamespace.addAll(NameResolutionUtils.getShortestQualifiedNames(enclosingNamespaceOfElement, scope));
- // creates the list of shortest name from the list of shortest names for the enclosing namespace
- for(final String shortestNameForEnclosing : shortestNamesForEnclosingNamespace) {
- final List<String> memberNames = enclosingNamespaceOfElement.getNamesOfMember(element);
- for(final String memberName : memberNames) {
- shortestNames.add(shortestNameForEnclosing + NamedElementUtil.QUALIFIED_NAME_SEPARATOR + memberName);
- }
- }
- shortestNames.removeAll(NameResolutionUtils.findAmbiguousNames(shortestNames, element, scope));
- }
- }
- }
- return shortestNames;
- }
-
- /**
- * From a list of names, select the names which do not unambiguously resolve to researchedElement,
- * in the context of scope
- *
- * @param names
- * , the list of names to evaluate
- * @param researchedElement
- * , the element that must be resolved from the names
- * @param scope
- * , the scope in which evaluation happens
- * @return the list of names which are ambiguous
- */
- private static final List<String> findAmbiguousNames(final List<String> names, final NamedElement researchedElement, final Namespace scope) {
- final List<String> ambiguousNames = new ArrayList<String>();
- for(final String name : names) {
- if(NameResolutionUtils.isQualifiedNameAmbiguous(name, researchedElement, scope)) {
- ambiguousNames.add("" + name);
- }
- }
- return ambiguousNames;
- }
-
-
- /**
- * Determines if a given name is ambiguous. From a given scope where evaluation of the name happens,
- * a name is ambiguous if:
- * - The given name resolves to multiple elements,
- * - Or the name resolves to one element which is not the researched element.
- * This method relies on getNamedElements(String, Element, EClass), using researchedElement.eClass() as a filter.
- *
- * @param name
- * @param researchedElement
- * @param scope
- * @return
- */
- private static final boolean isQualifiedNameAmbiguous(final String name, final NamedElement researchedElement, final Namespace scope) {
- final List<NamedElement> resolvedElements = NameResolutionUtils.getNamedElements(name, scope, researchedElement.eClass());
- if(resolvedElements.size() > 1) {
- return true;
- }
- if(resolvedElements.get(0) != researchedElement) {
- return true;
- }
- return false;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java deleted file mode 100644 index 13da0b0c704..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/NamedElementUtil.java +++ /dev/null @@ -1,186 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
-import org.eclipse.uml2.uml.NamedElement;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.NamedElement</code><BR>
- */
-public class NamedElementUtil {
-
- public static final String QUALIFIED_NAME_SEPARATOR = "::";
-
- private final static String PUBLIC_STRING = "+";
-
- private final static String PROTECTED_STRING = "#";
-
- private final static String PRIVATE_STRING = "-";
-
- private final static String PACKAGE_STRING = "~";
-
- /**
- * A helper method to calculate the max depth of an element
- *
- * @param the
- * named element
- * @return the maximum depth found in qualified name
- */
- public static int getQualifiedNameMaxDepth(NamedElement namedElement) {
- int d = 0;
- String s = namedElement.getQualifiedName();
- if(s == null) {
- return 0;
- }
- int n = 0;
- while((n = s.indexOf(QUALIFIED_NAME_SEPARATOR, n)) != -1) {
- n += 2;
- d++;
- }
- return d;
- }
-
- /**
- * generate a default name for the eobject in parameter the format is :
- * "eclassName"+"max(elementOfTheSameName in the container)" + 1
- *
- * @param newElement
- * @return
- */
- public static String getDefaultNameWithIncrement(EObject newElement) {
- if(newElement.eContainer() != null) {
- return getDefaultNameWithIncrement(newElement, newElement.eContainer().eContents());
- }
- return null;
- }
-
- /**
- * generate a default name for the eobject in parameter the format is :
- * "eclassName"+"max(elementOfTheSameName in the container)" + 1 the method checks already
- * existing element in contents parameter
- *
- * @param newElement
- */
- @SuppressWarnings("rawtypes")
- public static String getDefaultNameWithIncrement(EObject newElement, Collection contents) {
- return getDefaultNameWithIncrement("", newElement, contents);
- }
-
- @SuppressWarnings("rawtypes")
- public static String getDefaultNameWithIncrement(String prefix, EObject newElement, Collection contents) {
- if(prefix == null) {
- prefix = "";
- }
-
- return getDefaultNameWithIncrementFromBase(prefix + newElement.eClass().getName(), contents);
- }
-
- @SuppressWarnings("rawtypes")
- public static String getDefaultNameWithIncrementFromBase(String base, Collection contents) {
- if(base.equalsIgnoreCase("property")) {
- base = "Attribute";
- }
- int nextNumber = 1;
-
- for(Object o : contents) {
- if(o instanceof EObject) {
- String name = EMFCoreUtil.getName((EObject)o);
- if(name != null && name.startsWith(base)) {
- String end = name.substring(base.length());
- int nextNumberTmp = 1;
-
- try {
- nextNumberTmp = Integer.parseInt(end) + 1;
- } catch (NumberFormatException ex) {
- }
-
- if(nextNumberTmp > nextNumber) {
- nextNumber = nextNumberTmp;
- }
- }
- }
- }
-
- return base + nextNumber;
- }
-
- /**
- * Give the visibility of the {@link NamedElement} as a string, as defined in the UML2 standard.
- *
- * @return A String representing the visibility of the {@link NamedElement}. Possible values:
- * <ul>
- * <li>public: <code>"+"</code>
- * <li>private: <code>"-"</code>
- * <li>protected: <code>"#"</code>
- * <li>package: <code>"~"</code>
- * </ul>
- */
- public static String getVisibilityAsSign(NamedElement element) {
- String vKindValue = "";
-
- switch(element.getVisibility().getValue()) {
- case org.eclipse.uml2.uml.VisibilityKind.PUBLIC:
- vKindValue = PUBLIC_STRING;
- break;
- case org.eclipse.uml2.uml.VisibilityKind.PRIVATE:
- vKindValue = PRIVATE_STRING;
- break;
- case org.eclipse.uml2.uml.VisibilityKind.PACKAGE:
- vKindValue = PACKAGE_STRING;
- break;
- case org.eclipse.uml2.uml.VisibilityKind.PROTECTED:
- vKindValue = PROTECTED_STRING;
- break;
- }
- return vKindValue;
- }
-
- /**
- * Returns the name of an element, given its qualified name
- *
- * @param qualifiedName
- * the qualified name of the element
- * @return the name of the element. It shall never be <code>null</code>.
- */
- public static String getNameFromQualifiedName(String qualifiedName) {
- String name = qualifiedName.substring(qualifiedName.lastIndexOf(NamedElement.SEPARATOR) + NamedElement.SEPARATOR.length());
- return (name != null) ? name : "";
- }
-
- /**
- *
- * @param childQualifiedName
- * the qualifiedName of an element
- * @return
- * the qualified name of its parent
- */
- public static String getParentQualifiedName(final String childQualifiedName) {
- final String childName = getNameFromQualifiedName(childQualifiedName);
- final String parentQualifiedName = childQualifiedName.substring(0, childQualifiedName.length() - (NamedElement.SEPARATOR.length() + childName.length()));
- return (parentQualifiedName != null) ? parentQualifiedName : "";
- }
-
-
- public static String getName(NamedElement element) {
- if(element.getName() != null) {
- return element.getName();
- } else {
- return (NamedElementUtil.getDefaultNameWithIncrement(element));
- }
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java deleted file mode 100644 index 03b4d5dc2a1..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ObjectFlowUtil.java +++ /dev/null @@ -1,299 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.uml2.uml.AcceptEventAction;
-import org.eclipse.uml2.uml.Action;
-import org.eclipse.uml2.uml.Activity;
-import org.eclipse.uml2.uml.ActivityEdge;
-import org.eclipse.uml2.uml.ActivityNode;
-import org.eclipse.uml2.uml.ActivityParameterNode;
-import org.eclipse.uml2.uml.DecisionNode;
-import org.eclipse.uml2.uml.FinalNode;
-import org.eclipse.uml2.uml.ForkNode;
-import org.eclipse.uml2.uml.InitialNode;
-import org.eclipse.uml2.uml.InputPin;
-import org.eclipse.uml2.uml.JoinNode;
-import org.eclipse.uml2.uml.MergeNode;
-import org.eclipse.uml2.uml.ObjectFlow;
-import org.eclipse.uml2.uml.OpaqueAction;
-import org.eclipse.uml2.uml.OutputPin;
-import org.eclipse.uml2.uml.StructuredActivityNode;
-import org.eclipse.uml2.uml.UMLPackage;
-
-
-/**
- * Utility class for {@link ObjectFlow}
- */
-public class ObjectFlowUtil {
-
- /**
- * Return whether we can create a new object flow starting from this action by adding an intermediate output pin at it.
- *
- * @param action
- * the action to start from
- * @return whether action accept new output pin
- */
- public static boolean canStartNewObjectFlow(Action action) {
- // CallOperationAction and CallBehaviorAction have pre-defined pins which are all represented.
- // SendObjectAction have only two input pins which are all represented.
- // SendSignalAction has only pre-defined input pins which are all represented.
- return (action instanceof OpaqueAction) || (action instanceof AcceptEventAction);
- }
-
- /**
- * Return whether we can create a new object flow ending to this action by adding an intermediate input pin at it.
- *
- * @param action
- * the action to end to
- * @return whether action accept new input pin
- */
- public static boolean canEndNewObjectFlow(Action action) {
- // CallOperationAction and CallBehaviorAction have pre-defined pins which are all represented.
- // SendObjectAction have only two input pins which are all represented.
- // SendSignalAction has only pre-defined input pins which are all represented.
- // AcceptEventAction has no input pin
- return action instanceof OpaqueAction;
- }
-
- /**
- * Check condition on Object flows
- * @param container container of the object flow
- * @param linkInstance object flow itself
- * @param source
- * @param target
- * @return
- */
- public static boolean canExistObjectFlow(Activity container, ObjectFlow linkInstance, ActivityNode source, ActivityNode target) {
- try {
- if(source instanceof Action) {
- // rule validateObjectFlow_validateNoActions
- // rule workaround by addition of pins in case of Action
- if(!ObjectFlowUtil.canStartNewObjectFlow((Action)source)) {
- return false;
- }
- }
- if(source instanceof InputPin) {
- // rule validateInputPin_validateOutgoingEdgesStructuredOnly
- if(source.getOwner() instanceof StructuredActivityNode) {
- if(target != null && !source.getOwner().equals(target.getInStructuredNode())) {
- return false;
- }
- } else {
- return false;
- }
- }
- if(source instanceof InitialNode) {
- // rule validateInitialNode_validateControlEdges
- return false;
- }
- if(source instanceof FinalNode) {
- // rule validateFinalNode_validateNoOutgoingEdges
- return false;
- }
- if(source instanceof JoinNode) {
- // rule validateJoinNode_validateOneOutgoingEdge
- if(!source.getOutgoings().isEmpty()) {
- return false;
- }
- /*
- * rule validateJoinNode_validateIncomingObjectFlow :
- * We do not prevent creation of an outgoing ObjectFlow even if there is no incoming ObjectFlow.
- * We let the possibility that the user intends to add an incoming ObjectFlow later.
- */
- }
- if(source instanceof ForkNode) {
- // rule validateForkNode_validateEdges on source Fork node
- ActivityEdge outgoingControlFlow = source.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = source.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- // there is a ControlFlow which means there must be no ObjectFlow
- return false;
- }
- }
- if(source instanceof MergeNode) {
- //rule validateMergeNode_validateOneOutgoingEdge
- if(!source.getOutgoings().isEmpty()) {
- return false;
- }
- // rule validateMergeNode_validateEdges on source Merge node
- ActivityEdge outgoingControlFlow = source.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = source.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- // there is a ControlFlow which means there must be no ObjectFlow
- return false;
- }
- }
- if(source instanceof DecisionNode) {
- // rule validateDecisionNode_validateEdges on source Decision node
- ActivityEdge outgoingControlFlow = source.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = source.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- // there is a ControlFlow which means there must be no ObjectFlow
- return false;
- }
- }
- if(source instanceof ActivityParameterNode) {
- // rule validateActivityParameterNode_validateIncomingOrOutgoing
- EList<ActivityEdge> incomings = source.getIncomings();
- if(!incomings.isEmpty()) {
- return false;
- }
- }
- if(target instanceof Action) {
- // rule validateObjectFlow_validateNoActions
- // rule workaround by addition of pins in case of Action
- if(!ObjectFlowUtil.canEndNewObjectFlow((Action)target)) {
- return false;
- }
- }
- if(target instanceof OutputPin) {
- // rule validateOutputPin_validateIncomingEdgesStructuredOnly
- if(target.getOwner() instanceof StructuredActivityNode) {
- if(source != null && !target.getOwner().equals(source.getInStructuredNode())) {
- return false;
- }
- } else {
- return false;
- }
- }
- if(target instanceof InitialNode) {
- // rule validateInitialNode_validateNoIncomingEdges
- return false;
- }
- if(target instanceof JoinNode) {
- // rule validateJoinNode_validateIncomingObjectFlow
- ActivityEdge outgoingControlFlow = target.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null) {
- // the outgoing edge is a ControlFlow which means there must be no incoming ObjectFlow
- return false;
- }
- }
- if(target instanceof ForkNode) {
- // rule validateForkNode_validateOneIncomingEdge
- if(!target.getIncomings().isEmpty()) {
- return false;
- }
- // rule validateForkNode_validateEdges on target Fork node
- ActivityEdge outgoingControlFlow = target.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = target.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- // there is a ControlFlow which means there must be no ObjectFlow
- return false;
- }
- }
- if(target instanceof MergeNode) {
- // rule validateMergeNode_validateEdges on target Merge node
- ActivityEdge outgoingControlFlow = target.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = target.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- // there is a ControlFlow which means there must be no ObjectFlow
- return false;
- }
- }
- if(target instanceof DecisionNode) {
- // rule validateDecisionNode_validateIncomingOutgoingEdges
- if(target.getIncomings().size() >= 2) {
- // no more than two incoming edges
- return false;
- }
- // rule validateDecisionNode_validateEdges on target Decision node
- ActivityEdge outgoingControlFlow = target.getOutgoing(null, true, UMLPackage.eINSTANCE.getControlFlow());
- ActivityEdge incomingControlFlow = target.getIncoming(null, true, UMLPackage.eINSTANCE.getControlFlow());
- if(outgoingControlFlow != null || incomingControlFlow != null) {
- /*
- * There is a ControlFlow which means there must be no
- * ObjectFlow but the decision flow itself.
- * We let the user insert up to one ObjectFlow for being
- * able to select the decision flow among existing
- * input flows.
- */
- if(target.getIncoming(null, true, UMLPackage.eINSTANCE.getObjectFlow()) != null) {
- // there is already an object flow which is intended to become the decision flow
- return false;
- }
- }
- }
- if(target instanceof ActivityParameterNode) {
- // rule validateActivityParameterNode_validateIncomingOrOutgoing
- EList<ActivityEdge> outgoings = target.getOutgoings();
- if(!outgoings.isEmpty()) {
- return false;
- }
- }
- return true;
- } catch (Exception e) {
- Activator.log.error(e);
- return false;
- }
- }
-
- /**
- * Return whether a pin must be inserted to create a new object flow starting from this activity node.
- *
- * @param node
- * the activity node to start from
- * @return whether a pin must can inserted to create an object flow from this node
- */
- public static boolean insertPinForStartingNewObjectFlow(ActivityNode node) {
- if(node instanceof Action) {
- return canStartNewObjectFlow((Action)node);
- }
- return false;
- }
-
- /**
- * Return whether a pin must be inserted to create a new object flow ending to this activity node.
- *
- * @param node
- * the activity node to end to
- * @return whether a pin must can inserted to create an object flow to this node
- */
- public static boolean insertPinForEndingNewObjectFlow(ActivityNode node) {
- if(node instanceof Action) {
- return canEndNewObjectFlow((Action)node);
- }
- return false;
- }
-
- /**
- * Insert the created output pin in the parent action
- *
- * @param parentAction
- * action to insert pin in
- * @param outputPin
- * output pin to insert
- */
- public static void insertOutputPin(Action parentAction, OutputPin outputPin) {
- if(parentAction instanceof OpaqueAction) {
- ((OpaqueAction)parentAction).getOutputValues().add(outputPin);
- } else if(parentAction instanceof AcceptEventAction) {
- ((AcceptEventAction)parentAction).getResults().add(outputPin);
- }
- }
-
- /**
- * Insert the created input pin in the parent action
- *
- * @param parentAction
- * action to insert pin in
- * @param inputPin
- * input pin to insert
- */
- public static void insertInputPin(Action parentAction, InputPin inputPin) {
- if(parentAction instanceof OpaqueAction) {
- ((OpaqueAction)parentAction).getInputValues().add(inputPin);
- }
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueBehaviorUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueBehaviorUtil.java deleted file mode 100644 index 802d4dae0ce..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueBehaviorUtil.java +++ /dev/null @@ -1,109 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.OpaqueBehavior;
-
-/**
- * This class encapsulates an <code>org.eclipse.uml2.uml.OpaqueBehavior</code><BR>
- */
-public class OpaqueBehaviorUtil {
-
- /**
- * Gets the value of the 'Body' attribute for the <code>OpaqueBehavior</code> at the given
- * index.
- *
- * @param index
- *
- * @return the value of 'Body'at the index i
- */
- // @unused
- public static String getBody(OpaqueBehavior behavior, int index) {
- return behavior.getBodies().get(index);
- }
-
- /**
- * Gets the value of the 'Body' attribute for the <code>OpaqueBehavior</code> for a given
- * language.
- *
- * @param language
- * the language in which the body is written
- * @return the value of 'Body' at the index i
- */
- // @unused
- public static String getBody(OpaqueBehavior behavior, String language) {
- int index = 0;
- String tmp = "";
-
- index = getBodyIndex(behavior, language);
- if((index > -1) && (index < behavior.getBodies().size())) {
- tmp = behavior.getBodies().get(index);
- }
-
- return tmp;
- }
-
- /**
- * Returns the index of the body for a given langauge.
- *
- * @param language
- * the language of the body to find
- * @return the index of the body in the list or -1 if not found
- */
- public static int getBodyIndex(OpaqueBehavior behavior, String language) {
- int index = 0;
- boolean isFound = false;
-
- // test if the language exists
- Iterator<String> it = behavior.getLanguages().iterator();
- while(it.hasNext() && !isFound) {
- String lang = it.next();
- if(lang.equalsIgnoreCase(language)) {
- isFound = true;
- } else {
- index++;
- }
- }
- // returns -1 if not found
- if(!isFound) {
- index = -1;
- }
- return index;
- }
-
- /**
- * Sets the value of the 'Body' attribute for a given language.
- *
- * @param value
- * the new value of the 'Body'
- * @param language
- * the langauge of the body to set
- */
- // @unused
- public static void setBody(OpaqueBehavior behavior, String value, String language) {
- // get the index of the given language
- int index = getBodyIndex(behavior, language);
- if(index == -1) {
- // this language does not exists, adds it to the end of the list
- behavior.getLanguages().add(language);
- behavior.getBodies().add(value);
- } else {
- // the language was found, change the value of the language
- behavior.getBodies().set(index, value);
- }
- }
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueExpressionUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueExpressionUtil.java deleted file mode 100644 index 3d6e915282a..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OpaqueExpressionUtil.java +++ /dev/null @@ -1,120 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-
-/**
- * Util class for {@link OpaqueExpression}
- */
-public class OpaqueExpressionUtil {
-
- /**
- * Returns the body for an OpaqueExpression for the given language
- *
- * @param opaqueExpression
- * the opaque expression to edit.
- * @param language
- * the language in which the body is written
- * @return the body for the given language or the empty string if the language was not found
- */
- public static String getBodyForLanguage(org.eclipse.uml2.uml.OpaqueExpression opaqueExpression, String language) {
- String body = "";
- if(language == null) {
- if(!opaqueExpression.getBodies().isEmpty()) {
- body = opaqueExpression.getBodies().get(0);
- }
- } else {
- // retrieve the index of the given language in the opaque Expression
- int index = opaqueExpression.getLanguages().indexOf(language);
- if(index != -1) {
- // language found. return the corresponding body in the bodies list.
- // List should be synchronized, ie having the same size, but be sure...
- if(index < opaqueExpression.getBodies().size()) {
- body = opaqueExpression.getBodies().get(index);
- }
- }
- }
- return body;
- }
-
- /**
- * sets the body for an OpaqueExpression for the given language.
- * <p>
- * If the language was already defined, it replaces the corresponding body. If the language was not already defined, it adds it to the list of
- * languages and adds the corresponding body.
- * <p>
- * A utility method, {@link OpaqueExpression#checkAndCorrectLists(org.eclipse.uml2.uml.OpaqueExpression)} is used to correct the language and body
- * lists.
- *
- * @param opaqueExpression
- * the opaque expression to edit.
- * @param language
- * the language in which the body is written
- * @param body
- * the body to save
- */
- public static void setBodyForLanguage(org.eclipse.uml2.uml.OpaqueExpression opaqueExpression, String language, String body) {
- // checks both lists by size
- checkAndCorrectLists(opaqueExpression);
- // checks if language exists, if not, creates one
- if(!opaqueExpression.getLanguages().contains(language)) {
- opaqueExpression.getLanguages().add(language);
- opaqueExpression.getBodies().add(body);
- } else {
- // retrieve the index of the given language in the opaque Expression
- int index = opaqueExpression.getLanguages().indexOf(language);
- // sets the body at the given index in the list of bodies.
- opaqueExpression.getBodies().set(index, body);
- }
- }
-
- /**
- * Checks body and languages list of an opaque expression.
- * <p>
- * It returns <code>true</code> if both lists have the same size. It returns <code>false</code> if one of the list was bigger than the other one.
- * In this latter case, one of the list was corrected, ie enough elements where added in the list
- *
- * @param opaqueExpression
- * the opaque expression to check
- * @return <code>true</code> if both lists already had the same size, <code>false</code> in
- * other cases.
- */
- public static boolean checkAndCorrectLists(org.eclipse.uml2.uml.OpaqueExpression opaqueExpression) {
- // both lists, languages and bodies, should have the same size
- final int bodySize = opaqueExpression.getBodies().size();
- final int languageSize = opaqueExpression.getLanguages().size();
- // check both size
- // if equals, lists are supposed synchronized, it is ok
- // if less body than languages, add bodies
- // if more body, add enough languages
- if(bodySize == languageSize) {
- return true;
- } else {
- final int difference = languageSize - bodySize;
- if(difference > 0) {
- // more languages strings than body strings, add enough bodies
- for(int i = 0; i < difference; i++) {
- opaqueExpression.getBodies().add("");
- }
- } else {
- // more body strings than language strings, add enough languages
- for(int i = 0; i < (-difference); i++) {
- opaqueExpression.getLanguages().add("");
- }
- }
- // lists had to be modified, return false...
- return false;
- }
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java deleted file mode 100644 index 7b4adf2b05d..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/OperationUtil.java +++ /dev/null @@ -1,221 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Constraint;
-import org.eclipse.uml2.uml.Operation;
-import org.eclipse.uml2.uml.Parameter;
-import org.eclipse.uml2.uml.ParameterDirectionKind;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Operation</code><BR>
- */
-public class OperationUtil {
-
- /**
- * return the custom label of the operation, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the operation
- */
- public static String getCustomLabel(Operation operation, int style) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" "); // adds " " first for correct display considerations
-
- // visibility
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(operation));
- }
-
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(" ");
- buffer.append(operation.getName());
- }
-
- //
- // parameters : '(' parameter-list ')'
- buffer.append("(");
- buffer.append(OperationUtil.getParametersAsString(operation, style));
- buffer.append(")");
-
- // return type
- if((style & ICustomAppearence.DISP_RT_TYPE) != 0) {
- buffer.append(OperationUtil.getReturnTypeAsString(operation, style));
- }
-
- // modifiers
- if((style & ICustomAppearence.DISP_MOFIFIERS) != 0) {
- String modifiers = OperationUtil.getModifiersAsString(operation);
- if(!modifiers.equals("")) {
- buffer.append("{");
- buffer.append(modifiers);
- buffer.append("}");
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns return parameter label as a string, string parametrized with a style mask.
- *
- * @param style
- * the mask that indicates which element to display
- * @return a string containing the return parameter type
- */
- private static String getReturnTypeAsString(Operation operation, int style) {
- boolean displayType = ((style & ICustomAppearence.DISP_RT_TYPE) != 0);
- boolean displayMultiplicity = ((style & ICustomAppearence.DISP_RT_MULTIPLICITY) != 0);
- StringBuffer label = new StringBuffer("");
-
- // Retrieve the return parameter (assume to be unique if defined)
- Parameter returnParameter = OperationUtil.getReturnParameter(operation);
- // Create the string for the return type
- if(returnParameter == null) {
- // no-operation: label = ""
-
- } else if(!displayType && !displayMultiplicity) {
- // no-operation: label = ""
-
- } else {
- label.append(": ");
- if(displayType) {
- label.append(TypedElementUtil.getTypeAsString(returnParameter));
- }
-
- if(displayMultiplicity) {
- label.append(MultiplicityElementUtil.getMultiplicityAsString(returnParameter));
- }
- }
- return label.toString();
- }
-
- /**
- * Returns operation parameters as a string, the label is customized using a bit mask
- *
- * @return a string containing all parameters separated by commas
- */
- private static String getParametersAsString(Operation operation, int style) {
- StringBuffer paramString = new StringBuffer();
- Iterator<Parameter> paramIterator = operation.getOwnedParameters().iterator();
- boolean firstParameter = true;
- while(paramIterator.hasNext()) {
- Parameter parameter = paramIterator.next();
- // Do not include return parameters
- if(!parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
-
-
-
- // get the label for this parameter
- String parameterString = ParameterUtil.getCustomLabel(parameter, style);
- if (!parameterString.trim().equals("")) {
- if (!firstParameter) {
- paramString.append(", ");
- }
- paramString.append(parameterString);
- firstParameter = false;
- }
- }
- }
- return paramString.toString();
- }
-
- /**
- * Returns operation modifiers as string, separated with comma.
- *
- * @return a string containing the modifiers
- */
- private static String getModifiersAsString(Operation operation) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
-
- // Return parameter modifiers
- Parameter returnParameter = OperationUtil.getReturnParameter(operation);
- if(returnParameter != null) {
- // non unique parameter
- if(!returnParameter.isUnique()) {
- buffer.append("nonunique");
- needsComma = true;
- }
-
- // return parameter has ordered values
- if(returnParameter.isOrdered()) {
- if(needsComma) {
- buffer.append(", ");
- }
- buffer.append("ordered");
- needsComma = true;
- }
- }
-
- // is the operation a query ?
- if(operation.isQuery()) {
- if(needsComma) {
- buffer.append(", ");
- }
- buffer.append("query");
- needsComma = true;
- }
-
- // is the operation redefining another operation ?
- Iterator<Operation> it = operation.getRedefinedOperations().iterator();
- while(it.hasNext()) {
- Operation currentOperation = it.next();
- if(needsComma) {
- buffer.append(", ");
- }
- buffer.append("redefines ");
- buffer.append(currentOperation.getName());
- needsComma = true;
- }
-
- // has the operation a constraint ?
- Iterator<Constraint> it2 = operation.getOwnedRules().iterator();
- while(it2.hasNext()) {
- Constraint constraint = it2.next();
- if(needsComma) {
- buffer.append(", ");
- }
- if(constraint.getSpecification() != null) {
- buffer.append(constraint.getSpecification().stringValue());
- }
- needsComma = true;
- }
-
- return buffer.toString();
- }
-
- /**
- * Gives the return parameter for this operation, or <code>null</code> if none exists.
- *
- * @return the return parameter of the operation or <code>null</code>
- */
- private static Parameter getReturnParameter(Operation operation) {
- // Retrieve the return parameter (assume to be unique if defined)
- Parameter returnParameter = null;
-
- Iterator<Parameter> it = operation.getOwnedParameters().iterator();
- while((returnParameter == null) && (it.hasNext())) {
- Parameter parameter = it.next();
- if(parameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) {
- returnParameter = parameter;
- }
- }
- return returnParameter;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java deleted file mode 100644 index 45a9370a0d5..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PackageUtil.java +++ /dev/null @@ -1,589 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2008, 2009 CEA LIST. - * - * - * 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: - * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation - * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.utils; - -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.eclipse.emf.common.notify.Notifier; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.TreeIterator; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EAnnotation; -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.uml2.uml.Collaboration; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Package; -import org.eclipse.uml2.uml.PackageImport; -import org.eclipse.uml2.uml.PackageableElement; -import org.eclipse.uml2.uml.Profile; -import org.eclipse.uml2.uml.ProfileApplication; -import org.eclipse.uml2.uml.Type; -import org.eclipse.uml2.uml.UMLFactory; -import org.eclipse.uml2.uml.UMLPackage; - -/** - * Utility class for <code>org.eclipse.uml2.uml.Package</code><BR> - */ -public class PackageUtil { - - /** - * Apply a profile and every subprofiles to a package. Also import types defined in profile - * - * @param profileToApply - * profile to apply on package - * @param package_ - * on which profiles are applied - * @param withSubProfiles - * true if subprofiles must be automatically imported - */ - public static boolean applyProfile(org.eclipse.uml2.uml.Package package_, org.eclipse.uml2.uml.Profile profileToApply, boolean withSubProfiles) { - - // Returns true if the model was modified - boolean isChanged = false; - - // if profile is not defined abort treatment - if(!profileToApply.isDefined()) { - return isChanged; - } - - // if same version of profile is applied do not re-apply it - ProfileApplication profileApplication = package_.getProfileApplication(profileToApply); - if(profileApplication != null) { - - EPackage previous_definition = profileApplication.getAppliedDefinition(); - EPackage new_definition = profileToApply.getDefinition(); - if(previous_definition == new_definition) { - return isChanged; - } - } - - // Apply main profile and import contained types - package_.applyProfile(profileToApply); - importTypes(package_, profileToApply); - isChanged = true; - - if(withSubProfiles) { - // Manage sub profiles - List<Profile> subProfiles = new ArrayList<Profile>(); - subProfiles = getSubProfiles(profileToApply); - - Iterator<Profile> iter = subProfiles.iterator(); - while(iter.hasNext()) { - Profile subProfile = iter.next(); - package_.applyProfile(subProfile); - importTypes(package_, subProfile); - } - } - - return isChanged; - } - - /** - * Retrieve recursively the subprofiles of package. - * - * @param profile - * - * @return an arrayList containing the subprofiles - */ - public static List<Profile> getSubProfiles(org.eclipse.uml2.uml.Package package_) { - List<Profile> subProfiles = new ArrayList<Profile>(); - - Iterator<Package> iter = package_.getNestedPackages().iterator(); - while(iter.hasNext()) { - - Object element = iter.next(); - if(element instanceof Profile) { - Profile currentSubProfile = (Profile)element; - subProfiles.add(currentSubProfile); - subProfiles.addAll(getSubProfiles(currentSubProfile)); - } else if(element instanceof org.eclipse.uml2.uml.Package) { - org.eclipse.uml2.uml.Package currentSubPackage = (org.eclipse.uml2.uml.Package)element; - subProfiles.addAll(getSubProfiles(currentSubPackage)); - } - } - return subProfiles; - } - - /** - * Returns the top package of the specified element, i.e. the model or profile that is the root element - * - * @return the top {@link Package} for the specified element - */ - public static Package getRootPackage(Element element) { - return getRootPackage(element.getNearestPackage()); - } - - /** - * Returns the top package of the specified package, i.e. the model or profile that is the root element - * - * @return the top {@link Package} for the specified element - */ - public static Package getRootPackage(Package package_) { - Element owner = package_.getOwner(); - - //Bug 370412: The package might not be contained in a Package - //(e.g. it can be contained in a Component). Search for the nearest - //package, excluding self (Package#getNearestPackage() returns self) - while(owner != null && !(owner instanceof Package)) { - owner = owner.getOwner(); - } - - if(owner == null) { - return package_; - } - - return getRootPackage((Package)owner); - } - - /** - * Import public type contained in the profileToApply into pkg. - * - * @param profileToApply - * profile that contains type to import - * @param pkg - * receive the types from profile - */ - private static void importTypes(Package pkg, Package profileToApply) { - - /** import public types of the profile */ - - // get visible members of the profile - EList<PackageableElement> visibleMemb = profileToApply.visibleMembers(); - Iterator<PackageableElement> iterator = visibleMemb.iterator(); - - while(iterator.hasNext()) { - Element elemt = iterator.next(); - - if(elemt instanceof Package) { - - // if the package is a model library the import it - // in the package on which the profile is applied - if(((Package)elemt).isModelLibrary()) { - PackageImport pi = UMLFactory.eINSTANCE.createPackageImport(); - pi.setImportedPackage((Package)elemt); - pkg.getPackageImports().add(pi); - } - } - } - } - - /** - * returns the list of the names of imported packages - * - * @param pkg - * the package that has element imports - * @return the list of the name of imported packages - */ - public static List<String> getImportedPackagesNames(Package pkg) { - List<String> packageNames = new ArrayList<String>(); - // iterate through package imports of the given package - Iterator<PackageImport> importedIt = pkg.getPackageImports().iterator(); - while(importedIt.hasNext()) { - PackageImport currentImport = importedIt.next(); - // get name of the imported package and adds it to the result list - String currentName = currentImport.getImportedPackage().getName(); - packageNames.add(currentName); - } - return packageNames; - } - - /** - * Removes the last definition of a profile, and in its nested profiles - * - * @param thepackage - * profile to clean - */ - // @unused - public static void removeLastDefinition(Package thepackage) { - removeLastDefinition(thepackage, true); - } - - /** - * Removes the last definition of a profile - * - * @param thepackage - * profile to clean - * @param recursive - * boolean <code>true</code> if the clean is recursive, i.e. nested profiles must be - * clean - */ - public static void removeLastDefinition(Package thepackage, boolean recursive) { - // he wants to define - if(thepackage instanceof Profile) { - EPackage pak = ((Profile)thepackage).getDefinition(); - ((EAnnotation)pak.eContainer()).getContents().remove(pak); - } - if(recursive) { - Iterator<Package> it = thepackage.getNestedPackages().iterator(); - while(it.hasNext()) { - Package p = it.next(); - removeLastDefinition(p, recursive); - } - } - } - - /** - * Define this package if it is a profile and its sub-profiles - * - * @param thePackage - * the package to define (if it is a profile) - */ - public static void defineProfiles(Package thePackage) { - // he wants to define - if(thePackage instanceof Profile) { - ((Profile)thePackage).define(); - } - Iterator<Package> it = thePackage.getNestedPackages().iterator(); - while(it.hasNext()) { - Package p = it.next(); - defineProfiles(p); - } - } - - /** - * Retrieve a type accessible in this Package, given its name. - * - * @param name - * the name of the type to find, which must not be <code>null</code> - * - * @return the type found or <code>null</code> if not found. - */ - public static Type findTypeByName(Package pack, String name) { - assert name != null : "Type Name should not be null"; - - // update method to find a type by its name - // 1. find the direct accessible types (in the package and the imported - // elements) - // 2. find in the subpackages and their import - // 3. find in all resources - - Iterator<Type> it = getAccessibleTypes(pack).iterator(); - while(it.hasNext()) { - Type t = it.next(); - if(name.equals(t.getName())) { - return t; - } - } - - Resource resource = pack.eResource(); - ResourceSet resourceSet = null; - if(resource != null) { - resourceSet = resource.getResourceSet(); - } - - if(resourceSet != null) { - return findTypeByName(resourceSet, name); - } - return null; - } - - /** - * Retrieve a collaboration accessible in this Package, given its name. - * - * @param name - * the name of the collaboration to find, which must not be <code>null</code> - * - * @return the collaboration found or <code>null</code> if not found. - */ - public static Collaboration findCollaborationByName(Package pack, String name) { - assert name != null : "Collaboration Name should not be null"; - - // update method to find a type by its name - // 1. find the direct accessible types (in the package and the imported - // elements) - // 2. find in the subpackages and their import - // 3. find in all resources - - Iterator<Collaboration> it = getAccessibleCollaborations(pack).iterator(); - while(it.hasNext()) { - Collaboration t = it.next(); - if(name.equals(t.getName())) { - return t; - } - } - - Resource resource = pack.eResource(); - ResourceSet resourceSet = null; - if(resource != null) { - resourceSet = resource.getResourceSet(); - } - - if(resourceSet != null) { - return findCollaborationByName(resourceSet, name); - } - return null; - } - - /** - * Returns a type given its name from a resource set. - * - * @param resourceSet - * the resource Set - * @param name - * the name of the type to find. It must not be <code>null</code> - * @return the found type or <code>null</code> if the type was not found - */ - private static Type findTypeByName(ResourceSet resourceSet, String name) { - TreeIterator<Notifier> iterator = resourceSet.getAllContents(); - - while(iterator.hasNext()) { - Notifier notifier = iterator.next(); - if(notifier instanceof Type) { - Type type = ((Type)notifier); - if(name.equals(type.getName())) { - return type; - } - } - } - return null; - } - - /** - * Returns a collaboration given its name from a resource set. - * - * @param resourceSet - * the resource Set - * @param name - * the name of the collaboration to find. It must not be <code>null</code> - * @return the found type or <code>null</code> if the collaboration was not found - */ - private static Collaboration findCollaborationByName(ResourceSet resourceSet, String name) { - TreeIterator<Notifier> iterator = resourceSet.getAllContents(); - - while(iterator.hasNext()) { - Notifier notifier = iterator.next(); - if(notifier instanceof Collaboration) { - Collaboration type = ((Collaboration)notifier); - if(name.equals(type.getName())) { - return type; - } - } - } - return null; - } - - /** - * Returns all accessible types in the model - * - * @param element - * the element from which all resources can be accessed - * @return the list of Types accessible in the model - */ - public static Set<Type> getAllTypes(Element element) { - SortedSet<Type> set = new TreeSet<Type>(new TypeNameComparator()); - - Resource resource = element.eResource(); - ResourceSet resourceSet = null; - if(resource != null) { - resourceSet = resource.getResourceSet(); - } - - if(resourceSet != null) { - TreeIterator<Notifier> iterator = resourceSet.getAllContents(); - - while(iterator.hasNext()) { - Notifier notifier = iterator.next(); - if(notifier instanceof Type && ((Type)notifier).getName() != null) { - set.add(((Type)notifier)); - } - } - } - return set; - } - - /** - * Returns all accessible Collaboration in the model - * - * @param element - * the element from which all resources can be accessed - * @return the list of Collaboration accessible in the model - */ - public static Set<Collaboration> getAllCollaborations(Element element) { - SortedSet<Collaboration> set = new TreeSet<Collaboration>(new TypeNameComparator()); - - Resource resource = element.eResource(); - ResourceSet resourceSet = null; - if(resource != null) { - resourceSet = resource.getResourceSet(); - } - - if(resourceSet != null) { - TreeIterator<Notifier> iterator = resourceSet.getAllContents(); - - while(iterator.hasNext()) { - Notifier notifier = iterator.next(); - if(notifier instanceof Collaboration && ((Collaboration)notifier).getName() != null) { - set.add(((Collaboration)notifier)); - } - } - } - return set; - } - - /** - * Get all possible types for an element owned by this package. - * - * @return a set of all available Types - */ - public static TreeSet<Type> getAccessibleTypes(Package pack) { - TreeSet<Type> set = new TreeSet<Type>(new TypeNameComparator()); - // umlTypeList is used to detect type listed twice in the proposed list - // this may occurs for example with indirect import of UMLPrimitiveTypes - // Set<String> umlTypeQNames = new HashSet<String>(); - - Iterator<NamedElement> it = pack.getMembers().iterator(); - // get direct members - while(it.hasNext()) { - NamedElement element = it.next(); - if((element instanceof Type) /* - * && (!(element instanceof Relationship)) - */) { - // Check for redundant type - // if (!umlTypeQNames.contains(element.getQualifiedName())) { - // /umlTypeQNames.add(element.getQualifiedName()); - // set.add((Type) element); - // } - set.add((Type)element); - } - } - - // Recursive call on parents - if((pack.getOwner() != null) && (pack.getOwner() instanceof Package)) { - - Iterator<Type> itParent = PackageUtil.getAccessibleTypes(pack.getNestingPackage()).iterator(); - - while(itParent.hasNext()) { - set.add(itParent.next()); - // Type currentType = itParent.next(); - - // if (!umlTypeQNames.contains(currentType.getQualifiedName())) - // { - // umlTypeQNames.add(currentType.getQualifiedName()); - // set.add(currentType); - // } - } - } - - return set; - } - - /** - * Get all possible Collaboration owned by this package. - * - * @return a set of all available Collaborations - */ - public static TreeSet<Collaboration> getAccessibleCollaborations(Package pack) { - TreeSet<Collaboration> set = new TreeSet<Collaboration>(new TypeNameComparator()); - - Iterator<NamedElement> it = pack.getMembers().iterator(); - // Get direct members - while(it.hasNext()) { - NamedElement element = it.next(); - if(element instanceof Collaboration) { - - set.add((Collaboration)element); - } - } - - // Recursive call on parents - if((pack.getOwner() != null) && (pack.getOwner() instanceof Package)) { - - Iterator<Collaboration> itParent = PackageUtil.getAccessibleCollaborations(pack.getNestingPackage()).iterator(); - - while(itParent.hasNext()) { - set.add(itParent.next()); - } - } - - return set; - } - - /** - * - * - * @return returns all nested elements of a package (classes, packages, interfaces, data types, - * properties, operations) Returned elements are of type org.eclipse.uml2.uml.Element - */ - public static Set<Element> getAllNestedElements(Package thePackage) { - Set<org.eclipse.uml2.uml.Element> nestedElements = new HashSet<Element>(); - Iterator<org.eclipse.uml2.uml.NamedElement> i = thePackage.getOwnedMembers().iterator(); - org.eclipse.uml2.uml.Element currentElement; - while(i.hasNext()) { - currentElement = i.next(); - nestedElements.add(currentElement); - // Package - if(currentElement instanceof org.eclipse.uml2.uml.Package) { - nestedElements.addAll((PackageUtil.getAllNestedElements((Package)currentElement))); - } - // Class - else if(currentElement instanceof org.eclipse.uml2.uml.Class) { - nestedElements.addAll(((org.eclipse.uml2.uml.Class)currentElement).getMembers()); - } - } - return nestedElements; - } - - /** - * Load Package from a specified URI - * - * @param uri - * URI of the file to load - * @param set - * ResourceSet - * @return the root Package - */ - public static org.eclipse.uml2.uml.Package loadPackage(URI uri, ResourceSet set) { - - org.eclipse.uml2.uml.Package package_ = null; - Resource resource = set.getResource(uri, true); - - if(resource != null) { - package_ = (org.eclipse.uml2.uml.Package)EcoreUtil.getObjectByType(resource.getContents(), UMLPackage.Literals.PACKAGE); - } else { - Activator.logException(new FileNotFoundException("Could not retrieve resource from URI : " + uri + ".")); - } - - return package_; - - } - - /** - * Comparator using type names - */ - static class TypeNameComparator implements Comparator<Type> { - - /** - * {@inheritDoc} - */ - public int compare(Type o1, Type o2) { - final String o1Name = ((o1.getName() != null) ? o1.getName() : ""); - final String o2Name = ((o2.getName() != null) ? o2.getName() : ""); - return o1Name.compareTo(o2Name); - } - - } -} diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java deleted file mode 100644 index ce38cf5ad51..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ParameterUtil.java +++ /dev/null @@ -1,225 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.Parameter;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Parameter</code><BR>
- */
-public class ParameterUtil {
-
- /**
- * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline
- * string if <code>multiline</code> is <code>false</code>.
- *
- * @param multiLine
- * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to
- * <code>false</code>.
- *
- * @return a string giving all modifiers for the property
- */
- public static String getModifiersAsString(Parameter parameter, boolean multiLine) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
- String NL = (multiLine) ? "\n" : " ";
-
- // Return parameter modifiers
- if(parameter.isOrdered()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "ordered");;
- }
- if(parameter.isUnique()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "unique");
- }
- if(parameter.isException()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "exception");
- }
- if(parameter.isStream()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "stream");
- }
-
- if(!buffer.toString().equals("")) {
- buffer.insert(0, "{");
- buffer.append("}");
- }
-
- return buffer.toString();
- }
-
- /**
- * Update the modifiers string
- *
- * @param buffer
- * the existing bufferString to append
- * @param needsComma
- * if it needs coma
- * @param NL
- * if it is multiline
- * @param message
- * the message top
- * @return true because the modifier string is no more empty
- */
- private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) {
- if(needsComma) {
- buffer.append(",");
- buffer.append(NL);
- }
- buffer.append(message);
- return true;
- }
-
- /**
- * return the full label of the Parameter.
- *
- * @return the string corresponding to the label of the parameter
- */
- public static String getLabel(Parameter parameter) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));
-
- // direction
- buffer.append(" ");
- buffer.append(parameter.getDirection().getLiteral());
-
- // name
- buffer.append(" ");
- if(parameter.getName() != null) {
- buffer.append(parameter.getName());
- }
-
- // type
- if(parameter.getType() != null) {
- buffer.append(": " + parameter.getType().getName());
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
-
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
- if(!multiplicity.trim().equals("[1]")) {
- buffer.append(multiplicity);
- }
-
- // default value
- if(parameter.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(parameter.getDefault());
- }
-
- // property modifiers
- buffer.append(ParameterUtil.getModifiersAsString(parameter, false));
-
- return buffer.toString();
- }
-
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Parameter parameter, int style) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(parameter));
- }
-
- // direction property
- if((style & ICustomAppearence.DISP_PARAMETER_DIRECTION) != 0) {
- buffer.append(" ");
- buffer.append(parameter.getDirection().getLiteral());
- }
-
- // name
- if((style & ICustomAppearence.DISP_PARAMETER_NAME) != 0) {
- buffer.append(" ");
- buffer.append(parameter.getName());
- }
-
- if((style & ICustomAppearence.DISP_PARAMETER_TYPE) != 0) {
- // type
- if(parameter.getType() != null) {
- buffer.append(": " + parameter.getType().getName());
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if((style & ICustomAppearence.DISP_PARAMETER_MULTIPLICITY) != 0) {
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(parameter);
- buffer.append(multiplicity);
- }
-
- if((style & ICustomAppearence.DISP_PARAMETER_DEFAULT) != 0) {
- // default value
- if(parameter.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(parameter.getDefault());
- }
- }
-
- if((style & ICustomAppearence.DISP_MOFIFIERS) != 0) {
- boolean multiLine = ((style & ICustomAppearence.DISP_MULTI_LINE) != 0);
- // property modifiers
- String modifiers = ParameterUtil.getModifiersAsString(parameter, multiLine);
- if(!modifiers.equals("")) {
- if(multiLine) {
- buffer.append("\n");
- }
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns the default value as a String
- *
- * @param equalSign
- * boolean set to <code>true</code> if the label must have the <code>=</code> sign
- * before the default value
- * @return the default value as a String
- */
- private static String getDefaultAsString(Parameter parameter, boolean equalSign) {
- String defaultString = "";
- // default value
- if((parameter.getDefault() != null) && !parameter.getDefault().equals("")) {
- if(equalSign) {
- defaultString += "= ";
- }
- defaultString += parameter.getDefault();
- }
- return "";
- }
-
- /**
- * Returns <code>true</code> if the given style has the given mask
- *
- * @param style
- * the style to check
- * @param mask
- * the mask to check
- * @return <code>true</code> if the style has the bit mask
- */
- static boolean hasStyle(int style, int mask) {
- return ((style & mask) != 0);
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java deleted file mode 100644 index 009248b612c..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PortUtil.java +++ /dev/null @@ -1,102 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Property;
-
-
-public class PortUtil extends PropertyUtil {
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Property property, int style) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(property));
- }
-
- // derived property
- if((style & ICustomAppearence.DISP_DERIVE) != 0) {
- if(property.isDerived()) {
- buffer.append("/");
- }
- }
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(" ");
- buffer.append(property.getName());
- }
-
- if((style & ICustomAppearence.DISP_TYPE) != 0) {
- if( (style &ICustomAppearence.DISP_CONJUGATED)!=0){
- if( ((Port)property).isConjugated()){
- buffer.append(": ~");
- }
- else{
- buffer.append(": ");
- }
- }
- else{
- buffer.append(": ");
- }
- // type
- if(property.getType() != null) {
- buffer.append( property.getType().getName());
- } else {
- buffer.append( TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if((style & ICustomAppearence.DISP_MULTIPLICITY) != 0) {
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property);
- buffer.append(multiplicity);
- }
-
- if((style & ICustomAppearence.DISP_DFLT_VALUE) != 0) {
- // default value
- if(property.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(property.getDefault());
- }
- }
-
- if((style & ICustomAppearence.DISP_MOFIFIERS) != 0) {
- boolean multiLine = ((style & ICustomAppearence.DISP_MULTI_LINE) != 0);
- // property modifiers
- String modifiers = PropertyUtil.getModifiersAsString(property, multiLine);
- if(!modifiers.equals("")) {
- if(multiLine) {
- buffer.append("\n");
- }
-
- if (!buffer.toString().endsWith(" ")){
- buffer.append(" ");
- }
-
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java deleted file mode 100644 index 8d5270fe756..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PrimitivesTypesUtils.java +++ /dev/null @@ -1,45 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-
-public class PrimitivesTypesUtils {
-
- private PrimitivesTypesUtils() {
- //to prevent instanciation
- }
-
- /** the string used for the uml boolean */
- public static final String UML_BOOLEAN = "Boolean";//$NON-NLS-1$
-
- /** the string used for UML integer */
- public static final String UML_INTEGER = "Integer"; //$NON-NLS-1$
-
- /** the string used for uml real */
- public static final String UML_REAL = "Real"; //$NON-NLS-1$
-
- /** the string used for UML string */
- public static final String UML_STRING = "String"; //$NON-NLS-1$
-
- /** the string used for uml unlimited natural */
- public static final String UML_UNLIMITED_NATURAL = "UnlimitedNatural"; //$NON-NLS-1$
-
- /** the string used for enumeration */
- public static final String ENUMERATION = "Enumeration"; //$NON-NLS-1$
-
- /** the string used for enumeration literal */
- public static final String ENUMERATION_LITERAL = "EnumerationLiteral"; //$NON-NLS-1$
-
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java deleted file mode 100644 index a9cd12f5589..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java +++ /dev/null @@ -1,234 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2012, 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - Handle dynamic profile applications in CDO
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.uml2.common.util.UML2Util;
-import org.eclipse.uml2.uml.Association;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A class containing static utility method regarding UML profiles
- *
- * @author Camille Letavernier
- *
- */
-public class ProfileUtil {
-
-
- /**
- * Checks if the profile applied has been changed since last application (definition does not match.
- *
- * @param _package
- * on which the profile is applied
- * @param _profile
- * the applied profile
- * @return true if the profile has changed
- */
- public static boolean isDirty(Package _package, Profile _profile) {
- boolean isDirty = false;
- if(_profile == null || _profile.eResource() == null) {
- return false;
- }
-
- // Retrieve model resourceSet
- ResourceSet pkge_resourceSet = _package.eResource().getResourceSet();
-
- if(pkge_resourceSet != null) {
-
- // Retrieve profile resource
- URI prof_URI = _profile.eResource().getURI();
- Resource modelResource = pkge_resourceSet.getResource(prof_URI, true);
-
- if(modelResource != null && modelResource.getContents().get(0) instanceof Profile) {
-
- // ckeck applied profile application definition vs profile definition referenced in file
- Profile profileInFile = (Profile)(modelResource.getContents().get(0));
-
- if(_package.getProfileApplication(_profile) != null) {
- EPackage appliedProfileDefinition = _package.getProfileApplication(_profile).getAppliedDefinition();
- EPackage fileProfileDefinition = null;
-
- // Check profiles qualified names to ensure the correct profiles are compared
- String appliedProfileName = _profile.getQualifiedName();
- String fileProfileName = profileInFile.getQualifiedName();
- if(!appliedProfileName.equals(fileProfileName)) {
-
- // The profile must be a subprofile
- Iterator<Profile> it = PackageUtil.getSubProfiles(profileInFile).iterator();
- while(it.hasNext()) {
- Profile current = it.next();
- fileProfileName = current.getQualifiedName();
- if(fileProfileName.equals(appliedProfileName)) {
- profileInFile = current;
- }
- }
- }
-
- fileProfileDefinition = profileInFile.getDefinition();
-
- // don't just test that the EPackage definitions are the
- // same object because in the CDO context they are not, even
- // though they are "the same package". Comparing the NSURIs
- // should suffice
- if ((appliedProfileDefinition == null)
- || (fileProfileDefinition == null)
- || !UML2Util.safeEquals(
- appliedProfileDefinition.getNsURI(),
- fileProfileDefinition.getNsURI())) {
-
- isDirty = true;
- }
- }
-
- }
- }
-
-
-
- return isDirty;
- }
-
- public static List<Stereotype> findAllSubStereotypes(Stereotype parentStereotype, Package umlPackage, boolean concreteOnly) {
- Collection<Stereotype> result = new LinkedHashSet<Stereotype>();
-
- for(Profile profile : umlPackage.getAllAppliedProfiles()) {
- List<Stereotype> allStereotypes = new LinkedList<Stereotype>();
- findAllStereotypes(profile, allStereotypes);
- for(Stereotype stereotype : allStereotypes) {
- if(concreteOnly && stereotype.isAbstract()) {
- continue; //Skip abstract stereotypes
- }
-
- if(isSubStereotype(parentStereotype, stereotype)) {
- result.add(stereotype);
- }
- }
-
- }
-
- return new LinkedList<Stereotype>(result);
- }
-
- public static boolean isSubStereotype(Stereotype parentStereotype, Stereotype childStereotype) {
- if(parentStereotype == childStereotype) {
- return true;
- }
- return childStereotype.getGenerals().contains(parentStereotype); //TODO : This is probably not recursive...
- }
-
- /**
- * Finds recursively all stereotypes contained in this profile
- *
- * @param profile
- *
- * @param result
- */
- public static void findAllStereotypes(Profile profile, List<Stereotype> result) {
- for(Stereotype stereotype : profile.getOwnedStereotypes()) {
- result.add(stereotype);
- }
- for(Package subPackage : profile.getNestedPackages()) {
- if(subPackage instanceof Profile) {
- Profile subProfile = (Profile)subPackage;
- findAllStereotypes(subProfile, result);
- }
- }
- }
-
- private static EPackage umlMetamodel = UMLPackage.eINSTANCE;
-
- public static List<EClass> getAllExtendedMetaclasses(Stereotype stereotype, boolean concreteClassesOnly) {
- List<Class> extendedMetaclasses = stereotype.getAllExtendedMetaclasses();
- Set<EClass> allMetaclasses = new LinkedHashSet<EClass>();
- for(Class extendedMetaclass : extendedMetaclasses) {
- EClass UMLEClass = findEClass(extendedMetaclass);
- allMetaclasses.addAll(EMFHelper.getSubclassesOf(UMLEClass, concreteClassesOnly));
- }
-
- return new LinkedList<EClass>(allMetaclasses);
- }
-
- private static EClass findEClass(Class metaclass) {
- for(EClassifier classifier : umlMetamodel.getEClassifiers()) {
- if(classifier instanceof EClass) {
- if(classifier.getName().equals(metaclass.getName())) {
- return (EClass)classifier;
- }
- }
- }
- return null;
- }
-
- /**
- * Searchs the association containing a member end matching the given name
- * in the given stereotype, and returns it if it is typed by a stereotype
- *
- * TODO : This method can probably be used in a single specific case and should probably not be here
- *
- * @param stereotype
- * @param associationName
- * @return
- */
- public static Property findStereotypedProperty(Stereotype stereotype, String associationName) {
- //associations loop
- associations: for(Association association : stereotype.getAssociations()) {
- //memberEnds loop
- for(Property memberEnd : association.getMemberEnds()) {
- if(memberEnd.getType() == stereotype) {
- //oppositeEnds loop
- for(Property oppositeEnd : association.getMemberEnds()) {
- if(oppositeEnd != memberEnd && oppositeEnd.getName().equals(associationName) && !association.getOwnedEnds().contains(oppositeEnd)) {
- if(oppositeEnd.getType() instanceof Stereotype) {
- return oppositeEnd;
- }
- break associations; //break the three loops
- }
- }
- }
- }
- }
-
- //FIXME : Do we really need to browse associations first ?
-
- //Search for properties which are not associations
- for(Property property : stereotype.getAllAttributes()) {
- if(property.getName().equals(associationName)) {
- if(property.getType() instanceof Stereotype) {
- return property;
- }
- }
- }
-
- return null;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java deleted file mode 100644 index 554e42e9feb..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/PropertyUtil.java +++ /dev/null @@ -1,352 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Property</code><BR>
- */
-public class PropertyUtil {
-
- /**
- * Get all properties that can be subset by this {@link Property} checks the type and the
- * multiplicity.
- *
- * @param property
- * property for which the list of subsettable properties are made
- * @param noCheck
- * set this parameter to <code>true</code> if multiplicity and type check should be
- * made for the computation
- * @return all properties that can be subset
- */
- public static List<Property> getSubsettablesProperties(Property property, boolean noCheck) {
- List<Property> list = new ArrayList<Property>();
-
- // subset properties:
- Iterator<NamedElement> it = property.getClass_().getMembers().iterator();
- while(it.hasNext()) {
-
- NamedElement element = it.next();
- if(element instanceof Property) {
- boolean isValid = true;
- Property subsettableProperty = (Property)element;
-
- // check it is not itself....
- if(subsettableProperty.equals(property)) {
- isValid = false;
- }
-
- // check types conformity
- if(!noCheck) {
- if(property.getType() != null && subsettableProperty.getType() != null) {
- if(!property.getType().conformsTo(subsettableProperty.getType())) {
- isValid = false;
- }
- } else {
- isValid = false;
- }
-
- // check multiplicity (only upper bound has an OCL rule)
- if((subsettableProperty.getUpper() != -1) && (property.getUpper() > subsettableProperty.getUpper())) {
- isValid = false;
- }
- }
-
- if(isValid) {
- list.add(subsettableProperty);
- }
- }
- }
- return list;
- }
-
- /**
- * Find a subsetted property given its name and a context to find it.
- *
- * @param name
- * the name of the property
- * @return the property found or <code>null</code> if the element was not found.
- */
- // @unused
- public static Property findSusbsettedPropertyByName(String propertyName, Property property, boolean noCheck) {
- Iterator<Property> it = PropertyUtil.getSubsettablesProperties(property, true).iterator();
- while(it.hasNext()) {
- Property tmpProperty = it.next();
- String tmpPropertyName = tmpProperty.getName();
- if(tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) {
- return tmpProperty;
- }
- }
- return null;
- }
-
- /**
- * Get all properties that can be redefined by this {@link Property}.
- *
- * @return all properties that can be redefined
- */
- public static List<Property> getRedefinableProperties(Property property) {
- List<Property> list = new ArrayList<Property>();
-
- // redefine-able properties:
- Iterator<NamedElement> it = property.getClass_().getInheritedMembers().iterator();
- while(it.hasNext()) {
- NamedElement element = it.next();
- if(element instanceof Property) {
- list.add((Property)element);
- }
- }
-
- // adds also already redefined members. In fact, when properties are
- // redefined, they
- // disappear from the inherited members list
- Iterator<Property> it2 = property.getRedefinedProperties().iterator();
- while(it2.hasNext()) {
- Property element = it2.next();
- list.add(element);
- }
- return list;
- }
-
- /**
- * Find a redefined property given its name and a context to find it.
- *
- * @param name
- * the name of the property
- * @return the property found or <code>null</code> if the element was not found.
- */
- public static Property findRedefinedPropertyByName(String propertyName, Property property) {
- Iterator<Property> it = PropertyUtil.getRedefinableProperties(property).iterator();
- while(it.hasNext()) {
- Property tmpProperty = it.next();
- String tmpPropertyName = tmpProperty.getName();
- if(tmpPropertyName != null && propertyName.equals(tmpPropertyName.trim())) {
- return tmpProperty;
- }
- }
- return null;
- }
-
- /**
- * Get the displayed string for the derived attribute of the property.
- *
- * @param property
- * the property
- * @return If the property is derived, return "/". Otherwise return an empty String
- */
- public static String getDerived(Property property) {
- return property.isDerived() ? "/" : "";
- }
-
- /**
- * return the full label of the property, given UML2 specification.
- *
- * @return the string corresponding to the label of the property
- */
- public static String getLabel(Property property) {
- StringBuffer buffer = new StringBuffer();
- // visibility
- buffer.append(" ");
- buffer.append(NamedElementUtil.getVisibilityAsSign(property));
-
- // derived property
- buffer.append(getDerived(property));
-
- // name
- buffer.append(" ");
- buffer.append(getName(property));
-
- // type
- if(property.getType() != null) {
- buffer.append(" : " + property.getType().getName());
- } else {
- buffer.append(" : " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
-
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property);
- if(!multiplicity.trim().equals("[1]")) {
- buffer.append(multiplicity);
- }
-
- // default value
- if(property.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(property.getDefault());
- }
-
- // property modifiers
- buffer.append(PropertyUtil.getModifiersAsString(property, false));
-
- return buffer.toString();
- }
-
- public static String getName(Property property) {
- if(property.getName() != null) {
- return property.getName();
- } else {
- return (NamedElementUtil.getDefaultNameWithIncrement(property));
- }
- }
-
- /**
- * return the custom label of the property, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the property
- */
- public static String getCustomLabel(Property property, int style) {
- StringBuffer buffer = new StringBuffer();
- // visibility
-
- buffer.append(" ");
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(property));
- }
-
- // derived property
- if((style & ICustomAppearence.DISP_DERIVE) != 0) {
- if(property.isDerived()) {
- buffer.append("/");
- }
- }
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(" ");
- buffer.append(property.getName());
- }
-
- if((style & ICustomAppearence.DISP_TYPE) != 0) {
- // type
- if(property.getType() != null) {
- buffer.append(": " + property.getType().getName());
- } else {
- buffer.append(": " + TypeUtil.UNDEFINED_TYPE_NAME);
- }
- }
-
- if((style & ICustomAppearence.DISP_MULTIPLICITY) != 0) {
- // multiplicity -> do not display [1]
- String multiplicity = MultiplicityElementUtil.getMultiplicityAsString(property);
- buffer.append(multiplicity);
- }
-
- if((style & ICustomAppearence.DISP_DFLT_VALUE) != 0) {
- // default value
- if(property.getDefault() != null) {
- buffer.append(" = ");
- buffer.append(property.getDefault());
- }
- }
-
- if((style & ICustomAppearence.DISP_MOFIFIERS) != 0) {
- boolean multiLine = ((style & ICustomAppearence.DISP_MULTI_LINE) != 0);
- // property modifiers
- String modifiers = PropertyUtil.getModifiersAsString(property, multiLine);
- if(!modifiers.equals("")) {
- if(multiLine) {
- buffer.append("\n");
- }
-
- if (!buffer.toString().endsWith(" ")){
- buffer.append(" ");
- }
-
- buffer.append(modifiers);
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns the modifier of the property, separated by a comma, as as single line if <code>multiline</code> is <code>false</code> or as a multiline
- * string if <code>multiline</code> is <code>false</code>.
- *
- * @param multiLine
- * boolean that indicates if the string should have several lines when set to <code>true</code> or only one line when set to
- * <code>false</code>.
- *
- * @return a string giving all modifiers for the property
- */
- public static String getModifiersAsString(Property property, boolean multiLine) {
- StringBuffer buffer = new StringBuffer();
- boolean needsComma = false;
- String NL = (multiLine) ? "\n" : " ";
-
- // Return property modifiers
- if(property.isReadOnly()) {
- buffer.append("readOnly");
- needsComma = true;
- }
- if(property.isDerivedUnion()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "union");
- }
- if(property.isOrdered()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "ordered");;
- }
- if(property.isUnique()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "unique");
- }
-
- // is the property redefining another property ?
- for(Property current : property.getRedefinedProperties()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "redefines ");
- buffer.append(current.getName());
- }
-
- // is the property subsetting another property ?
- for(Property current : property.getSubsettedProperties()) {
- needsComma = updateModifiersString(buffer, needsComma, NL, "subsets ");
- buffer.append(current.getName());
- }
-
- if(!buffer.toString().equals("")) {
- buffer.insert(0, "{");
- buffer.append("}");
- }
-
- return buffer.toString();
- }
-
- /**
- * Update the modifiers string
- *
- * @param buffer
- * the existing bufferString to append
- * @param needsComma
- * if it needs coma
- * @param NL
- * if it is multiline
- * @param message
- * the message top
- * @return true because the modifier string is no more empty
- */
- private static boolean updateModifiersString(StringBuffer buffer, boolean needsComma, String NL, String message) {
- if(needsComma) {
- buffer.append(",");
- buffer.append(NL);
- }
- buffer.append(message);
- return true;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java deleted file mode 100644 index aff8f747f3d..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/SignalUtil.java +++ /dev/null @@ -1,77 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Signal;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Signal</code><BR>
- */
-public class SignalUtil {
-
- /**
- * return the custom label of the signal, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the signal
- */
- public static String getCustomLabel(Signal signal, int style) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(" "); // adds " " first for correct display considerations
-
- // visibility
- if((style & ICustomAppearence.DISP_VISIBILITY) != 0) {
- buffer.append(NamedElementUtil.getVisibilityAsSign(signal));
- }
-
- // name
- if((style & ICustomAppearence.DISP_NAME) != 0) {
- buffer.append(" ");
- buffer.append(signal.getName());
- }
-
- //
- // parameters : '(' parameter-list ')'
- buffer.append("(");
- buffer.append(getPropertiesAsString(signal, style));
- buffer.append(")");
-
- return buffer.toString();
- }
-
- /**
- * Returns signal properties as a string, the label is customized using a bit mask
- *
- * @return a string containing all properties separated by commas
- */
- private static String getPropertiesAsString(Signal signal, int style) {
- StringBuffer propertiesString = new StringBuffer();
- boolean firstProperty = true;
- for(Property property : signal.getOwnedAttributes()) {
- // get the label for this property
- String propertyString = PropertyUtil.getCustomLabel(property, style);
- if(!propertyString.trim().equals("")) {
- if(!firstProperty) {
- propertiesString.append(", ");
- }
- propertiesString.append(propertyString);
- firstProperty = false;
- }
- }
- return propertiesString.toString();
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/StereotypeUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/StereotypeUtil.java deleted file mode 100644 index 0b8c9b140e3..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/StereotypeUtil.java +++ /dev/null @@ -1,686 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2008 CEA LIST. - * - * - * 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: - * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation - * - *****************************************************************************/ -package org.eclipse.papyrus.uml.tools.utils; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.emf.common.util.BasicEList; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.papyrus.infra.core.services.ServiceException; -import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; -import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService; -import org.eclipse.uml2.uml.Association; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.Classifier; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.EnumerationLiteral; -import org.eclipse.uml2.uml.Extension; -import org.eclipse.uml2.uml.Image; -import org.eclipse.uml2.uml.NamedElement; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Stereotype; -import org.eclipse.uml2.uml.util.UMLUtil; - -/** - * Utility class for Stereotypes. - */ -public class StereotypeUtil { - - protected static final String QUOTE = "\""; - - protected static final String SPACE_SEPARATOR = "#"; - - protected static final String EQUAL_SEPARATOR = "="; - - protected static final String PROPERTY_VALUE_SEPARATOR = "|"; - - protected static final String SETREOTYPE_WITH_VALUE_SEPARATOR = ";"; - - protected static final String ST_LEFT = String.valueOf("\u00AB"); - - protected static final String ST_RIGHT = String.valueOf("\u00BB"); - - public static final String BASE_PREFIX = "base_"; //$NON-NLS-N$ - - /** - * returns the list of all super stereotypes for the specified stereotype - * - * @param stereotype - * the stereotype for which super-stereotypes are looked for. - * @return the list of all stereotypes from which the specified stereotype inherits - */ - public static List<Stereotype> getAllSuperStereotypes(Stereotype stereotype) { - List<Stereotype> generalStereotypes = new ArrayList<Stereotype>(); - for(Classifier generalClassifier : stereotype.getGenerals()) { - if(generalClassifier instanceof Stereotype) { - generalStereotypes.add((Stereotype)generalClassifier); - generalStereotypes.addAll(getAllSuperStereotypes((Stereotype)generalClassifier)); - } - } - return generalStereotypes; - } - - /** - * Parse the stereotype image and select those that have an "icon" kind (EAnnotation). - * - * @param stereotype - * to parse - * - * @return a EList of {@link Image} - */ - public static EList<Image> getIcons(Stereotype stereotype) { - - EList<Image> icons = new BasicEList<Image>(); - - Iterator<Image> it = stereotype.getIcons().iterator(); - while(it.hasNext()) { - Image image = it.next(); - if("icon".equals(ImageUtil.getKind(image))) { - icons.add(image); - } - } - - return icons; - } - - /** - * Returns the list of names (not qualified) of properties to display. - * - * @param stereotype - * @param stPropList - * - * @return - */ - private static List<String> getStereoPropertiesToDisplay(org.eclipse.uml2.uml.Stereotype stereotype, List<String> stPropList) { - ArrayList<String> result = new ArrayList<String>(); - - Iterator<String> propIter = stPropList.iterator(); - while(propIter.hasNext()) { - String currentProp = propIter.next(); - if(currentProp.substring(0, currentProp.lastIndexOf(".")).equals(stereotype.getQualifiedName())) { - result.add(currentProp.substring(currentProp.lastIndexOf(".") + 1, currentProp.length())); - } - } - return result; - } - - /** - * return string that contains value of properties of applied stereotype - * - * @param stereotypesPropertiesToDisplay - * list of properties of stereotype to display grammar= - * {<B>stereotypequalifiedName</B>'.'<B>propertyName</B>','}* - * - * @return a string withe the following grammar grammar= - * {'\u00AB'<B>StereotypeName</B>'\u00BB''#' - * {<B>propertyName</B>'='<B>propertyValue</B>'|'}*';'}* - */ - public static String getPropertiesValues(String stereotypesPropertiesToDisplay, Element umlElement) { - HashSet<org.eclipse.uml2.uml.Stereotype> stereoSet = new HashSet<org.eclipse.uml2.uml.Stereotype>(); - ArrayList<String> stPropList = new ArrayList<String>(); - - String propValues = ""; - - // fill our data structure in order to generate the string - StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ","); - while(propStringTokenizer.hasMoreElements()) { - // extract property to display - String propertyQN = propStringTokenizer.nextToken(); - // stereotype - String stereotypeQN = propertyQN.substring(0, propertyQN.indexOf(".")); - - Stereotype stereotype = umlElement.getAppliedStereotype(stereotypeQN); - if(stereotype != null) { - stereoSet.add(stereotype); - } - stPropList.add(propertyQN); - } - - // Display each stereotype - Iterator<org.eclipse.uml2.uml.Stereotype> stereoIter = stereoSet.iterator(); - while(stereoIter.hasNext()) { - org.eclipse.uml2.uml.Stereotype stereotype = stereoIter.next(); - // display the stereotype - propValues = propValues + ST_LEFT + stereotype.getName() + ST_RIGHT + SPACE_SEPARATOR; - // get the set of property to display - Iterator<String> stPropIter = getStereoPropertiesToDisplay(stereotype, stPropList).iterator(); - - // display each property - while(stPropIter.hasNext()) { - String stProp = stPropIter.next(); - // get the property - org.eclipse.uml2.uml.Property currentProp = getPropertyByName(stereotype, stProp); - - if(currentProp == null) { - return "No value"; - } - propValues += displayPropertyValue(stereotype, currentProp, umlElement, PROPERTY_VALUE_SEPARATOR); - }// display each property - if(propValues.endsWith(PROPERTY_VALUE_SEPARATOR)) { - propValues = propValues.substring(0, propValues.lastIndexOf(PROPERTY_VALUE_SEPARATOR)); - } - propValues = propValues + SETREOTYPE_WITH_VALUE_SEPARATOR; - }// end display each property - - return propValues; - } - - /** - * Computes the display of a property value. - * - * @param stereotype - * the stereotype that contains the property to be displayed - * @param property - * the property to be displayed - * @param umlElement - * the element that is stereotyped by the specified - * @param separator - * the separator between each property value, in case several properties are - * displayed for the same property - * @return a string corresponding to the property value - */ - public static String displayPropertyValue(Stereotype stereotype, Property property, Element umlElement, String separator) { - org.eclipse.uml2.uml.Type propType = property.getType(); - - // property type is an enumeration - if(propType instanceof org.eclipse.uml2.uml.Enumeration) { - return getPropertyValueForEnumerationType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator); - } - - // property type is a metaclass - else if((propType instanceof org.eclipse.uml2.uml.Class) && (propType.getAppliedStereotypes() != null) && (propType.getAppliedStereotypes().size() > 0) && propType.getAppliedStereotypes().get(0).getName().equals("Metaclass")) { - return getPropertyValueForMetaclassType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator,false); - } - // property type is a stereotype - else if(propType instanceof org.eclipse.uml2.uml.Stereotype) { - return getPropertyValueForStereotypeType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator,false); - } - // property is a composite class - else if((propType instanceof org.eclipse.uml2.uml.Class) && !(propType instanceof org.eclipse.uml2.uml.Stereotype) && property.isComposite()) { - return /* FIXME stProp + */property.getName() + EQUAL_SEPARATOR + property.getName() + separator; - } - - // otherwise - else { - return getPropertyValue(property, stereotype, umlElement, EQUAL_SEPARATOR, separator,false); - } - } - - - - /** - * Computes the display of a property value. - * - * @param stereotype - * the stereotype that contains the property to be displayed - * @param property - * the property to be displayed - * @param umlElement - * the element that is stereotyped by the specified - * @param separator - * the separator between each property value, in case several properties are - * displayed for the same property - * @return a string corresponding to the property value - */ - public static String displayPropertyValueToEdit(Stereotype stereotype, Property property, Element umlElement, String separator) { - org.eclipse.uml2.uml.Type propType = property.getType(); - - // property type is an enumeration - if(propType instanceof org.eclipse.uml2.uml.Enumeration) { - return getPropertyValueForEnumerationType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator); - } - - // property type is a metaclass - else if((propType instanceof org.eclipse.uml2.uml.Class) && (propType.getAppliedStereotypes() != null) && (propType.getAppliedStereotypes().size() > 0) && propType.getAppliedStereotypes().get(0).getName().equals("Metaclass")) { - return getPropertyValueForMetaclassType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator,true); - } - // property type is a stereotype - else if(propType instanceof org.eclipse.uml2.uml.Stereotype) { - return getPropertyValueForStereotypeType(property, stereotype, umlElement, EQUAL_SEPARATOR, separator,true); - } - // property is a composite class - else if((propType instanceof org.eclipse.uml2.uml.Class) && !(propType instanceof org.eclipse.uml2.uml.Stereotype) && property.isComposite()) { - return /* FIXME stProp + */property.getName() + EQUAL_SEPARATOR + property.getName() + separator; - } - // otherwise - else { - return getPropertyValue(property, stereotype, umlElement, EQUAL_SEPARATOR, separator, true); - } - } - - /** - * Retrieves a property of the specified stereotype, given its name - * - * @param stereotype - * the stereotype owner of the property - * @param propertyName - * the name of the property to find - */ - public static Property getPropertyByName(Stereotype stereotype, String propertyName) { - Iterator<Property> iterPro = stereotype.getAllAttributes().iterator(); - // from a string look for the property - while(iterPro.hasNext()) { - org.eclipse.uml2.uml.Property tmpProperty = iterPro.next(); - String name = ""; - if(tmpProperty != null) { - name = (tmpProperty.getName() != null) ? tmpProperty.getName() : ""; - } - if(name.equals(propertyName)) { - return tmpProperty; - } - } - return null; - } - - /** - * return string that contains value of properties of applied stereotype - * - * @param stereotypesPropertiesToDisplay - * list of properties of stereotype to display grammar= - * {<B>stereotypequalifiedName</B>'.'<B>propertyName</B>','}* - * - * @return a string with the following grammar grammar= - * {(<B>propertyName</B>'='<B>propertyValue</B>',')* - * <B>propertyName</B>'='<B>propertyValue</B>'} - */ - public static String getPropertiesValuesInBrace(String stereotypesPropertiesToDisplay, Element umlElement) { - String propertyValues = ""; - - HashSet<org.eclipse.uml2.uml.Stereotype> stereoSet = new HashSet<org.eclipse.uml2.uml.Stereotype>(); - ArrayList<String> stPropList = new ArrayList<String>(); - - // fill our data structure in order to generate the string - StringTokenizer propStringTokenizer = new StringTokenizer(stereotypesPropertiesToDisplay, ","); - while(propStringTokenizer.hasMoreElements()) { - // extract property to display - String propertyQN = propStringTokenizer.nextToken(); - // stereotype - String stereotypeQN = propertyQN.substring(0, propertyQN.indexOf(".")); - - Stereotype stereotype = umlElement.getAppliedStereotype(stereotypeQN); - if(stereotype != null) { - stereoSet.add(stereotype); - } - - stPropList.add(propertyQN); - } - - // Display each stereotype - Iterator<org.eclipse.uml2.uml.Stereotype> stereoIter = stereoSet.iterator(); - while(stereoIter.hasNext()) { - Stereotype stereotype = stereoIter.next(); - if(stereotype != null) { - propertyValues += displayPropertyValuesForStereotype(stereotype, stPropList, umlElement); - } - } - return propertyValues; - } - - public static String displayPropertyValuesForStereotype(Stereotype stereotype, List<String> stPropList, Element umlElement) { - StringBuffer buffer = new StringBuffer(); - - // add stereotype name. For "In Brace", display nothing - buffer.append(""); - // get the set of property to display - Iterator<String> stPropIter = getStereoPropertiesToDisplay(stereotype, stPropList).iterator(); - - // display each property - while(stPropIter.hasNext()) { - String stProp = stPropIter.next(); - // get the property - org.eclipse.uml2.uml.Property currentProp = null; - Iterator<Property> iterPro = stereotype.getAllAttributes().iterator(); - // from a string look for the property - while(iterPro.hasNext()) { - org.eclipse.uml2.uml.Property tmpProperty = iterPro.next(); - if(stProp.equals(tmpProperty.getName())) { - currentProp = tmpProperty; - } - } - - if(currentProp == null) { - return "No value"; - } - org.eclipse.uml2.uml.Type propType = currentProp.getType(); - - // property type is an enumeration - - if(propType instanceof org.eclipse.uml2.uml.Enumeration) { - buffer.append(getPropertyValueForEnumerationType(currentProp, stereotype, umlElement, EQUAL_SEPARATOR, ",")); - } - - // property type is a metaclass - else if((propType instanceof org.eclipse.uml2.uml.Class) && (propType.getAppliedStereotypes() != null) && (propType.getAppliedStereotypes().size() > 0) && propType.getAppliedStereotypes().get(0).getName().equals("Metaclass")) { - buffer.append(getPropertyValueForMetaclassType(currentProp, stereotype, umlElement, EQUAL_SEPARATOR, ",",false)); - } - - // property type is a stereotype - else if(propType instanceof org.eclipse.uml2.uml.Stereotype) { - buffer.append(getPropertyValueForStereotypeType(currentProp, stereotype, umlElement, EQUAL_SEPARATOR, ",",false)); - } - - // property is a composite class - else if((propType instanceof org.eclipse.uml2.uml.Class) && !(propType instanceof org.eclipse.uml2.uml.Stereotype) && currentProp.isComposite()) { - buffer.append(stProp + EQUAL_SEPARATOR + currentProp.getName() + ","); - } - - // otherwise - else { - buffer.append(getPropertyValue(currentProp, stereotype, umlElement, EQUAL_SEPARATOR, ",",false)); - } - }// display each property - - String propValues = buffer.toString(); - if(propValues.endsWith(",")) { - propValues = propValues.substring(0, propValues.lastIndexOf(",")); - } - - return propValues; - } - - /** - * return the string that represents the value of property when its type is an Enumeration - * - * @param property - * the property to display - * @param stereotype - * the stereotype that contains the property - * @param umlElement - * the umlelement on which the stereotype is applied - * @param EQUAL_SEPARATOR - * the separator between property and property value - * @param PROPERTY_VALUE_SEPARATOR - * the separator to end the exprestion - * @return String withe the following grammar propertyname EQUAL_SEPERATOR propertyValue - * PROPERTY_VALUE_SEPERATOR - */ - private static String getPropertyValueForEnumerationType(Property property, Stereotype stereotype, Element umlElement, final String EQUAL_SEPARATOR, final String PROPERTY_VALUE_SEPARATOR) { - String out = ""; - if((property.getUpper() == 1) && (umlElement.getValue(stereotype, property.getName()) != null)) { - if((property.getLower() != 0) || umlElement.getValue(stereotype, property.getName()) != null) { - if(property.isSetDefault() || umlElement.getValue(stereotype, property.getName()) != null) { - Object val = umlElement.getValue(stereotype, property.getName()); - if (val instanceof EnumerationLiteral) { - out = property.getName() + EQUAL_SEPARATOR + ((EnumerationLiteral)val).getLabel() + PROPERTY_VALUE_SEPARATOR; - } else { - out = property.getName() + EQUAL_SEPARATOR + val + PROPERTY_VALUE_SEPARATOR; - } - } else { - out = property.getName() + PROPERTY_VALUE_SEPARATOR; - } - } else { - out = property.getName() + PROPERTY_VALUE_SEPARATOR; - } - } - - // multiplicity is greater than one - else { - out = property.getName() + EQUAL_SEPARATOR + umlElement.getValue(stereotype, property.getName()) + PROPERTY_VALUE_SEPARATOR; - } - return out; - } - - /** - * return the string that represents the value of property when its type is a Metaclass - * - * @param property - * the property to display - * @param stereotype - * the stereotype that contains the property - * @param umlElement - * the umlelement on which the stereotype is applied - * @param EQUAL_SEPARATOR - * the separator between property and property value - * @param PROPERTY_VALUE_SEPARATOR - * the separator to end the exprestion - * @return String withe the following grammar propertyname EQUAL_SEPERATOR propertyValue - * PROPERTY_VALUE_SEPERATOR - */ - private static String getPropertyValueForMetaclassType(Property property, Stereotype stereotype, Element umlElement, final String EQUAL_SEPARATOR, final String PROPERTY_VALUE_SEPARATOR, boolean withQualifiedName) { - String out = ""; - - if((property.getUpper() == 1) && (umlElement.getValue(stereotype, property.getName()) != null) && (umlElement.getValue(stereotype, property.getName()) instanceof NamedElement)) { - if(withQualifiedName){ - out = property.getName() + EQUAL_SEPARATOR + ((NamedElement)(umlElement.getValue(stereotype, property.getName()))).getQualifiedName() + PROPERTY_VALUE_SEPARATOR; - } - else{ - out = property.getName() + EQUAL_SEPARATOR + ((NamedElement)(umlElement.getValue(stereotype, property.getName()))).getName() + PROPERTY_VALUE_SEPARATOR; - } - } - - // multiplicity greater than one - else if(property.getUpper() != 1) { - List values = (List)umlElement.getValue(stereotype, property.getName()); - ArrayList elementNames = new ArrayList(); - if(values != null) { - for(int count = 0; count < values.size(); count++) { - if(values.get(count) instanceof NamedElement) { - if(withQualifiedName){ - elementNames.add(((NamedElement)values.get(count)).getQualifiedName()); - } - else{ - elementNames.add(((NamedElement)values.get(count)).getName()); - } - } - } - } - out = property.getName() + EQUAL_SEPARATOR + elementNames + PROPERTY_VALUE_SEPARATOR; - } - - // multiplicity = 1 and property value null - else { - out = property.getName() + EQUAL_SEPARATOR + umlElement.getValue(stereotype, property.getName()) + PROPERTY_VALUE_SEPARATOR; - } - return out; - } - - /** - * return the string that represents the value of property when its type is a stereotype - * - * @param property - * the property to display - * @param stereotype - * the stereotype that contains the property - * @param umlElement - * the umlelement on which the stereotype is applied - * @param EQUAL_SEPARATOR - * the separator between property and property value - * @param PROPERTY_VALUE_SEPARATOR - * the separator to end the exprestion - * @return String withe the following grammar propertyname EQUAL_SEPERATOR propertyValue - * PROPERTY_VALUE_SEPERATOR - */ - private static String getPropertyValueForStereotypeType(Property property, Stereotype stereotype, Element umlElement, final String EQUAL_SEPARATOR, final String PROPERTY_VALUE_SEPARATOR, boolean withQualifiedName) { - String out = ""; - if((property.getUpper() == 1) && (umlElement.getValue(stereotype, property.getName()) != null)) { - - // retrieve the base element from the stereotype application - Object value = umlElement.getValue(stereotype, property.getName()); - Element baseElement = UMLUtil.getBaseElement((EObject)value); - - // display the base element's qualified name - if(withQualifiedName){ - out = property.getName() + EQUAL_SEPARATOR + ((NamedElement)baseElement).getQualifiedName() + PROPERTY_VALUE_SEPARATOR; - } - else{ - out = property.getName() + EQUAL_SEPARATOR + ((NamedElement)baseElement).getName() + PROPERTY_VALUE_SEPARATOR; - } - } - - // multiplicity greater than one - else if(property.getUpper() != 1) { - // retrieve the base element from the stereotype application - List values = (List)umlElement.getValue(stereotype, property.getName()); - ArrayList baseElements = new ArrayList(); - if(values != null) { - for(int k = 0; k < values.size(); k++) { - if(withQualifiedName){ - baseElements.add(((NamedElement)UMLUtil.getBaseElement((EObject)values.get(k))).getQualifiedName()); - } - else{ - baseElements.add(((NamedElement)UMLUtil.getBaseElement((EObject)values.get(k))).getName()); - } - } - } - - out = property.getName() + EQUAL_SEPARATOR + baseElements + PROPERTY_VALUE_SEPARATOR; - } - - // multiplicity = 1 and property value null - else { - out = property.getName() + EQUAL_SEPARATOR + (umlElement.getValue(stereotype, property.getName())) + PROPERTY_VALUE_SEPARATOR; - } - return out; - } - - /** - * return the string that represents the value of property - * - * @param property - * the property to display - * @param stereotype - * the stereotype that contains the property - * @param umlElement - * the umlelement on which the stereotype is applied - * @param EQUAL_SEPARATOR - * the separator between property and property value - * @param PROPERTY_VALUE_SEPARATOR - * the separator to end the exprestion - * @return String withe the following grammar propertyname EQUAL_SEPERATOR propertyValue - * PROPERTY_VALUE_SEPERATOR - */ - private static String getPropertyValue(Property property, Stereotype stereotype, Element umlElement, final String EQUAL_SEPARATOR, final String PROPERTY_VALUE_SEPARATOR,boolean withDelimitator) { - String out = ""; - if((property.getLower() != 0) || umlElement.getValue(stereotype, property.getName()) != null) { - if(property.isSetDefault() || umlElement.getValue(stereotype, property.getName()) != null) { - if(withDelimitator){ - String value= ""+umlElement.getValue(stereotype, property.getName()); - out = property.getName() + EQUAL_SEPARATOR + value + PROPERTY_VALUE_SEPARATOR; - if(value.contains("[")){ - out= out.replace("[", "["+QUOTE); - out= out.replace("]", QUOTE+"]"); - out= out.replace(", ", QUOTE+","+QUOTE); - } - else{ - out = property.getName() + EQUAL_SEPARATOR +QUOTE +value+QUOTE + PROPERTY_VALUE_SEPARATOR; - } - } - else{ - if(umlElement.getValue(stereotype, property.getName()) instanceof EObject){ - ILabelProvider labelProvider=getLabelProvider(property); - return out= property.getName() + EQUAL_SEPARATOR + labelProvider.getText(umlElement.getValue(stereotype, property.getName())) + PROPERTY_VALUE_SEPARATOR; - } - else{ - out = property.getName() + EQUAL_SEPARATOR + umlElement.getValue(stereotype, property.getName()) + PROPERTY_VALUE_SEPARATOR;} - } - } else { - out = property.getName() + PROPERTY_VALUE_SEPARATOR; - } - } else { - out = property.getName() + PROPERTY_VALUE_SEPARATOR; - - } - return out; - } - - public static ILabelProvider getLabelProvider(EObject eObject) { - try { - return ServiceUtilsForEObject.getInstance().getService(LabelProviderService.class, eObject).getLabelProvider(); - } catch (ServiceException ex) { - Activator.log.error(ex); - return new LabelProvider(); - } - } - /** - * Parse the stereotype image and select those that have an "shape" kind (EAnnotation). - * - * @param stereotype - * to parse - * - * @return a EList of {@link Image} - */ - public static EList<Image> getShapes(Stereotype stereotype) { - - EList<Image> shapes = new BasicEList<Image>(); - - Iterator<Image> it = stereotype.getIcons().iterator(); - while(it.hasNext()) { - Image image = it.next(); - if("shape".equals(ImageUtil.getKind(image))) { - shapes.add(image); - } - } - - return shapes; - } - - /** - * - * @param stereotype - * a stereotype - * @return - * the list of the properties of this stereotype, excluding the properties of the extending metaclasses - */ - public static final List<Property> getStereotypePropertiesWithoutBaseProperties(final Stereotype stereotype) { - final List<Property> properties = new ArrayList<Property>(); - for(Property property : stereotype.getOwnedAttributes()) { - if(isValidStereotypeProperty(property)) { - properties.add(property); - } - } - return properties; - } - - /** - * - * @param stereotype - * a stereotype - * @return - * the list of the properties of this stereotype, excluding the properties of the extending metaclasses - */ - public static final List<Property> getAllStereotypePropertiesWithoutBaseProperties(final Stereotype stereotype) { - final List<Property> properties = new ArrayList<Property>(); - for(Property property : stereotype.getAllAttributes()) { - if(isValidStereotypeProperty(property)) { - properties.add(property); - } - } - return properties; - } - /** - * - * @param property - * a property - * @return - * <code>true</code> if the property is a Metaclass property - */ - public static final boolean isValidStereotypeProperty(final Property property) { - Association association = property.getAssociation(); - if(association instanceof Extension) { - Extension ext = (Extension)association; - Class metaClass = ext.getMetaclass(); - if(property.getName().equals(BASE_PREFIX + metaClass.getName())) { //$NON-NLS-1$ - return false; - } - } - return true; - } -} diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TemplateSignatureUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TemplateSignatureUtil.java deleted file mode 100644 index ea0f3c73e47..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TemplateSignatureUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.uml2.uml.ParameterableElement;
-import org.eclipse.uml2.uml.TemplateParameter;
-import org.eclipse.uml2.uml.TemplateSignature;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.TemplateSignature</code><BR>
- */
-public class TemplateSignatureUtil {
-
- public static Set<org.eclipse.uml2.uml.Type> getAccessibleTypes(TemplateSignature signature) {
- Set<org.eclipse.uml2.uml.Type> list = new HashSet<org.eclipse.uml2.uml.Type>();
-
- for(Iterator<org.eclipse.uml2.uml.TemplateParameter> i = signature.getParameters().iterator(); i.hasNext();) {
- TemplateParameter current = i.next();
- ParameterableElement exposedElement = current.getOwnedParameteredElement();
- if(exposedElement instanceof org.eclipse.uml2.uml.Type) {
- list.add((org.eclipse.uml2.uml.Type)exposedElement);
- }
- }
- return list;
- }
-
- /**
- * Retrieve a type accessible in this Signature, given its name.
- *
- * @param name
- * the name of the type to find
- *
- * @return the type found or <code>null</code> if not found.
- */
- public static org.eclipse.uml2.uml.Type findTypeByName(TemplateSignature signature, String name) {
- org.eclipse.uml2.uml.Type type = null;
- boolean isFound = false;
- if("".equals(name)) {
- Activator.getDefault().getLog().log(
- new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Name parameter should not be an empty string."));
- } else {
- Iterator<org.eclipse.uml2.uml.Type> it = TemplateSignatureUtil.getAccessibleTypes(signature).iterator();
- while(!isFound && it.hasNext()) {
- org.eclipse.uml2.uml.Type t = it.next();
- if(t.getName().equals(name)) {
- isFound = true;
- type = t;
- }
- }
- }
-
- return type;
- }
-
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java deleted file mode 100644 index b7dca412feb..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypeUtil.java +++ /dev/null @@ -1,70 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.Type</code><BR>
- */
-public class TypeUtil {
-
- public final static String UNDEFINED_TYPE_NAME = "<Undefined>";
-
- /**
- * Get a string that displays the name of the type, and then its namespace.
- * <p>
- * For example: "String - UMLPrimitiveType"
- *
- * @return a string that displays information about the type
- */
- public static String getInfoString(Type type) {
- StringBuffer buffer = new StringBuffer();
- buffer.append(type.getName());
- buffer.append(" - ");
- String tmp = "";
- Iterator<Namespace> it = type.allNamespaces().iterator();
- while(it.hasNext()) {
- Namespace namespace = it.next();
- if(it.hasNext()) {
- tmp = NamedElement.SEPARATOR + namespace.getName() + tmp;
- } else {
- tmp = namespace.getName() + tmp;
- }
- }
- buffer.append(tmp);
- return buffer.toString();
- }
-
- /**
- *
- *
- * @param type
- * to check
- *
- * @return true if type is metaclass, else false
- */
- @Deprecated //use {@link Class#isMetaclass()} Check if a type is a metaclass.
- public static boolean isMetaclass(Type type) {
- if(type instanceof Class) {
- return ((Class)type).isMetaclass();
- }
- return false;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java deleted file mode 100644 index 84f0ea2503a..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/TypedElementUtil.java +++ /dev/null @@ -1,26 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Yann TANGUY (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import org.eclipse.uml2.uml.TypedElement;
-
-/**
- * Utility class for <code>org.eclipse.uml2.uml.TypedElement</code><BR>
- */
-public class TypedElementUtil {
-
- public static String getTypeAsString(TypedElement element) {
- return (element.getType() != null) ? element.getType().getName() : "<Undefined>";
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java deleted file mode 100644 index b5260edbc3e..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLStringValueConverter.java +++ /dev/null @@ -1,250 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.infra.emf.Activator;
-import org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter;
-import org.eclipse.papyrus.infra.emf.utils.MultiConvertedValueContainer;
-import org.eclipse.papyrus.infra.emf.utils.ConvertedValueContainer;
-import org.eclipse.papyrus.infra.emf.utils.StringValueConverterStatus;
-import org.eclipse.uml2.uml.DataType;
-import org.eclipse.uml2.uml.Enumeration;
-import org.eclipse.uml2.uml.EnumerationLiteral;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.PrimitiveType;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * ULM String converter
- * @author vl222926
- *
- */
-public class UMLStringValueConverter extends EMFStringValueConverter {
-
- final protected Map<EClass, NameResolutionHelper> nameResolutionHelpers = new HashMap<EClass, NameResolutionHelper>();
-
- private static final String THE_ENUMERATION_LITERAL_X_CANT_BE_FOUND = "The enumeration literal {0} can't be found";
-
- private static final String SOME_STRING_CANT_BE_RESOLVED_TO_FIND_X = "Some String can't be resolved to find {0}";
-
- private static final String NO_X_REPRESENTED_BY_Y_HAVE_BEEN_FOUND = "No {0} represented by {1} have been found";
-
- /**
- *
- * Constructor.
- *
- * @param context
- * the context used to resolve the value
- * @param multiValueSeparator
- * the string used to seprate values
- */
- public UMLStringValueConverter(final Namespace context, final String multiValueSeparator) {
- super(context, multiValueSeparator);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#dispose()
- *
- */
- @Override
- public void dispose() {
- super.dispose();
- nameResolutionHelpers.clear();
- }
-
- @Override
- protected int getFeatureUpperBound(Object feature) {
- if(feature instanceof Property) {
- return ((Property)feature).getUpper();
- }
- return super.getFeatureUpperBound(feature);
- }
-
- @Override
- protected EClassifier getFeatureType(Object feature) {
- final EClassifier featureType;
- if(feature instanceof Property) {
- final Type type = ((Property)feature).getType();
- if(type instanceof PrimitiveType) {
- final PrimitiveType pType = (PrimitiveType)type;
- final String name = pType.getName();
- if(PrimitivesTypesUtils.UML_BOOLEAN.equals(name)) {
- featureType = EcorePackage.eINSTANCE.getEBoolean();
- } else if(PrimitivesTypesUtils.UML_INTEGER.equals(name)) {
- featureType = EcorePackage.eINSTANCE.getEInt();
- } else if(PrimitivesTypesUtils.UML_REAL.equals(name)) {
- featureType = EcorePackage.eINSTANCE.getEDouble();
- } else if(PrimitivesTypesUtils.UML_STRING.equals(name)) {
- featureType = EcorePackage.eINSTANCE.getEString();
- } else if(PrimitivesTypesUtils.UML_UNLIMITED_NATURAL.equals(name)) {
- featureType = EcorePackage.eINSTANCE.getEInt();
- } else { //custom PrimitiveType
- featureType = EcorePackage.eINSTANCE.getEString();
- }
- } else if(type instanceof Enumeration) {
- featureType = UMLPackage.eINSTANCE.getEnumeration();
- } else if(type instanceof DataType) {//FIXME manage the data type
- featureType = EcorePackage.eINSTANCE.getEString();
- } else {
- featureType = type.eClass();
- }
- } else {
- featureType = super.getFeatureType(feature);
- }
- return featureType;
- }
-
-
- @Override
- public ConvertedValueContainer<?> deduceValueFromString(Object feature, String valueAsString) {
- final EClassifier featureType = getFeatureType(feature);
- if(feature instanceof Property) {
- return deduceValueFromString(feature, featureType, valueAsString);
- }
- return super.deduceValueFromString(feature, valueAsString);
- }
- /**
- *
- * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#deduceValueFromString(java.lang.Object, org.eclipse.emf.ecore.EClassifier,
- * java.lang.String)
- *
- * @param feature
- * @param featureType
- * @param valueAsString
- * @return
- */
- @Override
- protected ConvertedValueContainer<?> deduceValueFromString(Object feature, EClassifier featureType, String valueAsString) {
- if(featureType instanceof EClass && feature instanceof Property) {
- final int upperbound = getFeatureUpperBound(feature);
- boolean isMany = (upperbound > 1 || upperbound == -1);
- if(PrimitivesTypesUtils.ENUMERATION.equals(featureType.getName())) {
- return deduceEnumerationLiteralValue(isMany, valueAsString, (Enumeration)((Property)feature).getType());
- }
- }
- return super.deduceValueFromString(feature, featureType, valueAsString);
- }
-
-
- /**
- *
- * @see org.eclipse.papyrus.infra.emf.utils.EMFStringValueConverter#deduceEObjectValue(org.eclipse.emf.ecore.EObject, java.lang.Object,
- * org.eclipse.emf.ecore.EClass, boolean, java.lang.String)
- *
- * @param resolutionContext
- * @param feature
- * @param featureType
- * @param isMany
- * @param valueAsString
- * @return
- * @throws StringValueSolverException
- */
- @Override
- protected ConvertedValueContainer<?> deduceEObjectValue(EObject resolutionContext, Object feature, EClass eClass, boolean isMany, String valueAsString) {
- if(valueAsString!=null && !valueAsString.isEmpty() && resolutionContext instanceof Namespace) {
- IStatus iStatus = Status.OK_STATUS;
- final Collection<String> unresolvedValues = new ArrayList<String>();
- Namespace namespace = (Namespace)resolutionContext;
- ConvertedValueContainer<?> returnedValue = null;
- NameResolutionHelper helper = this.nameResolutionHelpers.get(eClass);
- if(helper == null) {
- helper = new NameResolutionHelper(namespace, eClass);
- this.nameResolutionHelpers.put(eClass, helper);
- }
- if(isMany) {
- final Collection<NamedElement> values = new HashSet<NamedElement>();
- for(final String str : valueAsString.split(this.multiValueSeparator)) {
- final List<NamedElement> elements = helper.getNamedElements(str);
- if(elements.size() == 1) {
- values.add(elements.get(0));
- } else {
- unresolvedValues.add(str);
- }
- if(!unresolvedValues.isEmpty()) {
- iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_CANT_BE_RESOLVED_TO_FIND_X, eClass.getName()), unresolvedValues);
- }
- returnedValue = new MultiConvertedValueContainer<NamedElement>(values, iStatus);
- }
- } else {
- final List<NamedElement> elements = helper.getNamedElements(valueAsString);
- if(elements.size() == 1) {
- //it is OK
- returnedValue = new ConvertedValueContainer<NamedElement>(elements.get(0), iStatus);
- } else {
- unresolvedValues.add(valueAsString);
- iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(NO_X_REPRESENTED_BY_Y_HAVE_BEEN_FOUND, eClass.getName(), valueAsString), unresolvedValues);
- returnedValue = new ConvertedValueContainer<Boolean>(null, iStatus);
- }
- }
- return returnedValue;
- }
- return super.deduceEObjectValue(resolutionContext, feature, eClass, isMany, valueAsString);
- }
-
- /**
- *
- * @param isMany
- * <code>true</code> if the feature isMany
- * @param valueAsString
- * the value to parse
- * @return
- * the result of the parsing
- */
- protected ConvertedValueContainer<?> deduceEnumerationLiteralValue(final boolean isMany, final String valueAsString, final Enumeration enumeration) {
- ConvertedValueContainer<?> returnedValue = null;
- IStatus iStatus = Status.OK_STATUS;
- final Collection<String> unresolvedValues = new ArrayList<String>();
- if(isMany) {
- final Collection<EnumerationLiteral> values = new ArrayList<EnumerationLiteral>();
- for(final String str : valueAsString.split(this.multiValueSeparator)) {
- final EnumerationLiteral lit = (EnumerationLiteral)enumeration.getMember(str);
- if(lit != null) {
- values.add(lit);
- } else {
- unresolvedValues.add(str);
- }
- }
- if(!unresolvedValues.isEmpty()) {
- iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, PrimitivesTypesUtils.ENUMERATION_LITERAL), unresolvedValues);
- }
- returnedValue = new MultiConvertedValueContainer<EnumerationLiteral>(values, iStatus);
- } else {
- final EnumerationLiteral lit = (EnumerationLiteral)enumeration.getMember(valueAsString);
- if(lit == null) {
- unresolvedValues.add(valueAsString);
- iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_ENUMERATION_LITERAL_X_CANT_BE_FOUND, valueAsString, PrimitivesTypesUtils.ENUMERATION_LITERAL), unresolvedValues);
- }
- returnedValue = new ConvertedValueContainer<EnumerationLiteral>(lit, iStatus);
- }
- return returnedValue;
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLUtil.java deleted file mode 100644 index 0731ffe2c82..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/UMLUtil.java +++ /dev/null @@ -1,324 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.uml2.uml.Class;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.ConnectableElement;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEvent;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.Profile;
-import org.eclipse.uml2.uml.Stereotype;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A Helper class for UML
- *
- * @author Camille Letavernier
- */
-//TODO/FIXME : Check implementations. Most of them are old and don't always match the
-//specification for some cases.
-public class UMLUtil {
-
- /**
- * Retrieve the UML semantic element from the given Object.
- * This method relies on {@link EMFHelper#getEObject(Object)} to resolve
- * an EObject from an Object, then checks if the resulting EObject is a
- * UML Element.
- *
- * @param source
- * The Object to resolve
- * @return
- * The UML semantic element, or null if it couldn't be resolved
- */
- public static Element resolveUMLElement(Object source) {
- EObject eElement = EMFHelper.getEObject(source);
-
- if(eElement instanceof Element) {
- return (Element)eElement;
- }
-
- return null;
- }
-
- /**
- * Tests if a class is a subclass of another class. The classes are described
- * by their className, in the UML Metamodel.
- *
- * @param className
- * @param superclassName
- * @return
- * True if the class className is a subclass of the class superclassName
- */
- public static boolean isSubClass(String className, String superclassName) {
- EClass eClass = (EClass)getUMLMetamodel().getEClassifier(className);
- EClass superClass = (EClass)getUMLMetamodel().getEClassifier(superclassName);
- return EMFHelper.isSubclass(eClass, superClass);
- }
-
- /**
- * Retrieve the EditingDomain for the given source object
- *
- * @param source
- * @return
- * The source object's editing domain, or null if it couldn't be found
- */
- public static EditingDomain resolveEditingDomain(Object source) {
- return EMFHelper.resolveEditingDomain(resolveUMLElement(source));
- }
-
- /**
- * @return the UML EPackage
- */
- public static EPackage getUMLMetamodel() {
- return UMLPackage.eINSTANCE;
- }
-
- /**
- * Search the given stereotype (By name) on the given UML Element.
- * If the search is not strict, the name may be the qualified name of a
- * sub-stereotype of an applied stereotype
- *
- * @param umlElement
- * The UML Element on which the stereotype is applied
- * @param stereotypeName
- * The qualified name of the stereotype
- * @param strict
- * If set to true, only a stereotype matching the exact qualified name
- * will be returned. Otherwise, any subtype of the given stereotype may be
- * returned. Note that if more than one stereotype is a subtype of the
- * given stereotype, the first matching stereotype is returned.
- * @return
- * The first matching stereotype, or null if none was found
- */
- public static Stereotype getAppliedStereotype(Element umlElement, String stereotypeName, boolean strict) {
- if(umlElement == null || stereotypeName == null) {
- return null;
- }
-
- Stereotype stereotype = umlElement.getAppliedStereotype(stereotypeName);
- if(strict || stereotype != null) {
- return stereotype;
- }
-
- //The parent stereotype is not always applicable...
- //stereotype = umlElement.getApplicableStereotype(stereotypeName);
-
- List<Stereotype> subStereotypes = findSubstereotypes(umlElement, stereotypeName);
-
- for(Stereotype subStereotype : subStereotypes) {
- if(umlElement.getAppliedStereotypes().contains(subStereotype)) {
- return subStereotype;
- }
- }
-
- return null;
- }
-
- /**
- * Finds the Stereotype matching the given name.
- * The search is done in the context of the given UML Element
- * (i.e. the Profiles applied on the Element's nearest package)
- *
- * @param umlElement
- * @param stereotypeName
- * @return
- */
- public static Stereotype findStereotype(Element umlElement, String stereotypeName) {
- if(umlElement == null || stereotypeName == null) {
- return null;
- }
-
- Stereotype stereotype = null;
- org.eclipse.uml2.uml.Package umlPackage = umlElement.getNearestPackage();
- if(umlPackage == null) {
- stereotype = umlElement.getApplicableStereotype(stereotypeName);
- } else {
- outerLoop: for(Profile profile : umlPackage.getAllAppliedProfiles()) {
- for(Stereotype ownedStereotype : profile.getOwnedStereotypes()) {
- if(ownedStereotype.getQualifiedName().equals(stereotypeName)) {
- stereotype = ownedStereotype;
- break outerLoop;
- }
- }
- }
- }
- return stereotype;
- }
-
- /**
- * Returns all stereotypes matching the given qualified stereotype name, and their substereotypes
- * The search is performed in the context of the given UML Element, i.e. the profiles applied
- * on the Element's nearest package
- *
- * @param umlElement
- * @param stereotypeName
- * @return
- */
- public static List<Stereotype> findSubstereotypes(Element umlElement, String stereotypeName) {
- if(umlElement == null || stereotypeName == null) {
- return null;
- }
-
- Set<Stereotype> stereotypes = new HashSet<Stereotype>();
- org.eclipse.uml2.uml.Package umlPackage = umlElement.getNearestPackage();
-
- if(umlPackage == null) {
- Stereotype stereotype = umlElement.getApplicableStereotype(stereotypeName);
- if(stereotype != null) {
- stereotypes.add(stereotype);
- }
- } else {
- for(Profile profile : umlPackage.getAllAppliedProfiles()) {
- for(Stereotype ownedStereotype : profile.getOwnedStereotypes()) {
- for(Stereotype superStereotype : getAllSuperStereotypes(ownedStereotype)) {
- if(stereotypeName.equals(superStereotype.getQualifiedName())) {
- stereotypes.add(ownedStereotype);
- }
- }
- }
- }
- }
-
- return new LinkedList<Stereotype>(stereotypes);
- }
-
- /**
- * Returns a collection of all super stereotypes of the given stereotype
- * (Including itself)
- *
- * @param stereotype
- * @return
- * A collection of all super stereotypes
- */
- public static Collection<Stereotype> getAllSuperStereotypes(Stereotype stereotype) {
- Set<Stereotype> result = new HashSet<Stereotype>();
- if(stereotype != null) {
- getAllSuperStereotypes(stereotype, result);
- }
- return result;
- }
-
- private static void getAllSuperStereotypes(Stereotype stereotype, Set<Stereotype> result) {
- result.add(stereotype);
- for(Classifier superClassifier : stereotype.getGenerals()) {
- if(superClassifier instanceof Stereotype && !result.contains(superClassifier)) {
- getAllSuperStereotypes((Stereotype)superClassifier, result);
- }
- }
- }
-
- /**
- * Retrieves the UML Class associated to the given Message
- *
- * @param message
- * @return the UML Class associated to the given Message
- */
- public static org.eclipse.uml2.uml.Class getContextClassForMessage(Message message) {
- MessageOccurrenceSpecification receiveEvent = (MessageOccurrenceSpecification)message.getReceiveEvent();
-
- if(receiveEvent == null) {
- return null;
- }
-
- return getContextClassForMessageOccurrence(receiveEvent);
- }
-
- /**
- * Retrieves the UML Class associated to the given MessageOccurrenceSpecification
- *
- * @param messageOccurrence
- * @return the UML Class associated to the given MessageOccurrenceSpecification
- */
- public static org.eclipse.uml2.uml.Class getContextClassForMessageOccurrence(MessageOccurrenceSpecification messageOccurrence) {
- List<Lifeline> lifelines = messageOccurrence.getCovereds();
- if(lifelines.isEmpty()) {
- return null; //We can't find the context
- } else if(lifelines.size() == 1) {
- Lifeline lifeline = lifelines.get(0);
- ConnectableElement element = lifeline.getRepresents();
- if(element == null) {
- return null;
- }
- Type type = element.getType();
- if(type instanceof org.eclipse.uml2.uml.Class) {
- org.eclipse.uml2.uml.Class clazz = (org.eclipse.uml2.uml.Class)type;
- return clazz;
- } else {
- return null; //The type is not a Class
- }
- } else {
- return null; //Too many contexts : which one should we choose ?
- }
- }
-
- /**
- * Finds the UML Class associated to the given MessageEvent
- *
- * @param event
- * @return the Class associated to the given MessageEvent
- */
- public static Class getContextClassForMessageEvent(MessageEvent event) {
- Collection<EStructuralFeature.Setting> settings = EMFHelper.getUsages(event);
- if(settings.isEmpty()) {
- return null;
- }
-
- if(settings.size() == 1) {
- EObject referer = settings.iterator().next().getEObject();
- if(referer instanceof MessageOccurrenceSpecification) {
- return UMLUtil.getContextClassForMessageOccurrence((MessageOccurrenceSpecification)referer);
- } else {
- return null;
- }
- }
-
- MessageOccurrenceSpecification referer = null;
- EObject newReferer = null;
-
- for(EStructuralFeature.Setting setting : settings) {
- newReferer = setting.getEObject();
- if(!(newReferer instanceof MessageOccurrenceSpecification)) {
- continue;
- }
-
- if(referer == null || referer == newReferer) {
- referer = (MessageOccurrenceSpecification)newReferer;
- } else {
- referer = null;
- break;
- }
- }
-
- if(referer == null) {
- return null;
- }
-
- return UMLUtil.getContextClassForMessageOccurrence(referer);
- }
-}
diff --git a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java b/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java deleted file mode 100644 index e0308513918..00000000000 --- a/sandbox/pasteInNewTable/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ValueSpecificationUtil.java +++ /dev/null @@ -1,334 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Remi SCHNEKENBURGER (CEA LIST) Remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-
-import org.eclipse.uml2.uml.Constraint;
-import org.eclipse.uml2.uml.Duration;
-import org.eclipse.uml2.uml.Expression;
-import org.eclipse.uml2.uml.InstanceValue;
-import org.eclipse.uml2.uml.Interval;
-import org.eclipse.uml2.uml.LiteralBoolean;
-import org.eclipse.uml2.uml.LiteralInteger;
-import org.eclipse.uml2.uml.LiteralNull;
-import org.eclipse.uml2.uml.LiteralString;
-import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
-import org.eclipse.uml2.uml.OpaqueExpression;
-import org.eclipse.uml2.uml.StringExpression;
-import org.eclipse.uml2.uml.TimeExpression;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.ValueSpecification;
-
-/**
- * Utility class for {@link ValueSpecification}
- */
-public class ValueSpecificationUtil {
-
- /** The * KeyWord to represent an unlimited integer (infinite) */
- private static final String UNLIMITED_KEYWORD = "*";
-
- private static final String INTERVAL_FORMAT = "%1s..%2s";
-
- /**
- * Get a string representing of a ValueSpecification
- *
- * @param specification
- */
- public static String getSpecificationValue(ValueSpecification specification) {
- String value = ""; //$NON-NLS-1$
- if(specification != null && specification.eClass() != null) {
- switch(specification.eClass().getClassifierID()) {
- case UMLPackage.LITERAL_STRING:
- value = ((LiteralString)specification).getValue();
- break;
- case UMLPackage.LITERAL_BOOLEAN:
- value = Boolean.toString(((LiteralBoolean)specification).booleanValue());
- break;
- case UMLPackage.LITERAL_INTEGER:
- value = Integer.toString(((LiteralInteger)specification).getValue());
- break;
- case UMLPackage.LITERAL_UNLIMITED_NATURAL:
- value = Integer.toString(((LiteralUnlimitedNatural)specification).getValue());
- if("-1".equals(value)) { //$NON-NLS-1$
- value = UNLIMITED_KEYWORD; //$NON-NLS-1$
- }
- break;
- case UMLPackage.LITERAL_NULL:
- break;
- case UMLPackage.OPAQUE_EXPRESSION:
- OpaqueExpression exp = (OpaqueExpression)specification;
- value = OpaqueExpressionUtil.getBodyForLanguage(exp, null); //$NON-NLS-1$
- break;
- case UMLPackage.INSTANCE_VALUE:
- if (((InstanceValue)specification).getInstance() != null) {
- value = ((InstanceValue)specification).getInstance().getName();
- }
- break;
- case UMLPackage.EXPRESSION:
- Expression expr = (Expression)specification;
- if(!expr.getOperands().isEmpty()) {
- StringBuffer operandsBuff = new StringBuffer(expr.getSymbol());
- operandsBuff.append("(");
- int initialLength = operandsBuff.length();
- for(ValueSpecification operand : expr.getOperands()) {
- if(operandsBuff.length() > initialLength) {
- operandsBuff.append(",");
- }
- operandsBuff.append(getSpecificationValue(operand));
- }
- operandsBuff.append(")");
- value = operandsBuff.toString();
- } else {
- value = expr.getSymbol();
- }
- break;
- case UMLPackage.STRING_EXPRESSION:
- // TODO
- break;
- case UMLPackage.DURATION:
- Duration durationExpr = (Duration)specification;
- if(durationExpr.getExpr() != null) {
- value = getSpecificationValue(durationExpr.getExpr());
- } else if(durationExpr.getObservations().size() > 0) {
- value = durationExpr.getObservations().get(0).getName();
- }
- break;
- case UMLPackage.TIME_EXPRESSION:
- TimeExpression timeExpr = (TimeExpression)specification;
- if(timeExpr.getExpr() != null) {
- value = getSpecificationValue(timeExpr.getExpr());
- } else if(timeExpr.getObservations().size() > 0) {
- value = timeExpr.getObservations().get(0).getName();
- }
- break;
- case UMLPackage.INTERVAL:
- case UMLPackage.TIME_INTERVAL:
- case UMLPackage.DURATION_INTERVAL:
- Interval interval = (Interval)specification;
- String min = getSpecificationValue(interval.getMin());
- String max = getSpecificationValue(interval.getMax());
- value = String.format(INTERVAL_FORMAT, min, max);
- break;
- default:
- {
- break;
- }
- }
- }
- return value;
- }
-
-
- /**
- * Get a string representing a Constraint
- *
- * @param Constraint
- */
- public static String getConstraintnValue(Constraint specification) {
- String value = ""; //$NON-NLS-1$
- if(specification != null) {
- ValueSpecification spe = specification.getSpecification();
- if(spe != null) {
- value = getSpecificationValue(spe);
- }
- }
- return value;
- }
-
- /**
- * Sets the value of a specification, using a string value
- *
- * @param specification
- * the value specification to update
- * @param value
- * the value to set
- */
- public static void restoreSpecificationValue(ValueSpecification specification, String value) {
- if(value == null) {
- return;
- }
-
- switch(specification.eClass().getClassifierID()) {
- case UMLPackage.LITERAL_STRING:
- restoreLiteralString((LiteralString)specification, value);
- break;
- case UMLPackage.LITERAL_BOOLEAN:
- restoreLiteralBoolean((LiteralBoolean)specification, value);
- break;
- case UMLPackage.LITERAL_INTEGER:
- restoreLiteralInteger((LiteralInteger)specification, value);
- break;
- case UMLPackage.LITERAL_UNLIMITED_NATURAL:
- restoreLiteralUnlimitedNatural((LiteralUnlimitedNatural)specification, value);
- break;
- case UMLPackage.LITERAL_NULL:
- restoreLiteralNull((LiteralNull)specification, value);
- break;
- case UMLPackage.OPAQUE_EXPRESSION:
- OpaqueExpression exp = (OpaqueExpression)specification;
- if(!exp.getLanguages().isEmpty()) {
- restoreOpaqueExpression((org.eclipse.uml2.uml.OpaqueExpression)specification, exp.getLanguages().get(0), value);
- } else {
- restoreOpaqueExpression((org.eclipse.uml2.uml.OpaqueExpression)specification, value);
- }
- break;
- default:
- {
- break;
- }
- }
- }
-
- /**
- * Sets the value of a literal string, using a string value
- *
- * @param specification
- * the literal string to update
- * @param value
- * the new value
- */
- public static void restoreLiteralString(LiteralString specification, String value) {
- specification.setValue(value);
- }
-
- /**
- * Sets the value of a literal, using a string value
- *
- * @param specification
- * the literal integer to update
- * @param value
- * the new value
- */
- public static void restoreLiteralInteger(LiteralInteger specification, String value) {
- int intValue = 0;
- try {
- intValue = Integer.decode(value);
- } catch (NumberFormatException e) {
- // Do nothing, this was not a number. 0 will be the default value
- }
- specification.setValue(intValue);
- }
-
- /**
- * Sets the value of a literal boolean, using a string value
- *
- * @param specification
- * the literal boolean to update
- * @param value
- * the new value
- */
- public static void restoreLiteralBoolean(LiteralBoolean specification, String value) {
- if("true".equals(value) || "1".equals(value)) {
- specification.setValue(true);
- } else {
- specification.setValue(false);
- }
- }
-
- /**
- * Sets the value of a literal unlimited natural, using a string value
- *
- * @param specification
- * the literal unlimited natural to update
- * @param value
- * the new value
- */
- public static void restoreLiteralUnlimitedNatural(LiteralUnlimitedNatural specification, String value) {
- int intValue = 0;
- try {
- intValue = Integer.decode(value);
- } catch (NumberFormatException e) {
- // Do nothing, this was not a number. 0 will be the default value
- }
- // Handle the special unlimited value separately
- if(UNLIMITED_KEYWORD.equals(value)) {
- intValue = -1;
- }
- specification.setValue(intValue);
- }
-
- /**
- * Sets the value of a literal null, using a string value
- *
- * @param specification
- * the literal null to update
- * @param value
- * the new value
- */
- public static void restoreLiteralNull(LiteralNull specification, String value) {
- // nothing to set
- }
-
- /**
- * Sets the value of an opaque expression, using a string value
- *
- * @param specification
- * the opaque expression to update
- * @param value
- * the new value
- */
- public static void restoreOpaqueExpression(org.eclipse.uml2.uml.OpaqueExpression specification, String value) {
- // save in "UML" language, but should be desactivable
- OpaqueExpressionUtil.setBodyForLanguage(specification, "UML", value);
- }
-
- /**
- * Sets the value of an opaque expression, using a string value.
- *
- * @param specification
- * the opaque expression to update
- * @param language
- * the specified language
- * @param value
- * the new value
- */
- public static void restoreOpaqueExpression(org.eclipse.uml2.uml.OpaqueExpression specification, String language, String value) {
- OpaqueExpressionUtil.setBodyForLanguage(specification, language, value);
- }
-
- /**
- * Add to the collection the value specification and all its related value specifications, like min and max of an interval for example.
- *
- * @param spec
- * the value specification to add
- * @param collection
- * the collection
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static void addEnclosedValueSpecificationToCollection(ValueSpecification spec, Collection collection) {
- if(!collection.contains(spec)) {
- collection.add(spec);
- if(spec instanceof Interval) {
- addEnclosedValueSpecificationToCollection(((Interval)spec).getMin(), collection);
- addEnclosedValueSpecificationToCollection(((Interval)spec).getMax(), collection);
- } else if(spec instanceof Duration) {
- addEnclosedValueSpecificationToCollection(((Duration)spec).getExpr(), collection);
- } else if(spec instanceof TimeExpression) {
- addEnclosedValueSpecificationToCollection(((TimeExpression)spec).getExpr(), collection);
- } else if(spec instanceof Expression) {
- for(ValueSpecification vs : ((Expression)spec).getOperands()) {
- addEnclosedValueSpecificationToCollection(vs, collection);
- }
- if(spec instanceof StringExpression) {
- for(StringExpression se : ((StringExpression)spec).getSubExpressions()) {
- addEnclosedValueSpecificationToCollection(se, collection);
- }
- }
- }
- }
- }
-
-}
|