GeneratorConfig.textile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. h1. Generating Code
  2. Code generation can be configured by providing a generator configuration model (a text file with suffix __.sgen__) that defines the code generator to use and the generator specific parameters.
  3. The code generator can be executed via the context menu of the __.sgen__ files (__right click > Generate statechart Artifacts__).
  4. h2. Common Generator Configuration
  5. A minimum generator model looks as follows:
  6. pre. GeneratorModel for yakindu::c {
  7. statechart MyStatechart {
  8. feature Outlet {
  9. targetProject = "MyProject"
  10. targetFolder = "src-gen"
  11. }
  12. }
  13. The generator to use is configured by specifying the corresponding generator id (__yakindu::c__ in the example).
  14. Available generator ids are:
  15. * __yakindu::c__ Generates C Code
  16. * __yakindu::cpp__ Generates C++ Code
  17. * __yakindu::java__ Generates Java Code
  18. * __yakindu::generic__ Executes Generators from the workspace
  19. * __yakindu::xpand__ Executes Xpand templates form the workspace
  20. For each statechart that shall be processed, a configuration block must be provided that contains the configuration for the generator features (starting with keyword __statechart__ followed by the name of the statechart).
  21. Every generator requires the __Outlet__ feature that defines the target project and folder where the output shall be written.
  22. Depending on the chosen generator, more features might be required.
  23. h2. Using the Generator Model Wizard
  24. The wizard for generator models is available under __New > Yakindu > YAKINDU statechart Generator Model__.
  25. It allows to select statecharts that should be processed and a generator type to use.
  26. The wizard will create a new generator model file with reasonable defaults for the generator's configuration features.
  27. h1. Generic Xpand Generator
  28. The generic Xpand Generator (Generator id __yakindu::xpand__) allows to execute Xpand templates located inside the workspace.
  29. h2. Configuration
  30. The generator requires a __Template__ configuration feature that defines the Xpand template that shall be executed.
  31. pre. GeneratorModel for yakindu::xpand {
  32. statechart MyStatechart {
  33. feature Template {
  34. templateProject = "MyXpandProject"
  35. templatePath = "org::yakindu::sct::generator::xpand::Main::main"
  36. }
  37. feature Outlet {...}
  38. }
  39. }
  40. h2. Implementation
  41. The Xpand template is expected to have the following entry method signature:
  42. pre. «DEFINE main(sgen::GeneratorEntry entry) FOR sexec::ExecutionFlow-»
  43. «ENDDEFINE»
  44. h2. Xpand Generator Project Wizard
  45. A wizard for Xpand-based generators is available under __New > Yakindu > YAKINDU Xpand Generator Project__.
  46. It will create a new project with all needed library dependencies and a hello world template to generate artifacts from a statechart.
  47. h3. Exporting the Generator as Plugin
  48. The wizard provides options to setup the new generator project as exportable plugin.
  49. Therefor, a generator id, a generator name and a generator class name must be specified. Optionally, a feature library can be generated to use custom configuration options with the generator.
  50. h1. Generic Workspace Generator
  51. The generic Workspace Generator (Generator id __yakindu::generic__) allows to execute Java classes located inside the workspace.
  52. h2. Configuration
  53. The generator requires a __Generator__ configuration feature that defines the Java class that shall be executed
  54. pre. GeneratorModel for yakindu::generic {
  55. statechart MyStatechart {
  56. feature Generator {
  57. generatorProject = "MyJavaProject"
  58. generatorClass = "org.yakindu.sct.generator.MyGenerator"
  59. }
  60. feature Outlet {..}
  61. }
  62. }
  63. h2. Implementaion
  64. The Java class that is referenced from the configuration must extend __org.yakindu.sct.generator.core.AbstractWorkspaceGenerator__.
  65. The signature of the generator entry method looks as follows:
  66. pre. public class MyGenerator extends AbstractWorkspaceGenerator {
  67. @Override
  68. public void generate(ExecutionFlow flow, GeneratorEntry entry) {
  69. }
  70. }
  71. If you prefer to implement the generator using Xtend, the following signature is required:
  72. pre. class Bla extends AbstractWorkspaceGenerator {
  73. override generate(ExecutionFlow flow, GeneratorEntry entry) {
  74. }
  75. }
  76. h2. Generic Java Generator Project wizard
  77. A wizard for Java/Xtend-based generators is available under __New > Yakindu > YAKINDU Workspace Generator Project__.
  78. It will create a new project with all needed library dependencies and a default generator implementation.
  79. The type of the generator (Java or Xtend) can be chosen from the wizard.