Book a Demo

Author Topic: Code generation of classes and interfaces only?  (Read 3519 times)

Stephanie

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Code generation of classes and interfaces only?
« on: May 02, 2007, 12:15:56 am »
Hi,

I would like to use EA to generate source code out of activity diagrams / state diagrams. However, I had to read in the user guide that code generation is only suppported for classes / interfaces.

If this is right, is ther any possibility in EA to generate source code out of other UML elements than classes and interfaces?

mikewhit

  • EA User
  • **
  • Posts: 608
  • Karma: +0/-0
  • Accessing ....
    • View Profile
Re: Code generation of classes and interfaces only
« Reply #1 on: May 02, 2007, 01:41:50 am »
As I understand it, EA only deals with transforming structural elements of the model into code, hence classes and interfaces.

Any procedural/behavioural stuff like activities and states depends too much on implementation details - but some expert could no doubt improve on this answer.
« Last Edit: May 02, 2007, 03:59:28 am by mikewhit »

Bokkie

  • EA User
  • **
  • Posts: 80
  • Karma: +0/-0
  • Lima Bravo!
    • View Profile
Re: Code generation of classes and interfaces only
« Reply #2 on: May 02, 2007, 02:45:54 am »
I guess that would be possible. However I would advise you to transform those non-structurals first to structural items and then generate code. This is how I have managed to transform a state machine into a state pattern and from the latter code was generated. At first I used the transformation templates but they not so maintainable. Instead I use plug-ins (written in C#) nowadays.

Regards, M.
Lima Bravo!

Stephanie

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Code generation of classes and interfaces only
« Reply #3 on: May 02, 2007, 02:58:33 am »
Thanks for your answer. Sounds quite complicated. The code fragment I want to generate is rather small, I would prefer a more direct way (although I am quite interested in your mre general solution as well).

You say, that you think it is possible to generate code from behavioural diagrams with the Code Generation Framework. Cna you give me a hint, how?

Thanks in advance

Bokkie

  • EA User
  • **
  • Posts: 80
  • Karma: +0/-0
  • Lima Bravo!
    • View Profile
Re: Code generation of classes and interfaces only
« Reply #4 on: May 02, 2007, 09:50:32 pm »
You will need to build your custom transformations and I wish I could say "Read the manual". But the manual on transformation templates is very poor. To get there you will involve a lot of trial and error. I really would not know where to start explaining how the transformation templates work -apart from the tricks and hidden features...

It is definitely possible to generate code from behavioral diagrams such as state diagrams and activity diagrams. If you want to use the transformation templates you will really to dive in. Again, I suggest you develop a plug-in which are easier to understand (and better documented).

Some hints for the plug-in:
* There is an example C# project you can download from the sparx site
* iterating the states of a class:
Code: [Select]

foreach (EA.Element elem in source.Elements)
{
 if (elem.Type == "State")
 {
   // a state
 }
 else if (state.Type == "StateNode" && state.Subtype == 3)
 {
   // state machine starting point
 }

* Iterating the transitions:
Code: [Select]

foreach (EA.Connector transition in state.Connectors)
{
 if (transition.ClientID == state.ElementID)
 {
   if (transition.ClientID == transition.SupplierID)
   {
     // transition to self
   }
   else
   {
     // transition to other state
   }

* etc... etc...

HTH, M.
Lima Bravo!

Stephanie

  • EA User
  • **
  • Posts: 40
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Code generation of classes and interfaces only
« Reply #5 on: May 02, 2007, 11:14:07 pm »
Thanks a lot for giving me a "jump start". I will try to do it  with a plugin as you suggested.