Xtend的代码生成代码的语句

时间:2018-07-04 09:30:47

标签: code-generation xtext xtend

我用Xtext实现了类似Java的语法,并且编辑器运行良好。现在,我开始使用xtend进行代码生成,以将dsl转换为java。 我的问题是:我想在xtend模板中打印该块(来自我的示例),因为它是类似Java的DSL。

这是我的DSL的示例:

namespace myExample;
import example.*;
Class test{
System.out.println("test");
}

Xtend-template:

def compile(SchedulerBlock a) ''' 
    package «a.getNamespace.name»;
    «FOR s : a.getImports»
    import «s.getImportedNamespace»;
    «ENDFOR»
    public class «a.name»{ 
    «FOR b : a.getBlock.getSequence.getStatements»
     « b.statement»
    «ENDFOR»

    }
'''

输出:

package myExample;
import example.*;
public class test{ 
org.xtext.hitecs.impl.InvocationOrAssignementOrDeclarationStatementImpl@b8f885c
}

我想添加“ System.out.println(” test“);”在街区,但我不知道该怎么办。

谢谢。

0 个答案:

没有答案