How to set multiple properties of a java annotation with xtend (using xbase)

459 views Asked by At

According to the JvmTypesBuilder documentation, I use need to use toAnnotation(EObject sourceElement, Class type, Object value)

I do not understand what value I should put there? Because I have an annotation w

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface OResultInfo {
    String rowNames() default "";
    String columnNames() default "";
    String keyNames() default "";
}

I have absolutely no idea how to to set these values. Maybe there is something about java annotations I do not know/understand?

1

There are 1 answers

0
Sven Efftinge On

You need to use

val jvmAnnotation = toAnnotation(EObject sourceElement, Class type)

And create and add annotation values per value and assign it to the jvmAnnotationReference:

val annotationValue = TypesFactory.eInstance.createJvmStringAnnotationValue();
annotationValue.getValues().add(value);
annotationValue.setOperation(annotationTypesOperation); //i.e. the JvmOperation representing rowNames(), columnNames() or keyNames()
jvmAnnotation.getValues().add(annotationValue);