diff options
author | Quentin Le Menez | 2018-02-28 15:41:42 +0000 |
---|---|---|
committer | Camille Letavernier | 2018-04-12 11:37:27 +0000 |
commit | 8733a658a78d04d8faf97264d1d75ad280208111 (patch) | |
tree | 336270520754ed92ac671c64ae27a4ae5ec4dcdb | |
parent | 3b7a1f19f5357ee548c11a444fd44bc9c9d43a72 (diff) | |
download | org.eclipse.papyrus-8733a658a78d04d8faf97264d1d75ad280208111.tar.gz org.eclipse.papyrus-8733a658a78d04d8faf97264d1d75ad280208111.tar.xz org.eclipse.papyrus-8733a658a78d04d8faf97264d1d75ad280208111.zip |
Bug 530156: [Performances] Avoid recomputing the Stereotype when
applying it
https://bugs.eclipse.org/bugs/show_bug.cgi?id=530156
Change-Id: I9c32ae8ca5844c43b832ff854e99ba7ec0c54e57
Signed-off-by: Camille Letavernier <cletavernier@eclipsesource.com>
5 files changed, 62 insertions, 29 deletions
diff --git a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/META-INF/MANIFEST.MF b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/META-INF/MANIFEST.MF index 9379fd2a174..ff864fd755e 100644 --- a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/META-INF/MANIFEST.MF +++ b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Require-Bundle: org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)";visibility:=reexport, org.eclipse.uml2.types;bundle-version="[2.0.0,3.0.0)";visibility:=reexport, - org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)";visibility:=reexport, + org.eclipse.uml2.uml;bundle-version="[5.4.0,6.0.0)";visibility:=reexport, org.eclipse.uml2.common;bundle-version="[2.1.0,3.0.0)";visibility:=reexport, org.eclipse.papyrus.infra.emf;bundle-version="[3.0.0,4.0.0)";visibility:=reexport, org.eclipse.papyrus.uml.tools.utils;bundle-version="[3.0.0,4.0.0)", diff --git a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/helper/PapyrusStereotypeApplicationHelper.java b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/helper/PapyrusStereotypeApplicationHelper.java index 150950ca46a..3f00b1961a3 100644 --- a/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/helper/PapyrusStereotypeApplicationHelper.java +++ b/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel/src/org/eclipse/papyrus/uml/decoratormodel/helper/PapyrusStereotypeApplicationHelper.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, and others. - * + * Copyright (c) 2013, 2018 CEA LIST, Christian W. Damus, EclipseSource and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Remi Schnekenburger (CEA LIST) - Initial API and implementation * Christian W. Damus - bug 399859 * Christian W. Damus - bug 459613 + * Camille Letavernier (EclipseSource) - bug 530156 * *****************************************************************************/ package org.eclipse.papyrus.uml.decoratormodel.helper; @@ -22,6 +23,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.papyrus.uml.tools.utils.ProfileUtil; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.ProfileApplication; +import org.eclipse.uml2.uml.Stereotype; import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper; @@ -30,12 +32,15 @@ import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper; */ public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHelper { + /** + * @since 2.1 + */ @Override - protected EList<EObject> getContainmentList(Element element, EClass definition) { + protected EList<EObject> getContainmentList(Element element, EClass definition, Stereotype stereotype) { // Locate stereotype applications in the same resource as the profile application, if the // profile application is not actually in the same content tree as the base 'element' - ProfileApplication profileApplication = ProfileUtil.getProfileApplication(element, definition); + ProfileApplication profileApplication = ProfileUtil.getProfileApplication(element, definition, stereotype); if ((profileApplication != null) && (profileApplication.getApplyingPackage() != null) && !EcoreUtil.isAncestor(profileApplication.getApplyingPackage(), element)) { @@ -45,7 +50,7 @@ public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHel } } - return super.getContainmentList(element, definition); + return super.getContainmentList(element, definition, stereotype); } } diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF index b975180d242..2a2cadea74f 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/META-INF/MANIFEST.MF @@ -12,13 +12,13 @@ Require-Bundle: org.eclipse.uml2.uml;bundle-version="[5.3.0,6.0.0)";visibility:= org.eclipse.papyrus.uml.internationalization.utils;bundle-version="[1.0.0,2.0.0)" Bundle-Vendor: %pluginProvider Bundle-ActivationPolicy: lazy -Bundle-Version: 3.3.0.qualifier +Bundle-Version: 3.4.0.qualifier Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-Activator: org.eclipse.papyrus.uml.tools.utils.Activator Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.papyrus.uml.tools.utils;singleton:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: com.google.common.base;version="21.0.0", com.google.common.collect;version="21.0.0" Bundle-Description: %Bundle-Description diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/pom.xml b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/pom.xml index 3a5fd610979..274666d31be 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/pom.xml +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/pom.xml @@ -8,7 +8,7 @@ <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.papyrus.uml.tools.utils</artifactId> - <version>3.3.0-SNAPSHOT</version> + <version>3.4.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> <description>This plugin contributes a set of common utils tools for UML</description> </project>
\ No newline at end of file diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java index f1a9d1928e1..7b28d806907 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/ProfileUtil.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012, 2016 CEA LIST, Christian W. Damus, Esterel Technologies SAS and others. + * Copyright (c) 2012, 2018 CEA LIST, Christian W. Damus, Esterel Technologies SAS, EclipseSource and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,6 +13,7 @@ * Christian W. Damus - bug 451613 * Christian W. Damus - bug 474610 * Calin Glitia (Esterel Technologies SAS) - bug 497699 + * Camille Letavernier (EclipseSource) - bug 530156 * *****************************************************************************/ package org.eclipse.papyrus.uml.tools.utils; @@ -141,10 +142,10 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { } public static List<Stereotype> findAllSubStereotypes(Stereotype parentStereotype, Package umlPackage, boolean concreteOnly) { - Collection<Stereotype> result = new LinkedHashSet<Stereotype>(); + Collection<Stereotype> result = new LinkedHashSet<>(); for (Profile profile : umlPackage.getAllAppliedProfiles()) { - List<Stereotype> allStereotypes = new LinkedList<Stereotype>(); + List<Stereotype> allStereotypes = new LinkedList<>(); findAllStereotypes(profile, allStereotypes); for (Stereotype stereotype : allStereotypes) { if (concreteOnly && stereotype.isAbstract()) { @@ -158,7 +159,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { } - return new LinkedList<Stereotype>(result); + return new LinkedList<>(result); } public static boolean isSubStereotype(Stereotype parentStereotype, Stereotype childStereotype) { @@ -191,13 +192,13 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { public static List<EClass> getAllExtendedMetaclasses(Stereotype stereotype, boolean concreteClassesOnly) { List<Class> extendedMetaclasses = stereotype.getAllExtendedMetaclasses(); - Set<EClass> allMetaclasses = new LinkedHashSet<EClass>(); + Set<EClass> allMetaclasses = new LinkedHashSet<>(); for (Class extendedMetaclass : extendedMetaclasses) { EClass UMLEClass = findEClass(extendedMetaclass); allMetaclasses.addAll(EMFHelper.getSubclassesOf(UMLEClass, concreteClassesOnly)); } - return new LinkedList<EClass>(allMetaclasses); + return new LinkedList<>(allMetaclasses); } private static EClass findEClass(Class metaclass) { @@ -257,28 +258,54 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { /** * Finds the profile application, if any, in the context of an {@code element} that supplies the given * stereotype Ecore definition. - * + * * @param element * a model element * @param stereotypeDefinition * the Ecore definition of a stereotype - * + * @param stereotype + * The stereotype from which the stereotypeDefinition was derived + * * @return the providing profile application, or {@code null} if none can be determined + * @since 3.4 */ - public static ProfileApplication getProfileApplication(Element element, EClass stereotypeDefinition) { + public static ProfileApplication getProfileApplication(Element element, EClass stereotypeDefinition, Stereotype stereotype) { + if (stereotype == null) { + NamedElement umlDefinition = getNamedElement(stereotypeDefinition, element); + if (umlDefinition instanceof Stereotype) { + stereotype = (Stereotype)umlDefinition; + } else { + return null; + } + } ProfileApplication result = null; - NamedElement umlDefinition = getNamedElement(stereotypeDefinition, element); - if (umlDefinition != null) { - Profile profile = getContainingProfile(umlDefinition); - if (profile != null) { - result = getApplicationOf(profile, element); - } + Profile profile = getContainingProfile(stereotype); + if (profile != null) { + result = getApplicationOf(profile, element); } return result; } + /** + * Finds the profile application, if any, in the context of an {@code element} that supplies the given + * stereotype Ecore definition. + * + * @param element + * a model element + * @param stereotypeDefinition + * the Ecore definition of a stereotype + * + * @return the providing profile application, or {@code null} if none can be determined + * @deprecated since 3.4 Use {@link #getProfileApplication(Element, EClass, Stereotype)} instead, + * which is more efficient. + */ + @Deprecated + public static ProfileApplication getProfileApplication(Element element, EClass stereotypeDefinition) { + return getProfileApplication(element, stereotypeDefinition, null); + } + static Profile getContainingProfile(NamedElement umlDefinition) { Profile result = null; @@ -311,7 +338,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { * <li>have attributes typed by classifiers in the other profile, or</li> * <li>have operations with parameters typed by classifiers in the other profile</li> * </ul> - * + * * @param profiles * a list of profiles to sort in place */ @@ -324,6 +351,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { // Now sort by used profiles ahead of those that use them Collections.sort(profiles, new Comparator<Profile>() { + @Override public int compare(Profile o1, Profile o2) { return dependencies.get(o1).contains(o2) ? +1 : dependencies.get(o2).contains(o1) ? -1 : 0; } @@ -332,7 +360,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { /** * Compute a mapping of profiles to the profiles that they depend on. - * + * * @param profiles * profiles for which to compute dependencies * @return the dependency mapping (one-to-many) @@ -385,7 +413,7 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { /** * Expands a profile dependency map to include all transitive dependencies in the mapping for each profile. - * + * * @param dependencies * a dependency map to expand */ @@ -393,8 +421,8 @@ public class ProfileUtil extends org.eclipse.uml2.uml.util.UMLUtil { for (boolean changed = true; changed;) { changed = false; - for (Profile next : new ArrayList<Profile>(dependencies.keySet())) { - for (Profile dep : new ArrayList<Profile>(dependencies.get(next))) { + for (Profile next : new ArrayList<>(dependencies.keySet())) { + for (Profile dep : new ArrayList<>(dependencies.get(next))) { Set<Profile> transitive = dependencies.get(dep); // Add the transitive dependencies to my own |