Sparx Systems Forum

Discussion => General Board => Topic started by: 0level on December 16, 2003, 11:24:26 am

Title: Code templates & generation: getter & sett
Post by: 0level on December 16, 2003, 11:24:26 am

I hope I did not miss this one in the manual.
Is there a way to create getters and setters automatically for a custom language?

I would like something like this:

private var property;

function set property() {
 return property;

function get property() {
 // bla

Thanks in advance
Title: Re: Code templates & generation: getter &
Post by: joyce on December 19, 2003, 09:25:49 am
Hi Olaf, we discovered that when we imported some c# code it made a stereotype called "property" for getters and setters in our code.

If we created a new stereotype called "property" in the Uml Stereotypes configuration screen in EA then used it on new classes it created a proper get and set for them when code was engineered from the diagram.

However it does not appear to be documented anywhere and you can't select a read only or a write only property.

Hope this helps in some way and hope we get an answer about this from someone soon or I'm going to be manually deleting a *lot* of setters for read only properties when we engineer the code from the big project were working on.

Title: Re: Code templates & generation: getter &
Post by: 0level on December 19, 2003, 10:32:11 am
Hi Joyce,
thanks for the hint. Maybe your problem with importing(?) code could be cured with the substitution macros? There are syntax files (like cgt_syntax.xml) which may be helpfull to change. Just an idea.

I found the property flag in the attribute tab which lets you create a getter/setter method. In this tab you can only get OR set, too. Fine. But this is not implemented for Actionscript and I do not know where to look :-(

BTW: If you change the attributes name after these getter/setters have been created the methods did not change automatically nor does EA asks wheater it should do so.

Even exporting the full reference data does not help too much: I thought there might be a possibility there.  :-/

Maybe there is a Sparx member how can help out, here?

So long
Title: Re: Code templates & generation: getter &
Post by: benc on December 22, 2003, 10:09:03 pm
Hi Olaf,

This may be possible after some tinkering with the code templates.

I'm really just thinking out loud here ...

Would it be possible to stereotype your attributes as "property" and then check for this in your Attribute Declaration template? (I'm assuming you have some ActionScript templates already defined in EA).

You might be able to get away with adding something like:

%if attStereotype == "property"%
function set property() {\n\t%attName% = value;\n}
function get property() {\n\treturn %attName%;\n}


You could use tagged values on the attribute to control whether the generated property is read only or write only. This can be easily checked from the templates also.

Let us know how you get on.