Xtext Tip: Use Java instead of Xtend

Xtend is a wonderful language. It is specially practical when traversing ASTs and it is the best option to generate code. However, it is “is no longer the Java 17 of today”, as Christian Dietrich (one of Xtext maintainers) put it in this thread.

Hence, the recommended best practices for Xtend as of today are:

  • Use Xtend as a thin code generation layer.
  • Use Java for the rest of the logic.
  • Migrate Xtend code to Java whenever possible.
  • Set the code generators in the MWE file to generate Java stubs instead of Xtend (newer versions of Xtext do this by default.)

The configurations in the MWE file are the following:

Workflow {
	// other configurations might be necessary, here we present only the parameters needed
	// to avoid generating Xtend code
	// the generator is left to generate an Xtend
	component = XtextGenerator {
		configuration = {
			scopeProvider = {
				generateXtendStub = false
			}
			validator = {
				generateXtendStub = false
			}
			generator = {
				generateXtendStub = true
			}
	}
}
comments powered by Disqus