Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Code generation like Domain Model?(The 1st and the next steps ...)
icon5.gif  Code generation like Domain Model? [message #555083] Wed, 25 August 2010 12:10 Go to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Code generation worked for the standard DSL (MyDsl) as well for the DomainModel (Excample). Now I have defined a new Project and I wonder, how one can do the code generation like in the DomainModel?

There are some more packages in the .ui project and the mwe2 are different for the DomainModel and my new project.

Do I simply add some fragment in the mwe2?

Or do i have to copy some packages in the ui project from DomainModel to my new project?

What are the next steps toward code generation like DomainModel?

Regards

Bodo
Re: Code generation like Domain Model? [message #555086 is a reply to message #555083] Wed, 25 August 2010 12:25 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Adapt the relevant code from the DomainModel example according to your
needs. That's what the examples are for. However, simply copyint the
packages is not sufficient.

Note that you need to register the builder participant (see plugin.xml
of the ui plugin).

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: Code generation like Domain Model? [message #555218 is a reply to message #555086] Wed, 25 August 2010 21:47 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hi Alexander,

now I changed the plugin.xml as you wrote and append the package generate.

I also managed to import all needed packages (xtend2 etc.).

But now I stick at the files with extension ext and xpt!

The first line (import) gives errors.

In my example the package names are org.xtext.algo and org.xtext.algo.ui

But if I set the imports to this package name I got the error Namespace .... is unknown or unused.

How one has to define the imports?

In the import of JavaBeans.ext one can write any string as import, no one complains! But the packageName() will throw an error.

Are there any help , how this 3 files has to be build?

Thanks

Bodo
Re: Code generation like Domain Model? [message #555333 is a reply to message #555218] Thu, 26 August 2010 11:14 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

> But now I stick at the files with extension ext and xpt!
See the documentation on Xpand and Xtend.

> But if I set the imports to this package name I got the error Namespace
> .... is unknown or unused.
If you have a closer look at the domain model example, you will see that
this is a type defined in that language. Of course you will have to use
your own types etc. rather than those of the example.

> How one has to define the imports?
See the above mentioned documentation. Basically here you import your
language, to make available its types. Alternatively, you can use fully
qualified names (:: being the separator).

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: Code generation like Domain Model? [message #555515 is a reply to message #555333] Thu, 26 August 2010 21:28 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Now I managed to get this tool work. But I want to know, how one can get access to the root element of the AST. In my case it is the class Modul. The method build in the class Generator got 2 arguments. Can one deduce this root element from the arguments or are there some other programmatic mechanism to access the root element of the AST?

Bodo
Re: Code generation like Domain Model? [message #555643 is a reply to message #555515] Fri, 27 August 2010 13:27 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

if you carefully walk through the code in the Generator class, you
should be able to follow what is going on. The context gives you access
to the changes in the workspace (context.getDeltas()) from them you can
retrieve the IEObjectDescriptions of the exported model elements.
Exported model elements are by default those that have a name attribute,
IEObjectDescriptions are used to keep track of known model elements even
if the file is not loaded (index for find references etc.)

Now the first line in the generate-Method retrieves the actual EObject
for an IEObjectDescription. This is one way to get at the model. If you
are now interested in the root element use EcoreUtil.getRootContainer on
that EObject.

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: Code generation like Domain Model? [message #555646 is a reply to message #555643] Fri, 27 August 2010 13:39 Go to previous messageGo to next message
Bodo is currently offline BodoFriend
Messages: 27
Registered: August 2010
Junior Member
Hi Alex,

thanks allot for your reply!

In the meantime i tried to do some experiments with the domain model. If one used the rule ENTITY every thing works fine, but not so for IMPORT. One can retrieve the content but only for Entity (or some sub rule) but not for the main rule DOMAIN_MODEL. And I didn't fined out where the rules are registered. I used this code to have a look what is in there (domain model):

Quote:

Iterable<IEObjectDescription> newOnes2 = delta.getNew().getExportedObjects();
for (IEObjectDescription d : newOnes2)
{

System.out.println ("d.name: " + d.getName());
System.out.println (" getQualifiedName: " + d.getQualifiedName());
System.out.println (" toString: " + d.toString());
System.out.println (" getClass: " + d.getClass());
System.out.println (" getEClass: " + d.getEClass());
System.out.println (" getEObjectURI: " + d.getEObjectURI());

}



I only got Entity, Reference, Attribute, but no Import even in the model-text there was an import.

Now I experimented with the object 'context' and tried this code:
Quote:

Object root = null;
TreeIterator ti = context.getResourceSet().getAllContents();
while (ti.hasNext())
{
root = ti.next();
if (root instanceof Model)
{
System.out.println ("hab dich!");
break;
}
System.out.println ("ti: " + root.getClass());
}




This time it works!

I hope, with this code, I also got the latest content from the editor.

Regards

Bodo
Re: Code generation like Domain Model? [message #555648 is a reply to message #555646] Fri, 27 August 2010 13:47 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

> In the meantime i tried to do some experiments with the domain model. If
> one used the rule ENTITY every thing works fine, but not so for IMPORT.

IEObjectDescriptions are only generated for exported elements. By
default this means model elements that have a name (you can reference
only things that have a name). You can adapt this standard behaviour,
though (adding or removin elements from the exported ones and also
influencing the names they are given).

This explainy why not all types can be found.

Alex


P.S.: you will have the same "problem" with the Reader component for
mwe2 workflows as discussed in several threads already.


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:xText Grammer Scoping for SQL SELECT statement
Next Topic:Problem with Xtext 1.0 tutorial in Documentation
Goto Forum:
  


Current Time: Sat May 04 05:00:40 GMT 2024

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

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

Back to the top