Xtend with external templates [message #713483] |
Mon, 08 August 2011 10:25  |
Eclipse User |
|
|
|
Hi again.
It seems I finally finished my DSL and now I want to create a compiler/code generator for my DSL. Xtend is an awesome language for writing such code generators but I'm not sure if they meet my requirements.
My compiler should be a standalone package which I can fire via command-line or ANT task (classpath, additional configurations etc) and the compiler should also support multiple output format-plugins for different target languages.
The main problem using Xtend is: I want the templates to be flexible and it should be possible to specify a template source jar/directory where the templates get loaded from. Xtend compiles it's template files into java classes, therefore they can't get modified without recompiling the whole compiler package. It's quite annoying if you only want to modify the template and need to recompile the whole compiler or compiler-plugin.
This is the workflow I want to achive:
1. The compiler gets invoked from commandline, ant or eclipse.
2. The compiler reads the configuration
3. The compiler loads the all models of the buildpath/classpath.
4. The compiler initializes and invokes the desired target-language plugin (i.E. Java)
5. The target-language plugin wraps the original model into an output optimized-model proxy (additional iterators, additional getters etc.)
6. The target-language plugin loads the desired template files from the specified template directory/jar
7. The target-language plugin uses the loaded templates to generate the code into the desired output directory.
How would you implement such an architecture? Is there a way I can build such a dynamic-template-loading / target-language-plugin-architecture using Xtend? Should I use such a workflow or should I take another approach?
I thought of using Freemaker as an alternative to Xtend.
Greetings
Daniel
[Updated on: Mon, 08 August 2011 10:25] by Moderator
|
|
|
|
|
Re: Xtend with external templates [message #713884 is a reply to message #713841] |
Tue, 09 August 2011 05:54  |
Eclipse User |
|
|
|
An additional question to this topic:
I want to place my compiler in an own project. Is there an easy way to add all required dependencies for creating an Xtend code generator? (xtext, xtend, guice, log4j ...)
I tried to add them manually but it doesn't seem to work well. Have created a "mydsl.compiler.java" project, added all libraries and added this xtend file:
package at.mydsl.compiler.java
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess
import at.mydsl.compiler.MyCompilerBase // implements IGenerator
import at.mydsl.smiDef.Model
class SmiDefJavaCompiler extends SmiDefCompilerBase {
String javaPackage
def String getJavaPackage() {
return this.javaPackage
}
def void setJavaPackage(String value) {
this.javaPackage = value
}
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
for(model : resource.contents.filter(typeof(Model))) {
}
}
}
But I get an error on resource.contents: "Couldn't resolve reference to JvmIdentifiableElement 'contents'."
The same file works within the main at.mydsl project.
[Updated on: Wed, 10 August 2011 03:45] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04473 seconds