diff options
author | Christian W. Damus | 2015-01-28 15:11:34 +0000 |
---|---|---|
committer | Christian W. Damus | 2015-01-28 15:11:34 +0000 |
commit | 8f5e313ed4d0974dce76264189b6b665920fe4ad (patch) | |
tree | 13f1a04feb2e820b05d2aaaf7dc72ec850cd7f8b | |
parent | 05607a6b8499d1838645c2e74eb82f948cd46cd3 (diff) | |
download | org.eclipse.papyrus-8f5e313ed4d0974dce76264189b6b665920fe4ad.tar.gz org.eclipse.papyrus-8f5e313ed4d0974dce76264189b6b665920fe4ad.tar.xz org.eclipse.papyrus-8f5e313ed4d0974dce76264189b6b665920fe4ad.zip |
458643: [Profile] Application version annotations accumulate
https://bugs.eclipse.org/bugs/show_bug.cgi?id=458643
Ensure that any and all previous PapyrusVersion annotations are replaced by the new version annotation when migrating a profile application.
2 files changed, 30 insertions, 5 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomUMLUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomUMLUtil.java index f60baf1a1a8..a5d4c66b6b7 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomUMLUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/CustomUMLUtil.java @@ -1,5 +1,5 @@ /*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2015 CEA LIST, Christian W. Damus, and others.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,10 +9,13 @@ *
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 458643
*
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.utils;
+import java.util.Collection;
+
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -23,6 +26,8 @@ import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Extension;
import org.eclipse.uml2.uml.util.UMLUtil;
+import com.google.common.collect.ImmutableList;
+
/**
* Provides methods for stereotypes application outside of a resource
*
@@ -31,6 +36,15 @@ import org.eclipse.uml2.uml.util.UMLUtil; */
public class CustomUMLUtil extends UMLUtil {
+ public static void destroy(EObject eObject) {
+ UML2Util.destroy(eObject);
+ }
+
+ public static void destroyAll(Collection<? extends EObject> eObjects) {
+ // Iterate a copy of the list to avoid concurrent modification
+ UML2Util.destroyAll(ImmutableList.copyOf(eObjects));
+ }
+
/**
* The StereotypeApplicationHelper can be overridden to change the default
* location of applied stereotypes.
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java index 3eda2012dcd..cc3f93408e0 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools/src/org/eclipse/papyrus/uml/tools/commands/ApplyProfileCommand.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2011 CEA LIST. + * Copyright (c) 2011, 2015 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -9,9 +9,12 @@ * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + * Christian W. Damus - bug 458643 *****************************************************************************/ package org.eclipse.papyrus.uml.tools.commands; +import static org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE; + import java.util.Collection; import java.util.Collections; @@ -19,7 +22,7 @@ import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.papyrus.uml.tools.profile.definition.IPapyrusVersionConstants; +import org.eclipse.papyrus.uml.tools.utils.CustomUMLUtil; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.Profile; import org.eclipse.uml2.uml.ProfileApplication; @@ -123,9 +126,17 @@ public class ApplyProfileCommand extends RecordingCommand { ProfileApplication profileApplication = umlPackage.getProfileApplication(profile); // Get version annotation in case it is a Papyrus profile - EAnnotation versionAnnotation = profile.getDefinition().getEAnnotation(IPapyrusVersionConstants.PAPYRUS_EANNOTATION_SOURCE); + EAnnotation versionAnnotation = profile.getDefinition().getEAnnotation(PAPYRUS_EANNOTATION_SOURCE); if (versionAnnotation != null) { - profileApplication.getEAnnotations().add(0, EcoreUtil.copy(versionAnnotation)); + int index = 0; + + for (EAnnotation existing = profileApplication.getEAnnotation(PAPYRUS_EANNOTATION_SOURCE); existing != null; existing = profileApplication.getEAnnotation(PAPYRUS_EANNOTATION_SOURCE)) { + // Replace this; don't just add to the existing ones + index = profileApplication.getEAnnotations().indexOf(existing); + CustomUMLUtil.destroy(existing); + } + + profileApplication.getEAnnotations().add(index, EcoreUtil.copy(versionAnnotation)); } } } |