Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 308622 - UML Typesystem does not handle Stereotype associations correctly
Summary: UML Typesystem does not handle Stereotype associations correctly
Status: CLOSED FIXED
Alias: None
Product: M2T
Classification: Modeling
Component: Xpand (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: SR1   Edit
Assignee: Karsten Thoms CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-09 06:29 EDT by Jochen Schmich CLA
Modified: 2013-02-21 08:12 EST (History)
6 users (show)

See Also:
karsten.thoms: indigo+


Attachments
example project (1.22 MB, application/octet-stream)
2010-08-17 09:36 EDT, Darius Jockel CLA
no flags Details
The Error messages (2.52 KB, text/plain)
2011-04-05 12:05 EDT, Jochen Schmich CLA
no flags Details
The example project (7.41 KB, application/octet-stream)
2011-04-05 12:06 EDT, Jochen Schmich CLA
no flags Details
The patch (1.14 KB, patch)
2011-04-05 12:18 EDT, Jochen Schmich CLA
sven.efftinge: iplog+
Details | Diff
Updated example project (7.56 KB, application/zip)
2011-07-25 17:23 EDT, Karsten Thoms CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jochen Schmich CLA 2010-04-09 06:29:45 EDT
Build Identifier: 

The basic UML Element that a Stereotype can be applied to, is specified by one or more Properties that reference the basic Element and are called base_<NameOfTheExtendedType> by default.

You can also define Stereotype associations that allow users to reference another Stereotyped Element.

Consider the following design:

<<Stereotype A>> <uml::Class> associates <<Stereotype B>> <uml::Operation>.

If the UML Typesystem tries to handle calls to the associated stereotyped Elements features, it will fail, since the implementation does only take care of so called "dynamic values" (Implementation detail) that extend the UML Element "Class" (via looking for the "base_Class"-feature).

A quick fix to the code would be the following solution:

Class "org.eclipse.xtend.typesystem.uml2.profile.StereotypeType" should change the getDynamicValue(Object) as follows:

private Object getDynamicValue(final Object value) {
									if (value instanceof EObject) {
										final EObject dynObject = (EObject) value;
										final EClass dynClass = dynObject.eClass();
										
										EStructuralFeature baseClassFeature = null;
										
										EList<EStructuralFeature> structuralFeatures = dynClass.getEStructuralFeatures();
										for (EStructuralFeature structuralFeature : structuralFeatures) {
											if(structuralFeature != null && structuralFeature.getName().startsWith("base_")) {
												baseClassFeature = structuralFeature;
												break;
											}
										}
																				
										if(baseClassFeature != null){
											return dynObject.eGet(baseClassFeature,true);
										}
									}
									return null;
								}

Reproducible: Always

Steps to Reproduce:
1. Create a Stereotype that extends any other Element than Class
2. Create a second Stereotype that references the first Stereotype by a Stereotype association
3. Write an Extension for the second this Stereotype that accesses one of the extended Elements features via the Stereotype assocation
4. Execute the Extension on the Stereotyped Element
Comment 1 Erhard Weinell CLA 2010-04-09 11:39:43 EDT
I think this bug is caused elsewhere, not in the internal getDynamicValue method. Given a proper type comparison is in place, your process should  receive an EList from ele.getValue holding the referenced elements. Given that none of their EClass have a "base_Class" property, the method safely returns "value" without further magic.
Comment 2 Jochen Schmich CLA 2010-04-24 03:00:18 EDT
Sorry for the late response - I can have another look at it - this was more of a unproper workaround - given that a Stereotype can have more than one Elements it extends.
When I applied the fix to the original implementation - I only got an DynamicEObjectImpl while debugging the method. No org.eclipse.uml2.uml.Element... that was another problem about it which then lead to the workaround.
Comment 3 Erhard Weinell CLA 2010-04-27 04:46:17 EDT
Maybe you should check your problem against CVS Head / XPand 1.0.0 - there are some changes in the UmlTypeSystem in the treatment of Stereotypes. Looking forward for experience reports :)
Comment 4 Jochen Schmich CLA 2010-05-26 11:45:20 EDT
Sadly I couldn't find any resolution to my problem in the repository. Most of the changes have been made back in 2009.

