javaannotationsacceleo

problem with using annotations in acceleo


Im very new to acceleo, for text generation(for java language) i'm using ecore file and .mtl module.

in my application there is a need of annotations, so I declared annotations in my ecore model. but the problem is i'm unable to check if condition with my annotation details( key,value) in MTL file.

my condition in .mtl file is

[if(r.getEAnnotation('sourcename').details.key.equalsIgnoreCase('keyname'))] [/if]

but here condition expression is not accepting in if block and even not accepting in let block also.

i'm able to print the values of my annotation source details(key,value) and even i'm able to print true or flase value of condition.

if any one know solution of this problem please replay me


Solution

  • This expression r.getEAnnotation('sourcename').details returns a collection so the condition of your "if" is a collection of boolean, not a boolean. You could change it to something like:

    [if(r.getEAnnotation('sourcename').details->first().key.equalsIgnoreCase('keyname'))] [/if]
    

    or

    [if(r.getEAnnotation('sourcename').details->collect(key.equalsIgnoreCase('keyname'))->size() > 0)] 
    
    [/if]