我们想要重新实现一个旧项目,该项目通过 xtext 和 xpand 使用代码生成。 Xpand 应替换为 Xtend(2),并且应删除旧的 fornax 插件工作流程执行,并替换为 xtext 和 xtend maven 插件。
在旧项目中我们使用两个maven项目。
第一个是 xtext-project,它保存“ownLanguage”的语言定义,如果可能的话,只能作为编译依赖项重新使用。
第二个包含一个文件,其中包含所描述语言的模型、xpand 的旧工作流程和 xpt 文件。 旧的工作流程使用这个 main.xpt 作为入口:
«IMPORT ownLanguage»
«DEFINE main FOR Model-»
«EXPAND AttributeInterfaces::attributeInterfaces FOR this»
«ENDDEFINE»
这里引用了 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»
用于从“fieldDef”列表生成接口。 此“fieldDef”列表取自 model.ownLaguage 文件,该文件使用依赖项中的语言。
有没有办法将这些 .xpt 文件重写为 .xtend 文件,以便在新项目中结合使用 xtext 和 xtend maven 插件来生成与旧项目中相同的文件?
您可以使用依赖注入将其他内容导入到您的类中
@Inject extension Xxx
或者
@Inject Xxx xxx
然后从丰富的字符串中调用它
'''«method»'''
没有默认的maven或工作流程组件,但写一点gluecode应该没问题