Author Topic: Golang source code generation  (Read 543 times)

registered

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Golang source code generation
« on: June 14, 2017, 09:40:33 pm »
Can anyone share experience (if any) on generating Go language source code out of class diagram/model?
At least, is it possible at all and if so, where to start from?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7742
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Golang source code generation
« Reply #1 on: June 18, 2017, 03:56:57 pm »
I have no experience with that specifically.

Probably the best course of action is to copy an existing transformation that is closest to the language you are trying to generate and start from there.

Geert

Helmut Ortmann

  • EA User
  • **
  • Posts: 884
  • Karma: +37/-1
    • View Profile
Re: Golang source code generation
« Reply #2 on: June 19, 2017, 12:48:52 am »
Hi,

GO isn't supported out of the box by EA.
See: http://sparxsystems.com/enterprise_architect_user_guide/13.0/model_domains/languages_supported.html

You can add a new language for forward generating with the Code Template Editor (see: file:///C:/Program%20Files%20(x86)/Sparx%20Systems/User%20Guide/model_domains/thecodetemplateeditor.html).
But be aware it only supports forward generating. For reverse engineering (from Code to Model) you have to stick to the EA supported languages or define your own languages with the Grammar Framework (see below).

Also be aware defining your own language is a lot of work and needs experience.

If you only want to forward generate Code from a Model, you have the two options
- Code Template Editor as mentioned before
- Make your own generator with an Add-In or Script (I would prefer Add-In)
 

You can use the grammar framework to define your language. I've no experiences with it.
http://sparxsystems.com/enterprise_architect_user_guide/13.5/model_domains/grammar_editor_for_imported_co.html

Kind regards,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

registered

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Golang source code generation
« Reply #3 on: June 19, 2017, 08:42:45 pm »
I'm trying to keep things as simple as possible.
With assumption that I'll need only Model -> Code transformation,
it seems that Code Template Editor is a suitable choice.
Is there a way to generate new language in code template editor based on existing language?
I think, C# will do just fine.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 7742
  • Karma: +165/-21
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Golang source code generation
« Reply #4 on: June 20, 2017, 04:16:11 pm »
I just had a look and there doesn't seem to be a simple way to copy an existing set of code generation templates.

You can either do it one by one by hand, or figure out where EA stores those templates in the database and create copies there, or you could just use C# and update that to match your requirements. You won't be able to generate regular C# anymore using that repository, but maybe you don't need that at all.

Geert

Helmut Ortmann

  • EA User
  • **
  • Posts: 884
  • Karma: +37/-1
    • View Profile
Re: Golang source code generation
« Reply #5 on: June 20, 2017, 04:25:57 pm »
Hello,

the simplest way is just to change the C# template. Drawback C# means GO.

You can also create a new template with the Code Template Editor by:
- Click on New Language
- Click on Add product
- Insert something
EA adds a new language.

Then you can manually copy C# content to GO content. You may use Reference data for *.xml import/export of the changed templates.
See: http://www.sparxsystems.com/enterprise_architect_user_guide/13.0/model_repository/exportrefdata.html for the basics.

You may slightly change the C# Templates, e.g.insert a dot, export to *.xml, tinker with *.xml and import as GO.
See: http://www.sparxsystems.com/enterprise_architect_user_guide/13.0/model_repository/exportrefdata.html for the basics.

Maybe there is another possibility to easily copy a Code/Transformation template.

Kind regards,

Helmut

If you just do it once make it by hand. It's half an hour and you are done.

Kind regards,

Helmut

Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)