gpt4 book ai didi

java - 如何将代码生成从 xpand 迁移到 xtend(2)?

转载 作者:太空宇宙 更新时间:2023-11-04 11:43:59 25 4
gpt4 key购买 nike

我们想要重新实现一个旧项目,该项目通过 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”列表生成接口(interface)。此“fieldDef”列表取自 model.ownLaguage 文件,该文件使用依赖项中的语言。

有没有办法将这些 .xpt 文件重写为 .xtend 文件,以便在新项目中结合使用 xtext 和 xtend maven 插件来生成与旧项目中相同的文件?

最佳答案

您可以使用依赖注入(inject)将其他内容导入到您的类中

@Inject extension Xxx 

或者

@Inject Xxx xxx

然后从丰富的字符串中调用它

'''«method»'''

没有默认的maven或工作流组件,但写一点gluecode应该没问题

关于java - 如何将代码生成从 xpand 迁移到 xtend(2)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42512288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com