Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » How to create an static function with an annotation in Model?
How to create an static function with an annotation in Model? [message #541144] Fri, 18 June 2010 13:12 Go to next message
Ruben  is currently offline Ruben
Messages: 40
Registered: July 2009
Member
I would like to use the XTEXT Postprocessor to create a static function on an Object, which I can use later in xtend.

At the moment I'm using the following code to create the method.

Quote:


private create EOperation createToStringOperation():
setName("getName") ->
setEType(mapTypeName("String")) ->
setEParameters( { createFieldParameter() } ) ->
setEAnnotations( { createToStringAnnotation() })
;

private create EParameter createFieldParameter():
setName("field") ->
setEType(mapTypeName("JavaObject"))
;

private create EAnnotation createToStringAnnotation():
setSource("http://www.eclipse.org/emf/2002/GenModel") ->
setDetails( { createToStringAnnDetail() } )
;

private create EStringToStringMapEntry createToStringAnnDetail():
setKey("body") ->
setValue('
String name = null;

if (this instanceof com.bttg.meta_model.btc.btc.LocalField) {
name = ((com.bttg.meta_model.btc.btc.LocalField) this).getName();
} else if (this instanceof com.bttg.meta_model.btc.btc.OverrideField) {
name = ((com.bttg.meta_model.btc.btc.OverrideField) this).getField().getName();
} else if (this instanceof com.bttg.meta_model.btc.btc.VirtualField) {
name = ((com.bttg.meta_model.btc.btc.VirtualField) this).getName();
} else
throw new IllegalArgumentException("Not a known field type");

return name;
')
;



This works almost fine. The only problem is that the method created is not static, and therefore not usable as XTEND extension.

Any Idea how can I make the method static?

Thanks
Re: How to create an static function with an annotation in Model? [message #541416 is a reply to message #541144] Mon, 21 June 2010 04:59 Go to previous message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1769
Registered: July 2009
Senior Member
Ruben schrieb:

>
> This works almost fine. The only problem is that the method created is
> not static, and therefore not usable as XTEND extension.

It's a member of one of your EClasses. If you have an instance of that
class you can call the EOperation. I think that's even better than
having it static.

Sven

--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Previous Topic:[Xpand] typesystem.uml2 confuses xpand editor
Next Topic:[Acceleo] Debugging an acceleo module
Goto Forum:
  


Current Time: Tue Oct 21 07:26:36 GMT 2014

Powered by FUDForum. Page generated in 0.01890 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software