ActionScript: invalid object getter/setter generation with alt-insert Follow
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;
}
}
}
Please sign in to leave a comment.
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.
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?
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.
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.
I think It would be a good thing. Thanks.
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
Yes, please create an issue
http://youtrack.jetbrains.net/issue/IDEA-52369 has been created.
Thanks Alexander.