@Moritz: Sorry for adding you to the CC-List without asking - saw your name in the JavaDoc-Comments of the classes mentioned above. Do you know those problems we have? Added you to the CC List of Bug 307281, too.
Comment 5 Darius Jockel CLA 2010-08-17 09:34:07 EDT
Hello Jochen Schmich,

I tried to model stereotype associations.
I modeled two Stereotypes A and B.
B has a referenceto A called a.

A:Property <a- B:NamedElement
(see the example project attached)

Inside a Define I tried to navigate this association like this:
«DEFINE test FOR B»
Name: «name» 
Ref-Name: «a.name» 
Ref-Typ: «a.type.name»
--
Ref-Name: «base_NamedElement.name» 
«ENDDEFINE»

This is the result:
Name: b 
Ref-Name: a 
Ref-Typ: String
--
Ref-Name: b 

So, I think the associations work.
The only bug I see, is that the editor do not mark base_NamedElement as an error.

Please give me feedback if I miss the point.
Darius
Comment 6 Darius Jockel CLA 2010-08-17 09:36:21 EDT
Created attachment 176785 [details]
example project
Comment 7 Jochen Schmich CLA 2011-04-05 12:05:29 EDT
Created attachment 192572 [details]
The Error messages

Contents of the MWE log
Comment 8 Jochen Schmich CLA 2011-04-05 12:06:25 EDT
Created attachment 192573 [details]
The example project

the example
Comment 9 Jochen Schmich CLA 2011-04-05 12:07:06 EDT
Hi Darius,

I'm verry sorry for not responding to your last comment THAT long.

I had a look at your example project... I'm sorry but it is not sufficient to reproduce the bug.
I also built an own example project (first time I used the Standard Eclipse UML Editor ever - but thanks to the Xpand tutorials I finally made it...).

The project also contains a small profile with two and a model with some Elements that apply them.
You'll also find a MWE Workflow and a Xtend script included.

Running the workflow should lead to the messages in the attached logfile.

I'll attach the code patch, too ASAP.
Comment 10 Jochen Schmich CLA 2011-04-05 12:18:31 EDT
Created attachment 192575 [details]
The patch

Traverses every structural feature and picks the first one, that starts with "base_" - apply to workspace root
Comment 11 Peter Vermeulen CLA 2011-06-06 12:14:55 EDT
Experienced the same problem in my project after an upgrade to MagicDraw 17.
The difference between the EMF export in MagicDraw 17 and previous versions is that in the old version the stereotype properties with a type also a stereotype were exported with the base class as type. MagicDraw 17 exports the correct type. 

The patch of Jochen works with one minor change. I replaced dynClass.getEStructuralFeatures() with dynClass.getEAllStructuralFeatures(). In my model a number of stereotypes extend other stereotypes.
Comment 12 Saulius Pavalkis CLA 2011-06-08 02:28:42 EDT
Hello,

Our customer uses tool to generate other formats from UML model (XML-schema’s and Excel spreadsheets at the moment, Edifact Message Implementation Guides at a later stage). This tool is based on Xtext, Xtend, and Xpand. 

We update EMF export of UML tool. However due to the change/improvement in the export, customer ran into a bug of Xtend which does not always map UML stereotypes correctly to its own type system.

Maybe priority of this important issue could be raised?

Thank you in advance,
Saulius Pavalkis
Customer Support Manager
No Magic
Comment 13 Karsten Thoms CLA 2011-06-08 03:37:33 EDT
Eclipse Indigo is already at RC4, this is code freeze now. So this won't make it into Indigo. I'll deal it for Indigo SR1.
Comment 14 Saulius Pavalkis CLA 2011-06-08 03:45:47 EDT
Thank you very much, we appreciate this!
Comment 15 Jochen Schmich CLA 2011-06-08 05:27:11 EDT
Yeah, thank you Karsten!
@Saulius: Another issue with Stereotypes may be found here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=307281
Comment 16 Karsten Thoms CLA 2011-07-25 17:23:06 EDT
Sorry for taking ages. I could reproduce the problem with the given sample and applied the patch with the modification proposed by Peter Vermeulen.
Comment 17 Karsten Thoms CLA 2011-07-25 17:23:51 EDT
Created attachment 200313 [details]
Updated example project
Comment 18 Karsten Thoms CLA 2013-02-21 08:12:13 EST
Bug resolved before Xpand 1.2 release date => Closing