1

We wanto to reimplement an old project, wich used code generation via xtext and xpand. Xpand should be replaced with Xtend(2) and the old fornax plugin workflow execution should be removed, replacey by xtext and xtend maven plugins. In the old project we use two maven projects. The first is a xtext-project, which holds the language definition for "ownLanguage" and should only be re-used as compiled dependency, if possible. The second one holds a file with a model in the described language, an old workflow for xpand and the xpt files. The old workflow used this main.xpt as entry:

«IMPORT ownLanguage»
«DEFINE main FOR Model-»    
    «EXPAND AttributeInterfaces::attributeInterfaces FOR this»
«ENDDEFINE»

And here the referenced AttributesInterfaces.xpt

«IMPORT ownLanguage»
«DEFINE attributeInterfaces FOR Model»
    «EXPAND attributeInterface FOREACH this.fieldDefs»  
«ENDDEFINE»

«DEFINE attributeInterface FOR FieldDef»
    «FILE "com/package/attributes/" + this.name.toFirstUpper() + "Attribute.java"»
        package ....attributes;     

        public interface «this.name.toFirstUpper()»Attribute {

           «this.type.mappedTypeNullable.fullName» get«this.name.toFirstUpper()»OrNull();

       }
    «ENDFILE»
«ENDDEFINE»

It is used to generate interfaces from the list of "fieldDef". This list of "fieldDef" is taken from the model.ownLaguage file, which uses the language from the dependency.

Is there a way to rewrite these .xpt files to .xtend files, to use these in the new project with a combination of xtext and xtend maven plugin to generate the same files as in the old project?

gregor
  • 63
  • 6

1 Answers1

0

You can use dependency injection to import other stuff to your class

@Inject extension Xxx 

Or

@Inject Xxx xxx

An then call it from a rich string

'''«method»'''

There is no default maven or workflow component but it should be no problem to write a bit of gluecode

Christian Dietrich
  • 11,778
  • 4
  • 24
  • 32