Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using annotations in DSL
Using annotations in DSL [message #697595] Sun, 17 July 2011 10:52 Go to next message
Gunnar Morling is currently offline Gunnar MorlingFriend
Messages: 2
Registered: July 2011
Junior Member
Hi,

first off, I'd like to say that I'm really impressed by Xtext/Xtend. I think we're going to see a lot of exciting stuff based on these technologies in the future.

What I'd like to know is whether it's possible to use existing Java annotations within a DSL. Looking at the canonic entity DSL for example, it would be nice if it was possible to specify JPA annotations at the fields of an entity in the DSL. These anotations then would just be transferred unaltered to the output model during code generation.

Is something like that possible? If so, are there any examples which I could use as a starting point?

Thanks, Gunnar
Re: Using annotations in DSL [message #697601 is a reply to message #697595] Sun, 17 July 2011 11:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

Xtend does this Wink so have a look at the Xtend source code.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using annotations in DSL [message #697603 is a reply to message #697595] Sun, 17 July 2011 11:08 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gunnar,

your language could extend XbaseWithAnnotations. It provides exactly
what you are looking for. Though I've to admit that you'll have to dig
into Xtend's implementation to learn how to create annotated elements.
However, it should serve as a goog starting point.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

On 17.07.11 12:52, Gunnar Morling wrote:
> Hi,
>
> first off, I'd like to say that I'm really impressed by Xtext/Xtend. I
> think we're going to see a lot of exciting stuff based on these
> technologies in the future.
>
> What I'd like to know is whether it's possible to use existing Java
> annotations within a DSL. Looking at the canonic entity DSL for example,
> it would be nice if it was possible to specify JPA annotations at the
> fields of an entity in the DSL. These anotations then would just be
> transferred unaltered to the output model during code generation.
> Is something like that possible? If so, are there any examples which I
> could use as a starting point?
>
> Thanks, Gunnar
Re: Using annotations in DSL [message #697707 is a reply to message #697601] Sun, 17 July 2011 19:32 Go to previous messageGo to next message
Gunnar Morling is currently offline Gunnar MorlingFriend
Messages: 2
Registered: July 2011
Junior Member
Hi,

thanks for the pointers, I'll have a look at Xtend then. Though I guess working through Xtend might take some time Wink

--Gunnar
Re: Using annotations in DSL [message #1694828 is a reply to message #697707] Fri, 08 May 2015 09:52 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 6
Registered: April 2015
Junior Member
Hi,

I also want to support using annotations in my DSL.
In grammar, I define entity as below:
Entity:
	(entityAnnotation=XAnnotation)?
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
		features+=Feature*
	'}';


However, when I create a file of my DSL type and use annotation, I get an error: "missing EOF at '@'"

Am I missing something?

P.S.: I am trying to use JPA annotation in my file.

[Updated on: Fri, 08 May 2015 10:00]

Report message to a moderator

Re: Using annotations in DSL [message #1694831 is a reply to message #1694828] Fri, 08 May 2015 10:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

are you sure you did not miss to regenerate the language?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using annotations in DSL [message #1694834 is a reply to message #1694831] Fri, 08 May 2015 11:23 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 6
Registered: April 2015
Junior Member
Hi Christian,

Yes, I executed .mwe2 after changing entity definition.
Re: Using annotations in DSL [message #1694837 is a reply to message #1694834] Fri, 08 May 2015 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
very strange. do you use the domain model example as base? and which xtext version do you use?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using annotations in DSL [message #1694840 is a reply to message #1694837] Fri, 08 May 2015 12:11 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 6
Registered: April 2015
Junior Member
Yes, I am referring to domainmodel example (Xtext version 2.7.3).

Now I am not getting that error.
It seems projects were not built properly or error markers did not go away even after regenerating the language. (I had to make the file dirty to get rid of markers.)

Re: Using annotations in DSL [message #1695166 is a reply to message #1694840] Tue, 12 May 2015 12:41 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 6
Registered: April 2015
Junior Member
Hi,

I want to transfer annotations used in my DSL file to the generated java file.
I checked xtend source code; however, for me, it seemed a bit complex as I am new to xtext/xtend.

I tried following in my JvmModelInferrer:

annotations += entity.toAnnotation(entity.entityAnnotation.annotationType.class)


I am getting following error:
java.lang.IllegalArgumentException: The type org.eclipse.xtext.common.types.impl.JvmAnnotationTypeImpl is not on the classpath.


My DSL file:
import javax.persistence.Entity

@Entity
entity TestEntity {
	prop1 : String
}


Could you please provide me some pointers to get annotations in generated file?
Re: Using annotations in DSL [message #1695195 is a reply to message #1695166] Tue, 12 May 2015 14:53 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 12/05/2015 14:41, Manisha Ghule wrote:
> Hi,
>
> I want to transfer annotations used in my DSL file to the generated java
> file.
> I checked xtend source code; however, for me, it seemed a bit complex as
> I am new to xtext/xtend.
>
> I tried following in my JvmModelInferrer:
>
> annotations +=
> entity.toAnnotation(entity.entityAnnotation.annotationType.class)
>
> I am getting following error:
> java.lang.IllegalArgumentException: The type
> org.eclipse.xtext.common.types.impl.JvmAnnotationTypeImpl is not on the
> classpath.
>
> My DSL file:
> import javax.persistence.Entity
>
> @Entity
> entity TestEntity {
> prop1 : String
> }
>
> Could you please provide me some pointers to get annotations in
> generated file?
>

Hi

are you getting this error when you try the editor of your DSL in a
project? If that is the case, you need to make sure that the projects
for your DSL have a dependency on the bundles containing your
annotations and in particular other Xtext bundles, like
org.eclipse.xtext.common.types.

Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Using annotations in DSL [message #1695400 is a reply to message #1695195] Thu, 14 May 2015 06:32 Go to previous messageGo to next message
Manisha Ghule is currently offline Manisha GhuleFriend
Messages: 6
Registered: April 2015
Junior Member
Hi Lorenzo,

Thank you for your reply.

Yes, I was getting this error while trying the editor of my DSL in a project and I also had specified resp. bundle dependencies.

I solved the issue.
The problem was with adding my existing annotation to the field "annotations". Now I am adding it as below:
annotations += entity.entityAnnotation.jvmAnnotationReference


Is this the correct way?
Re: Using annotations in DSL [message #1695402 is a reply to message #1695400] Thu, 14 May 2015 07:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i think the correct way would be

accept(entity.toClass( entity.fullyQualifiedName )) [
    addAnnotation(entity.entityAnnotation)
    ....


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to dynamic filter the content assistant list in XxxProposalProvider?
Next Topic:How to handle left-recursive Call graphs in xtext?
Goto Forum:
  


Current Time: Thu Apr 18 05:02:03 GMT 2024

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

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

Back to the top