Book a Demo

Author Topic: Java Code Generation issues  (Read 4781 times)

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Java Code Generation issues
« on: November 13, 2007, 04:32:19 am »
Hi,

 As a new EA user, before I raise a series of bug reports I'd like to check if I'm doing something wrong! I'm using EA version 7.0.817.

We've noticed some oddities when generating Java code from a model, and are having to manually correct the code after generation. If we could resolve these it would help greatly. ???

Our UML model is pretty simple and contains classes with public properties and associations. I would like to auto-generate Java POJO code from this model, adhering to the usual JavaBean conventions.

1. Boolean properties - I have selected "Use is for boolean property get" but am still getting methods generated that are called "getXxx", not "isXxx".

2. Properties - I have selected "Capitalized Attribute Name for Properties", but some of our properties are being generated with an initial lower case, e.g. "getname" not "getName". Haven't found a pattern yet on when it works and when it doesn't.

3. Associations - Whereas a public property becomes a private attribute with public getter and setter methods using the Java Transformation, associations only generate getter and setter methods in the Java Model. When we then generate code we get the getter and setter methods, and a private member variable prefixed with "m_". I'd like associations to generate exactly the same code as properties, without the "m_".

Cheers,

 Chris

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation issues
« Reply #1 on: November 13, 2007, 11:37:15 am »
1 & 2. Without seeing your model, I suspect that these two things are happening because you created those properties before changing the options.  (The options apply when you're actually creating the properties in the model)

3. Associations don't transfer to an extra attribute because the association itself represents the attribute.  Have a look at modifying the transformation. (Linked Attribute template)

The "m_" prefix is probably being generated by the option for how to generate associations when no role name exists.  I'd recommend either giving your associations names, or changing the transformation again to create names that you like.

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Code Generation issues
« Reply #2 on: November 13, 2007, 02:20:59 pm »
Thanks for the reply. I'll deal with each issue one at a time.

For (1), I just started up EA, and check the "use Is .." option was selected. I then created a brand new project with just a domain model, then added a class with a public boolean property. I then used the Java transform and generated code, and I still get a method called "getXxx", not "isXxx".

Is there anything further I need to do?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation issues
« Reply #3 on: November 13, 2007, 03:57:17 pm »
It looks like the Java transform doesn't take that option into account.

You can modify this yourself (you can check the genOptGenPrefixBoolProperties macro) but you can also send in a bug report and we'll get to it.

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Code Generation issues
« Reply #4 on: November 14, 2007, 02:05:44 am »
I've raised a bug report.

Moving onto issue 3, our associations *do* have names. It seems the Java Transform ignores those too, so I'll raise another bug report?

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Java Code Generation issues
« Reply #5 on: November 14, 2007, 04:42:02 am »
Yes, please do.

And please let us know what Sparx has to say on the subject, and whether they give any idea of a resolution schedule.

Thanks much,
David
No, you can't have it!

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Code Generation issues
« Reply #6 on: November 15, 2007, 01:44:31 pm »
Some feedback on the third issue - EA transforms only use target role names, not association names. If there is no target role name, even if there is an association name, it uses the classname of the target instead.

The oddity that I hope will be resolved is that if there is a role name, the instance variable uses that. However if there isn't a role name then the instance variable is prefixed with "m_".

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation issues
« Reply #7 on: November 15, 2007, 02:35:48 pm »
There is an option for the name of the attribute created. Tools | Options | Code Engineering | Attributes/Operations.

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Code Generation issues
« Reply #8 on: November 15, 2007, 03:16:47 pm »
There's a "Default name for associated attrib" field on that dialog box that's disabled, is that what you mean?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Java Code Generation issues
« Reply #9 on: November 15, 2007, 08:50:34 pm »
Yes.  That option is a property of a model and is disabled if no model is open.

It defaults to m_$LinkClass
« Last Edit: November 15, 2007, 08:50:59 pm by simonm »

cjn

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Java Code Generation issues
« Reply #10 on: November 16, 2007, 12:46:48 am »
Ah, ok. I didn't realise some of the "Options" applied to the current model, and the rest to EA itself.

What would I change it to for EA to generate an instance variable based on the target class name, but with a lower case initial letter?