Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:14 Go to next message
Tobias Wink is currently offline Tobias WinkFriend
Messages: 20
Registered: September 2014
Junior Member
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 12:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

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

- values
- explicitValues


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: infer annotation with key-value Pairs [message #1434687 is a reply to message #1434681] Tue, 30 September 2014 12:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
https://www.eclipse.org/forums/index.php/m/1265742/?srch=explicitValues#msg_1265742

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: infer annotation with key-value Pairs [message #1434728 is a reply to message #1434541] Tue, 30 September 2014 13:47 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
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 05:17 Go to previous message
Tobias Wink is currently offline Tobias WinkFriend
Messages: 20
Registered: September 2014
Junior Member
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 Apr 19 02:15:10 GMT 2024

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

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

Back to the top