Skip to content
  Kermeta  

Using external code in kermeta

Document Actions

Semantic

See section Using existing java code in Kermeta of Kermeta Manual

Several mecanisms are supported :

Compiler subtitution

It is possible to create a kmt stub class with a tag @CompilerIgnore "true" that ask to not generate the code. The user is then responsible for providing a compiler compatible code for that class.

Ecore Genmodel annotation + bytecodeFromADependency

Kermeta is able to integrate java code coming from an Ecore genmodel. So it is possible to connect user code using the following technique: Create an ecore stub on the code you wish to encapsualte. Generate the genmodel, the java code, modify the java operation body use the "GENERATED NOT" annotation in the java code to keep modification in case of evolution in the ecore model. Build a jar from the java code.

In the kp, use the bytecodeFromADependency annotation and add a dependency to the jar in order to indicate that the code comes from the jar.

Rationale

We need to be able to easily include code that comes from the user (java libraries, integration in GUI, etc).


Open discussion

How to do some check on the the code added by the user ? => minimum : raise a "unsafe code warning" asking the user to double check his code.

Planned evolution

Support for the following techniques are planned :

  • extern : call to static operations (similar to kermeta 1)
  • embedded scala code : expert mode where the user can inject unchecked code directly in the generated code
  • require java : automatic analysis and creation of kmt wrapper to call usual java code (issue : dealing with constructors, method renaming, ...) similar to the experiment in V1