diff options
| author | Christian W. Damus | 2015-02-17 22:26:45 +0000 |
|---|---|---|
| committer | Christian W. Damus | 2015-02-17 22:26:45 +0000 |
| commit | ff9c05286a92bf5d870dfca56fa5bbe6876a2ef0 (patch) | |
| tree | 4f8dec2846cdb4a7a4830ad6ffc2d14556237d5f | |
| parent | 72984f2e7a65c2b7e0e231008b684f453b688be8 (diff) | |
| download | org.eclipse.papyrus-ff9c05286a92bf5d870dfca56fa5bbe6876a2ef0.tar.gz org.eclipse.papyrus-ff9c05286a92bf5d870dfca56fa5bbe6876a2ef0.tar.xz org.eclipse.papyrus-ff9c05286a92bf5d870dfca56fa5bbe6876a2ef0.zip | |
Bug 459613: [Profile Applications] [Submodels] Separate Profile Application stereotypes lost for fragmented models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=459613
Ensure that stereotype applications are always created in the same resource as
their base element (not the resource containing the profile application) except
in the case that the profile application is externalized.
2 files changed, 43 insertions, 4 deletions
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 73c14a72675..150950ca46a 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,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013, 2014 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2013, 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,6 +9,7 @@ * Contributors: * Remi Schnekenburger (CEA LIST) - Initial API and implementation * Christian W. Damus - bug 399859 + * Christian W. Damus - bug 459613 * *****************************************************************************/ package org.eclipse.papyrus.uml.decoratormodel.helper; @@ -17,6 +18,7 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +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; @@ -30,10 +32,13 @@ public class PapyrusStereotypeApplicationHelper extends StereotypeApplicationHel @Override protected EList<EObject> getContainmentList(Element element, EClass definition) { - // Locate stereotype applications in the same resource as the profile application + // 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); - if (profileApplication != null) { + if ((profileApplication != null) && (profileApplication.getApplyingPackage() != null) + && !EcoreUtil.isAncestor(profileApplication.getApplyingPackage(), element)) { + Resource containingResource = profileApplication.eResource(); if (containingResource != null) { return containingResource.getContents(); diff --git a/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/helper/tests/PapyrusStereotypeApplicationHelperTest.java b/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/helper/tests/PapyrusStereotypeApplicationHelperTest.java index fcd9771a60f..3083e0b9857 100644 --- a/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/helper/tests/PapyrusStereotypeApplicationHelperTest.java +++ b/tests/junit/plugins/uml/decoratormodel/org.eclipse.papyrus.uml.decoratormodel.tests/src/org/eclipse/papyrus/uml/decoratormodel/helper/tests/PapyrusStereotypeApplicationHelperTest.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 Christian W. Damus and others. + * Copyright (c) 2014, 2015 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 @@ -128,6 +128,40 @@ public class PapyrusStereotypeApplicationHelperTest extends AbstractPapyrusTest } } + /** + * Scenario: apply a stereotype to an element in a sub-model unit that is not a package (e.g., a class unit). + * The stereotype application must be added to the sub-model unit containing the base element, not the unit + * containing the profile application. + * + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=459613 + */ + @Test + public void stereotypeApplication_inNonPackageSubmodelUnit_bug459613() { + ResourceSet rset = new ResourceSetImpl(); + + try { + Resource uml = rset.createResource(URI.createURI("bogus://test"), UMLPackage.eCONTENT_TYPE); + Package package_ = UMLFactory.eINSTANCE.createPackage(); + uml.getContents().add(package_); + + Profile profile = createProfile(rset); + package_.applyProfile(profile); + + EClass stereotype = (EClass) package_.getProfileApplications().get(0).getAppliedDefinition(profile.getOwnedStereotype("Stereo")); + + Package nested = package_.createNestedPackage("nested"); + Class foo = nested.createOwnedClass("Foo", false); + Resource subUnit = rset.createResource(URI.createURI("bogus://test/class1"), UMLPackage.eCONTENT_TYPE); + subUnit.getContents().add(foo); + EObject stereotypeApplication = fixture.applyStereotype(foo, stereotype); + + assertThat(UMLUtil.getBaseElement(stereotypeApplication), is((Element) foo)); + assertThat(subUnit.getContents(), hasItem(stereotypeApplication)); + } finally { + EMFHelper.unload(rset); + } + } + // // Test framework // |
