Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Using Xtend for template code generation without a grammar(Noob)
Using Xtend for template code generation without a grammar [message #1220225] Tue, 10 December 2013 08:28 Go to next message
Eclipse UserFriend
I started using Xtext and Xtend to automatically generate classes and unit test cases for functional blocks which comprise the library for a CAD system I wrote.

Initially (prior to discovering DSLs) I wrote a bunch of block classes directly in Java, until I got tired of the repetition and figured out the easier way to do it (Xtext/Xtend). Some of those original classes written in Java have more elaborate features than is possible to represent with my current DSL model. I am OK leaving those written in Java for now but I would still like to use my unit test code generator to create unit test cases for them.

And rather than reading a DSL source file, I'd prefer to have the test code generator simply look in a specific place for a specific file name pattern (*CADBlock.java) and then use that name to generate the test case classes for each matching file.

Right now the test case code is isolated in its own Xtend class so all I have to do is to instantiate the class and send it a block class name (i.e. the "*" in *.CADBlock.java). I know that the DSL code generator gets triggered when I save a DSL source file. However, this is part of my DSL workspace, not my application workspace (which uses the DSL plug-ins).

I guess I could import the relevant code-generator Java code into my application workspace. Then I could have Java code look for the matching files and then send the substring over to the Java version of the code generator, to create the unit test classes each time the application runs, right before they are used. It seems a little clunky. Any suggestions as to a cleaner approach? I don't want to have to maintain two copies of the test code generator Java source.

[Updated on: Tue, 10 December 2013 09:11] by Moderator

Re: Using Xtend for template code generation without a grammar [message #1220280 is a reply to message #1220225] Tue, 10 December 2013 14:35 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

sorry i actually understand nothing. can you please elaborate what you actually want todo
and of course you can use xtend to generate code without grammar.

[Updated on: Tue, 10 December 2013 14:41] by Moderator

Re: Using Xtend for template code generation without a grammar [message #1220296 is a reply to message #1220280] Tue, 10 December 2013 17:36 Go to previous messageGo to next message
Eclipse UserFriend
I think what I'm going to do is to just create a Java application that scans the directories for existing Java files and then calls the Xtend to create the unit tests. It won't be triggered automatically. I'll run it when I feel like it and it will generate tests for whatever is there at the time.
Re: Using Xtend for template code generation without a grammar [message #1220320 is a reply to message #1220296] Wed, 11 December 2013 01:30 Go to previous message
Eclipse UserFriend
Simply give it a try?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Previous Topic:Error while starting xtext-Editor as RCP
Next Topic:Create a custom mapping from mydsl to JVM concepts
Goto Forum:
  


Current Time: Sun Jul 06 03:45:27 EDT 2025

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

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

Back to the top