How to create an static function with an annotation in Model? [message #541144] |
Fri, 18 June 2010 09:12  |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03310 seconds