Automatic Getter & Setters settings

I was wondering if there is anywhere where I can set the Generate Getters and Setters options. All of my member variables start with "_" so when I ask it to generate the methods I'd like it to ignore that.
Also, is there a way to change the argument name? I usually just use newValue, but when I generate it uses the name of the variable, and then specifies this._whatever.
For example, if I have a class with a variable int size and I autogenerate getters and setters, I'd like to to create methods getSize() and setSize(int newValue) instead of getsize() and set_size(int _size)
Thank you.

9 comments
Comment actions Permalink

Hello Stephen,

I was wondering if there is anywhere where I can set the Generate
Getters and Setters options. All of my member variables start with
"_" so when I ask it to generate the methods I'd like it to ignore
that.


You need to specify that in your Code Style Settings. Then the "Generate
Getter/Setter" feature will honor this.

Also, is there a way to change the argument name? I usually just use
newValue, but when I generate it uses the name of the variable, and
then specifies this._whatever.


No, this isn't possible to configure in the current version./

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

I am not sure which one is more evil, putting "m_", "_", or "a", before all your member variables. They are all equally worthless and makes the code hard to read IMHO. (I had a manager that used to do this, drove me freaking crazy!)

Anyway, if you insist on such a horrible code style you probably want to go to Settings->Global Code Style->Code Generation Tab, should be able to set it to ignore the prefixes. (This is what my manager used to do and it worked fine).

0
Comment actions Permalink

Thank you, that works fine.

0
Comment actions Permalink

Well, actually it's what my boss has asked of me, and I don't really mind one way or the other. I'll keep your objection in mind, though, and see what others have to say.

0
Comment actions Permalink

Well my post was meant to be more tongue-in-cheek than it actually reads...it sounded that way in my head...just didn't come out that way in a forum post...hah!

Although I do think prefixing member variables with "m_", "_", or "a" is pure evil :) There are plenty of people that disagree with me:

http://weblogs.java.net/blog/malcolmdavis/archive/2004/08/class_variable.html

0
Comment actions Permalink

I agree those sorts of prefixes are nasty, but unfortunately I'm forced to
use them as part of our codestyle. What really kills me is having to type
'm_' in many cases before code completion even starts to become useful :(

Well my post was meant to be more tongue-in-cheek than it actually
reads...it sounded that way in my head...just didn't come out that way
in a forum post...hah!

Although I do think prefixing member variables with "m_", "_", or "a"
is pure evil :) There are plenty of people that disagree with me:

http://weblogs.java.net/blog/malcolmdavis/archive/2004/08/class_variab
le.html



0
Comment actions Permalink

>> What really kills me is having to type
'm_' in many cases before code completion even starts to become useful :(

Besides cluttering the code and making it hard to read, rendering code completion difficult to use is really my biggest complaint against prefixing member variables. So with "m_" it is three keystrokes before code completion becomes useful (m-shift-underscore). Very annoying...

0
Comment actions Permalink

Funny I feel the other way round (though I only use a single "_").
It makes completion faster and more useful, because after typing "_" I get only member variable as completion suggestions.

Michael Parmeley wrote:
>>> What really kills me is having to type

'm_' in many cases before code completion even starts to become useful :(

Besides cluttering the code and making it hard to read, rendering code completion difficult to use is really my biggest complaint against prefixing member variables. So with "m_" it is three keystrokes before code completion becomes useful (m-shift-underscore). Very annoying...

0
Comment actions Permalink

I do exactly the same. It also means you don't have your code peppered
with 'this.' or risk writing to a local var instead of a field or vice
versa.

N.

Stephen Friedrich wrote:

Funny I feel the other way round (though I only use a single "_").
It makes completion faster and more useful, because after typing "_" I
get only member variable as completion suggestions.

Michael Parmeley wrote:

>>>> What really kills me is having to type
>> 'm_' in many cases before code completion even starts to become useful :(
>>
>> Besides cluttering the code and making it hard to read, rendering code
>> completion difficult to use is really my biggest complaint against
>> prefixing member variables. So with "m_" it is three keystrokes before
>> code completion becomes useful (m-shift-underscore). Very annoying...

0

Please sign in to leave a comment.