Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend] Relative Qualified Names in my Template
[Xtend] Relative Qualified Names in my Template [message #716024] Tue, 16 August 2011 08:35 Go to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi again.

I want to produce Java Classes of my DSL files. In my grammar it's possible to reference elements within expressions.

The built in scope provider optimizes full qualified names perfectly (relative to the current position). I want the same behavior during Java code generation.

I have a set of rules for the generation:
1. A global package for generation is set: at.myproject.lib
2. Each file gets an own subpackage: at.myproject.lib.$file
3. Global Constants are written to a globals class: at.myproject.lib.${file}.${file}Globals
4. Each Type Declaration is written to it's own class: at.myproject.lib.${file}.${type-name}

Its just like a qualified name generator. My idea was to create a new IQualifiedNameProvider for java output and use it during code-generation. (<<myelement.javaQualifiedName>>)

But this would lead me to the problem that all names are fully qualified even if they are local variables:
module test; 

type MyType {
   int Size;
   int Test = Size + 1;
}

becomes to:

package at.myproject.lib.test;

class MyType {
   private int size;
   private int test = at.myproject.lib.test.MyType.size;
}


Is there a way to use an own qualified name provider during generation which gets optimized like it's done within the dsl itself during scoping?

Greetings Daniel

[Updated on: Tue, 16 August 2011 08:53]

Report message to a moderator

Re: [Xtend] Relative Qualified Names in my Template [message #716032 is a reply to message #716024] Tue, 16 August 2011 08:56 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the idea of the IQualifiedNameProvider is to provide the fully qualified name (a globally valid name, all optimisations are done by other components). If I was to solve this on a low level basis, I would write an extension that calculates the name of an object relative to a context object, that is <<myelement.relativeNameTo(contextObject)>>. You would then calculate the java name of the reference to Size relative to MyType.

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: [Xtend] Relative Qualified Names in my Template [message #716040 is a reply to message #716032] Tue, 16 August 2011 09:23 Go to previous messageGo to next message
Daniel Missing name is currently offline Daniel Missing nameFriend
Messages: 101
Registered: July 2011
Senior Member
Hi Alex.

Okay, therefore I will need to write everything myself. I thought there already might be such a system for creating qualified names during generation.

One of the next steps will be to create import statements instead of writing fully qualified names everywhere in my generated file.

How did you solve this problem in Xtend/Xbase itself? Does this feature come with the Jvm integration or did you solve the "relative" qualified names by yourself?

[Updated on: Tue, 16 August 2011 09:28]

Report message to a moderator

Re: [Xtend] Relative Qualified Names in my Template [message #716042 is a reply to message #716040] Tue, 16 August 2011 09:32 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

actually for Xbase there already is an ImportManager (see ImportManager and IAppendable). Check if there is some indication as to the usage in the DomainmodelExample shipped with Xtext. As to your last question, I did not solve the problem. I said "if I was to solve", meaning "if I had to do it".

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
Previous Topic:Can I use grammar written by antlr 3.3 in xtext2.0?
Next Topic:k value in antlr
Goto Forum:
  


Current Time: Fri Apr 23 03:11:26 GMT 2021

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

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

Back to the top