Book a Demo

Author Topic: Java Code Generation  (Read 3232 times)

nbau2s

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Java Code Generation
« on: March 30, 2009, 11:32:26 pm »
Hello,
I have some problems with the Code Generation Features of Sparx EA.

First of all, when I transform my model to a Java Model and then generate the java code, Sparx EA seems to get confused with the stereotypes. All of my enumerations have two stereotypes: <<domain-value, enumeration>>, but Sparx EA seems to ignore the second stereotype because it generates simple java classes with getters and setters, not enumerations. If I delete the "domain-value" stereotype, the generation works correctly. Unfortunately, I did not find a way to remove that stereotype in the model-to model transformation. Is it possible to do something like this?

Secondly, I am a little surprised/disappointed by the quality of the generated java code. For example, Sparx EA does not transform the UML type "Real" to something that java understands (e.g. "double"). I added something like  
Code: [Select]
%if type=="Real"%
  type="double"
%else%
  type=%qt%%CONVERT_TYPE("Java",attType)%%qt%
%endIf%
to the Attribute template, but it seems I need to change more.

Furthermore, I set the collection type to be "Collection<#TYPE#>", but this does not generate the required imports (where do I have to add them?). The generated code also only provides simple setter and getter methods for the whole collection instead of add/remove/contains methods. Is there a way to change the template to create something like this.

All in all, are there "better" templates available somewhere?

Thank you in andvance,

Kind regards,

Nico


Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Java Code Generation
« Reply #1 on: March 31, 2009, 05:51:35 am »
Hi!


Quote
Unfortunately, I did not find a way to remove that stereotype in the model-to model transformation. Is it possible to do something like this?
You may be out of luck. I've done a few small tests and it appears that the %classStereotype% macro only returns the first stereotype if there are more than one. That would mean you could never find out that the element also has the <<enumeration>> stereotype.

I have also verified that the %elemType% macro returns Class for an Enumeration. This is weird, since the element type is listed correctly as Enumeration in the element properties - both for the original element and the transformed one.

I would expect an Enumeration not to have elemType Class, and I would also expect an Enumeration not to be given an <<enumeration>> stereotype as this seems to be two ways of saying the same thing.

But I'm probably showing my ignorance here...


/Uffe
My theories are always correct, just apply them to the right reality.