Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Issues retrieving enumeration literal from UML stereotype property
[Xpand] Issues retrieving enumeration literal from UML stereotype property [message #647539] Thu, 06 January 2011 17:44 Go to next message
Eclipse User is currently offline Eclipse User
Messages: 14
Registered: January 2011
Junior Member
I am using Xpand templates to generate code from a UML model that uses custom profile stereotypes. When I tried to use the following line in my Xpand template to get the value of a stereotype property (implemented as an enum)...

«this.getValue(this.getAppliedStereotype(MyProfile::MyMeter .toString()), "level")»

I get the following output in the target file:

org.eclipse.uml2.uml.internal.impl.EnumerationLiteralImpl@4dd84dd8 (name: LOW, visibility: <unset>)

What additional steps do I need to make to just get the enumeration literal value "LOW" to be the output? I've been trying different variations without much success.

Thanks!
Re: [Xpand] Issues retrieving enumeration literal from UML stereotype property [message #647541 is a reply to message #647539] Thu, 06 January 2011 17:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6198
Registered: July 2009
Senior Member
Hi, just asking it for its name (.name) does not work? you may have to cast it first to its actual type. (uml::EnumerationLiteral)

«((uml::EnumerationLiteral)this.getValue(this.getAppliedStereotype(test::Bean .toString()), "lala")).name»


Having a look at the the Java Classes might help to solve such problems
org.eclipse.uml2.uml.EnumerationLiteral has a getName() inherited from org.eclipse.uml2.uml.NamedElement

~Christian

[Updated on: Thu, 06 January 2011 18:08]

Report message to a moderator

Re: [Xpand] Issues retrieving enumeration literal from UML stereotype property [message #647597 is a reply to message #647541] Fri, 07 January 2011 04:24 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

Accessing the name property of an enumeration literal won't work directly, since the internal type of an enumeration literal is its enumeration and thus you get the name of the enumeration, not the literal. You have to write a Java extension to access a literal's name.

~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: [Xpand] Issues retrieving enumeration literal from UML stereotype property [message #647602 is a reply to message #647597] Fri, 07 January 2011 04:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6198
Registered: July 2009
Senior Member
@Karsten i tried my code and it works with uml enumerations.

«DEFINE main FOR test::Bean»
«FILE getFQPN().replaceAll("\\.","/")+"/"+name+".java"»
//«((uml::EnumerationLiteral)this.getValue(this.getAppliedStereotype(test::Bean .toString()), "lala")).name»«REM»will work«ENDREM»
//«this.lala.name»«REM»will work too«ENDREM»
package «getFQPN()»;
public class «name» {

}
«ENDFILE»
«ENDDEFINE»


~Christian

[Updated on: Fri, 07 January 2011 05:20]

Report message to a moderator

Re: [Xpand] Issues retrieving enumeration literal from UML stereotype property [message #647656 is a reply to message #647602] Fri, 07 January 2011 10:39 Go to previous message
Eclipse User is currently offline Eclipse User
Messages: 14
Registered: January 2011
Junior Member
Thanks very much Christian! I tried out both suggestions and they worked as advertised. Smile
Previous Topic:[MWE2,XPAND] Loading workflow in OSGi w/o workspace
Next Topic:[Xpand] How to get xmi id from an xpand template
Goto Forum:
  


Current Time: Wed Aug 20 12:47:27 EDT 2014

Powered by FUDForum. Page generated in 0.01666 seconds