Using the backend

Using the backend

Before you can start, you need to install the following features:

  • Xtend Backend
  • Xtend Backend UML2Types
  • Xtend Backend XSDTypes
  • Xtend Backend Compiler
  • Xtend Backend UI (only required by the compiler)
  • Xpand Middleend
  • Xpand Middleend UI (only required by the compiler)
  • Xtend Middleend
  • Xtend Middleend UI (only required by the compiler)

Altenatively you may install the Xtend Backend SDK and Xpand Middleend SDK

As a quickstart you may use the Xpand Project wizard and select "Generate a sample EMF based Xpand project". After completion of the wizard you will find the workflow file "generatorWithBackend.mwe" in the "workflow"-folder. The workflow is ready to use the backend for generation.

The compiler can be activated as a builder by adding M2T Backend Compiler nature to the project. This is done selecting "Configure" > "Add M2T Backend Compiler" from the context menu of the Xpand project. All Xpand/Xtend/Check resources will then be compiler to Java source files into the "backend-gen" folder of the project. When selecting "Clean..." from the project menu the Backend Compiler will do a full build, while changing a Xpand/Xtend/Check resource will compile this resource incrementally.

The compiler is still experimental.

The backend can execute functions and templates that have been compiled to Java or other resources that can be handled by one of the available middleends. It automatically recognizes compiled resources if available on the build path and prefers them over native Xpand/Xtend/Check resources.

The best way to execute compiled functions/templates is to use the XpandComponent or XtendComponent. The name of the function to be called is the same fully qualified name as defined in Xpand/Xtend/Check.

Functions may also be contributed by the Java Annotations Middleend to the M2T Backend. The middleend is implemented by org.eclipse.xtend.middleend.javaannotations.JavaFunctionClassContributor . Registration of Java classes is done by calling the method classAsResource with a class.

Functions have qualified names in the backend represented by org.eclipse.xtend.backend.common.QualifiedName consisting of a namespace and a simple name. E.g. the Xpand definition template::Template::main has the namespace template::Template and the simple name main. The String representation of the QualifiedName would be template::Template::main. When registering Java Defined Functions, normally only the simple name of a function will be defined as it's name. The simple name is method name. To set the qualified name of a function use the annotation @M2tQualifiedName. The namespace will be derived from the fully qualified class name.

Per default, all public methods will be registered as functions. To prevent the registration of a method, annotate it with @M2tNoFunction. You may also use one of the following annotations:

  • @M2tCached - use caching
  • @M2tPrivateFunction - mark the function as private
  • @M2tAroundAdvice(pointcut) - use the method as around advice. The pointcut has the parameters:
    • namePattern - a pattern for function names as in Xpand paramTypeNames - an array with patterns of parameter type names hasVarArgs - true, if the matching functions have any number of parameters after paramTypeNames the specified in the pointcut

Functions defined by methods of a Java class can be directly called on the facade org.eclipse.xtend.middleend.javaannotations.JavaAnnotationBackendFacade . Call the method invoke to invoke functions defined in Java:

invokeFunction(String className, BackendTypesystem
					ts, QualifiedName functionName, List<?> params)