ActionScript: invalid object getter/setter generation with alt-insert

Code generated by idea:

package obj {
public class Person {
    private var firstName:String;
    private var lastName:String;
    public function Person() {
    }

    public function get firstName():String {
        return firstName;
    }

    public function set firstName(value:String):void {
        firstName = value;
    }

    public function get lastName():String {
        return lastName;
    }

    public function set lastName(value:String):void {
        lastName = value;
    }
}
}

7 comments
Comment actions Permalink

Generate Getter/Setter action in ActionScript is designed according to Flex coding conventions.
"Give the storage variable for the getter/setter foo the name _foo"
http://opensource.adobe.com/wiki/display/flexsdk/Coding+Conventions#CodingConventions-Storagevariablenames

So please rename your variables to _firstName and _lastName and you'll get expected behavior.

0
Comment actions Permalink

Thank you for quick reply and work around help!
But convention is the only convention. What if i write code as i prefer (i have experience in java)?
Can i expect to see compilable code generated by Idea in next releases?

0
Comment actions Permalink
What if i write code as i prefer (i have experience in java)?

getter/setter in java is a method that has name getXXX/setXXX, whereas in flex there are special keywords get/set. So generally speaking java-style code in Flex is not what is called getters/setters, so this is not what Alt+Ins action is about.

Can i expect to see compilable code generated by Idea in next releases?

If you are talking about java-style code - I'm not sure that it is widely used approach in Flex. May be a different approach looks better: automatically rename property field to _property before generating getter/setter.

0
Comment actions Permalink

May be a different approach looks better: automatically rename property field to _property before generating getter/setter.


I think It would be a good thing. Thanks.

0
Comment actions Permalink

AlexanderD wrote:

automatically rename property field to _property before generating getter/setter.

Alexander,

That would be a great feature enhancement. I often find I want to encapsulate a property in a setter & getter. Currently I have to first do a rename of property to _property and then do the setter/getter generation. It'd be great if this was done in one step. Additionally, if propery is currently public, having IDEA change it to private or protected (selected via an option in the getter/setter dialog) would be icing on the cake. Let me know if you'd like a YouTrack feature request submitted on these.

Thanks,
Mark

0
Comment actions Permalink

Yes, please create an issue

0

Please sign in to leave a comment.