umple icon indicating copy to clipboard operation
umple copied to clipboard

Create a generator that automatically generates Javascript or Python from Umple, perhaps by calling a transpiler from Umple

Open TimLethbridge opened this issue 7 years ago • 4 comments

The way to do this would be the following:

  1. Create a new generator for Python
  2. At the start of every build it would copy the Java generation templates from the Java compiler (they would not be committed)
  3. Initially, then, the Python generator would generate Java.
  4. Then, a translator would be used to translate templates to Python. This might use TXL or some similar technology, that would be invoked by the build.
  5. A few templates should be translated at a time, starting with basic empty class, then class with attributes, then generalization, then associations of different kinds, then state machines, etc.
  6. As translation is improved, tests should be added for Python.

The above should be put into UmpleOnline but 'hidden'. You can type av or db into the Line= field to set the Page.getAdvancedMode variable and hence enable extra features to become visible.

You need to do this in an agile way. Create a branch called issue1384 and commit to that branch so that we can regularly test as improvments are being made.

Eventually, the same approach could be used to generate javascript.

The following is the original comment (superceded by the above) Add a generate Javascript and/or a generate Python capability.

Since this would be a lot of work and would require constant maintenance (editing each template for every languag), perhaps the best solution would be a source-to-source transpiler that could be applied to Umple-generated Java, or a transpiler that would automatically transpile the Java templates into the new target langauge (and would repeat the process every time Umple is built, incorporating any new templates).

Some tools that could be considered are here:

https://www.quora.com/What-is-the-best-way-to-automatically-convert-Java-to-JavaScript

TimLethbridge avatar Oct 03 '18 19:10 TimLethbridge

Generating Python via a transpiler could also be considered

TimLethbridge avatar Oct 30 '19 21:10 TimLethbridge

@TimLethbridge Is there any plan to investigate some effort on generating code for Python? Python is growing fast and many fields completely rely on this language. Being able to model the system and generate code with best practices will be appreciated by many Python users.

vahdat-ab avatar Jun 17 '20 01:06 vahdat-ab

This is being worked on by a Capstone group in 2021. https://github.com/umple/Umple/wiki/UOttawaCapstoneGroup2021

TimLethbridge avatar Jan 28 '21 17:01 TimLethbridge

The following questions were asked by @VincentMadoreC

1) To clarify, is the point of TXL to use the Umple code as tokens to output the different languages? If so, I would assume there would need to be a different implementation for each language. In this case, what would be the benefit?

TXL allows you to write rules that translate from one form to another relatively easily. Translation has to be done somehow, but TXL should allow this to be done rather directly here (conversion of Umple templates to Umple templates, where a lot of the template detail would not change), and the work can be agile (a rule at a time), which can help greatly. Yes, there would need to be a different rule sets for each language, but that would always be the case. Another viable option would be to use Umple itself to parse the templates into Umple's internal metamodel. Then to write some Java to convert relevant bits of Java to relevant bits of Python, but that would be somewhat 'opaque'. A language like TXL would allow creating a textual rule base to do the conversion.

2.1) If we used transpilers, would we need a specific tool for each language?

Yes, I would imagine so.

2.2) From what I gathered, there doesn't seem to be reliable tools to translate Java to Python, even though there are for Java to JavaScript, like GWT for instance.

You may be right. Part of this issue is to research that.

One thing to remember is this: Only a very small subset of Java is being used in the most templates. There may be some challenges with concurrency and timing in state diagrams; but let's be agile and get a small subset of python generating first. The possibility exists of generating for Jython too (separately or in addition).

3) How relevant is it really to generate JavaScript from class diagrams? Nowadays there are so many different libraries that I feel like it would be hard to make something useful. I feel like raw JS is rarely used nowadays

I agree. Perhaps not so important. Remember though that this is not just about class diagrams: Umple does far more, including state diagrams. There have been user requests for this, but Python has been the big request.

TimLethbridge avatar Mar 19 '21 15:03 TimLethbridge