finos / rune-dsl

The project containing the Rune DSL grammar and default code generators
Apache License 2.0
27 stars 30 forks source link

Java generator is not on the same level as "external" generators #534

Open SimonCockx opened 1 year ago

SimonCockx commented 1 year ago

The Java generator should be considered "just one of the generators". Instead, it's currently tightly coupled to our RosettaGenerator, which is responsible for generating code for all available generators. The distinction between our Java generator and external generators leads to several issues.

To address these issues, I propose the following:

  1. Provide a consistent interface for all code generators (Java's and the "external" ones), which is only a small wrapper around Xtext's IGenerator2. It exposes the following methods:

    void beforeAllGenerate(ResourceSet input, IFileSystemAccess2 fsa, RosettaGeneratorContext context);
    void beforeGenerate(RosettaModel input, IFileSystemAccess2 fsa, RosettaGeneratorContext context);
    void doGenerate(RosettaModel input, IFileSystemAccess2 fsa, RosettaGeneratorContext context);
    void afterGenerate(RosettaModel input, IFileSystemAccess2 fsa, RosettaGeneratorContext context);
    void afterAllGenerate(ResourceSet input, IFileSystemAccess2 fsa, RosettaGeneratorContext context);

    (solves https://github.com/REGnosys/rosetta-dsl/issues/527)

  2. Inject a single implementation of the above generator inside our RosettaGenerator, which can then generate code with it only for that code generator. Generating code for different languages can then be done by creating a Guice module that provides the right implementation. (solves https://github.com/REGnosys/rosetta-dsl/issues/526)

  3. Provide a single way of accessing project version information through the IGeneratorContext, i.e., by subclassing it with RosettaGeneratorContext:

    public interface RosettaGeneratorContext extends IGeneratorContext {
    public String getProjectVersion();
    }

    (addresses issues encountered while developing a Python generator - see discussion here: https://github.com/REGnosys/rosetta-code-generators/pull/204#discussion_r1178049334)

hugohills-regnosys commented 1 year ago

The RosettaGeneratorContext should also contain a name (e.g. common-domain-model or digitial-regulatory-reporting etc) as this is required in some scenarios (e.g. specified in the .toml file in python).