Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Package declaration help
Package declaration help [message #698300] Tue, 19 July 2011 08:32 Go to next message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Hi,

Im trying to generate java code with a package. But i cannot get the package name in my template.

Model :
name=ID
(packages+=Package)*;

Package:
"package" name=STRING '{'
(types+=Type)*
'}';

Type:
DataType | Droplet | FormHandler | Properties | JSP ;

....
...

xpand:

«DEFINE main FOR Model»
«EXPAND allpackages FOREACH packages»
«ENDDEFINE»

«DEFINE allpackages FOR Package»

«EXPAND droplet FOREACH types.typeSelect(Droplet)»
«EXPAND formhandler FOREACH types.typeSelect(FormHandler)»
......
...
«ENDDEFINE»


«DEFINE droplet FOR Droplet»
«FILE name+".java"»
«Package.name» //gives com::atg::atgdsl::atgDsl::Package
«ENDFILE»
«ENDDEFINE»

sample dsl:

package "com.user" {

datatype String

droplet SearchDroplet {

}

genrated code

com::atg::atgdsl::atgDsl::Package
public class SearchDroplet {
}

I need as follows

package com.user

public class SearchDroplet {
}

Thanks,
Arun
Re: Package declaration help [message #698305 is a reply to message #698300] Tue, 19 July 2011 08:39 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

you should define helper methods for that. The quick way is navigating to the container, casting to Package, obtain the name.

«FILE name+".java"»
«((Package)eContainer).name»

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Package declaration help [message #698322 is a reply to message #698305] Tue, 19 July 2011 09:10 Go to previous message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Thanks Alex! . Done with a helper method.

//Arun
Previous Topic:[xtext2.0] Hover not working in nested Rules.
Next Topic:Persistence problem with optional assignment rules
Goto Forum:
  


Current Time: Sat Sep 19 16:04:47 GMT 2020

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

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

Back to the top