Skip to main content



      Home
Home » Modeling » TMF (Xtext) » infer annotation with key-value Pairs
icon5.gif  infer annotation with key-value Pairs [message #1434541] Tue, 30 September 2014 04:14 Go to next message
Eclipse UserFriend
Hi,

I'm new here and still at the beginning of learning Xtext and Xtend.

As mentioned in the topic I'm currently trying to infer an annotation with a key-value Pair like the JPA Annotation @Table(name="TABLE_NAME")

I've found and adapted the solution from https://www.eclipse.org/forums/index.php/t/486005/:

	def addStringValues(JvmAnnotationReference annoRef, String name, String... newValues) {
		val op = annoRef.findOperationByName(name)
		annoRef.values += createJvmStringAnnotationValue => [
			operation = op
			values += newValues
		]
		annoRef
	}


My problem is, that by annoRef.values JvmAnnotationReferenceImplCustom.getValues() is called and returns a ECollections.unmodifiableEList so I get an Exception when trying to add a new value.

I've found out, that it's from type JvmAnnotationReferenceImplCustom because createJvmAnnotationReference in org.eclipse.xtext.common.types.impl.TypesFactoryImpl is:

public JvmAnnotationReference createJvmAnnotationReference()
	{
		JvmAnnotationReferenceImplCustom jvmAnnotationReference = new JvmAnnotationReferenceImplCustom();
		return jvmAnnotationReference;
	}


What are my possibilities to get around with it so I can infer those annotations?
Re: infer annotation with key-value Pairs [message #1434681 is a reply to message #1434541] Tue, 30 September 2014 08:41 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i guess the post you have found is outdated. if you have a look at JvmAnnotationReference you can find

- values
- explicitValues
Re: infer annotation with key-value Pairs [message #1434687 is a reply to message #1434681] Tue, 30 September 2014 08:47 Go to previous messageGo to next message
Eclipse UserFriend
https://www.eclipse.org/forums/index.php/m/1265742/?srch=explicitValues#msg_1265742
Re: infer annotation with key-value Pairs [message #1434728 is a reply to message #1434541] Tue, 30 September 2014 09:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tobias,

please set the explicitValues of your annotation reference rather than
values. #values provides a view that contains the explicit values and
the default values if no explicit values have been given.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 30.09.14 14:30, schrieb Tobias Wink:
> Hi,
>
> I'm new here and still at the beginning of learning Xtext and Xtend.
>
> As mentioned in the topic I'm currently trying to infer an annotation
> with a key-value Pair like the JPA Annotation @Table(name="TABLE_NAME")
>
> I've found and adapted the solution from
> https://www.eclipse.org/forums/index.php/t/486005/:
>
> def addStringValues(JvmAnnotationReference annoRef, String name,
> String... newValues) {
> val op = annoRef.findOperationByName(name)
> annoRef.values += createJvmStringAnnotationValue => [
> operation = op
> values += newValues
> ]
> annoRef
> }
>
> My problem is, that by annoRef.values
> JvmAnnotationReferenceImplCustom.getValues() is called and returns a
> ECollections.unmodifiableEList so I get an Exception when trying to add
> a new value.
>
> I've found out, that it's from type JvmAnnotationReferenceImplCustom
> because createJvmAnnotationReference in
> org.eclipse.xtext.common.types.impl.TypesFactoryImpl is:
>
> public JvmAnnotationReference createJvmAnnotationReference()
> {
> JvmAnnotationReferenceImplCustom jvmAnnotationReference = new
> JvmAnnotationReferenceImplCustom();
> return jvmAnnotationReference;
> }
>
> What are my possibilities to get around with it so I can infer those
> annotations?
Re: infer annotation with key-value Pairs [message #1435165 is a reply to message #1434728] Wed, 01 October 2014 01:17 Go to previous message
Eclipse UserFriend
Thanks. It works now.

I changed the
annoRef.values += createJvmStringAnnotationValue => [
			operation = op
			values += newValues
		]


to

annoRef.explicitValues += createJvmStringAnnotationValue => [
			operation = op
			values += newValues
		]
Previous Topic:Make a rcp e4 application with xtext editor
Next Topic:toField and newTypeRef question
Goto Forum:
  


Current Time: Fri Jul 04 13:38:18 EDT 2025

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

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

Back to the top