Book a Demo

Author Topic: Code Generation Templates > Java ...  (Read 5094 times)

juanPablos

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Code Generation Templates > Java ...
« on: July 05, 2008, 06:58:25 pm »
Hello,

I want to modify the code gen templates for Java (as I'm generating ActionScript 3 code from EA - and Java is the closest match, both based on ECMA).

Here is what EA produces for Java auto accessor methods (or getter/setters if you like):

public function set setmyProperty(newVal:int): void
public function get getmyProperty(): int

I just want to modify the templates so that it doesn't generate the get and set keywords twice (as it currently appends these keywords to the front of property name), ie: I want it exactly the same as the 2 lines of code above, without the bolded text.

Cheers.
« Last Edit: July 05, 2008, 07:11:48 pm by juanPablos »

juanPablos

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #1 on: July 05, 2008, 07:09:11 pm »
Furthermore, I think I've found what I need to modify.

I believe I need to modify a Transformation Template. Specifically the Properties template within the Java language.

Here's what it currently looks like:

Code: [Select]
$attName=$parameter1
$type=$parameter2
$propertyName=$attName
$propertyName=%REMOVE_PREFIX($propertyName,genOptPropertyPrefix)%
%if genOptGenCapitalisedProperties=="T"%
$propertyName=%CONVERT_NAME($propertyName, "camel case", "pascal case")%
%endIf%
Operation
{
  %TRANSFORM_REFERENCE()%
  name=%qt%%genOptJavaGetPrefix%$propertyName%qt%
  stereotype="property get"
  scope="Public"
  type=%qt%$type%qt%
  code=%qt%return $attName;%qt%
  Tag{name="attribute_name" value=%qt%$attName%qt%}
}

Operation
{
  %TRANSFORM_REFERENCE()%
  name=%qt%%genOptJavaSetPrefix%$propertyName%qt%
  stereotype="property set"
  scope="Public"
  type="void"
  Parameter
  {
    name="newVal"
    type=%qt%$type%qt%
  }
  code=%qt%$attName = newVal;%qt%
  Tag{name="attribute_name" value=%qt%$attName%qt%}
}
So can anyone advise how to remove the get and set prefixing?, or at least let me know what language this is above? I'll search meanwhile, I'm assume it's a C language.

Thanks.
« Last Edit: July 05, 2008, 07:10:33 pm by juanPablos »

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #2 on: July 06, 2008, 12:53:37 am »
Maybe you could just clear Get Prefix and Set Prefix in Options>Source Code Engineering > Java?

Regards
Kris
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

juanPablos

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #3 on: July 06, 2008, 01:37:11 am »
Thanks Kris - I'll set how it goes.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #4 on: July 07, 2008, 08:46:42 am »
None of the Java templates will help you as they are not used when making these properties.  (The template you showed does copy the behavior though.)

Unfortunately I suspect that if the prefix options are cleared EA assumes a default.
« Last Edit: July 07, 2008, 08:47:58 am by simonm »

Krzysztof Swiatkowski

  • EA User
  • **
  • Posts: 76
  • Karma: +0/-0
  • Understanding is a three-edged sword
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #5 on: July 07, 2008, 09:22:16 am »
Unfortunatelly Simon your suspicion is correct, but good old space does the trick :)
If I put you finger in the eye
then you have finger in the eye
and I have finger in the eye
but it's not the same

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #6 on: July 07, 2008, 09:26:48 am »
Just be aware, that it won't synchronize them correctly.  The parser won't see any methods in the code that match your model method.

That's why I didn't suggest modifying the actionscript property set and property get templates to remove the prefix.  The same problem applies.

juanPablos

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #7 on: July 08, 2008, 02:53:14 pm »
so is there a way around this ?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #8 on: July 08, 2008, 04:00:55 pm »
There are always options, but not necessarily ones you would like.

1. Manually create the properties.
2. Manually remove the prefixes
3. Write an automation client, add-in or sql call to remove the prefixes.
4. Generate it once with the prefixes, modify it in code and reverse engineer.
5. Write a transformation to create the properties the way you want.

That's a start, but I'm sure it's nowhere near an exhaustive list.

juanPablos

  • EA Novice
  • *
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Code Generation Templates > Java ...
« Reply #9 on: July 08, 2008, 04:02:57 pm »
Thanks Simon M - that's a little outside my range of skills and timeframe at the moment. I'll stick to running a macro across the generated files for now.

Thanks again.