I'm trying to add annotation with values to method in my inferrer. It is working fine under 2.4 but under 2.5 I'm getting this error :
1024 [Worker-6] ERROR org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder - Error initializing JvmElement
java.lang.UnsupportedOperationException
at org.eclipse.emf.common.util.ECollections$UnmodifiableEList.add(ECollections.java:354)
Problems come from this piece of code:
It look like annotation values are implemented using UnmodifiableEList
How should I generate annotations values under Xtext 2.5?
In my example is based on example in documentation http://www.eclipse.org/Xtext/documentation.html#JvmDomainmodel. In toMethod function I just added code to generate annotation and annotation values.
val anno = feature.toAnnotation(typeof(javax.xml.bind.annotation.XmlElement))
val annoValue = TypesFactory::eINSTANCE.createJvmTypeAnnotationValue
annoValue.operation = anno.annotation.getDeclaredOperations().filter(o|o.simpleName == "type").head
val jvmType = typeReferences.getTypeForName(java.lang.String, feature).type as JvmGenericTypeImplCustom
val literal = typeReferences.createTypeRef(jvmType)
annoValue.values += literal
anno.values+=annoValue
annotations+=anno