Getters/Setters template

Anyone know where the template code is for the getters and setters that IntelliJ generates? Thanks,

Marc

5 comments

I would also like to know if templates for equals and hashcode exist?

0

There are no templates neither for getters nor for equals/hashcode. These
are hardcoded in IDEA.

"Marc Stock" <no_mail@jetbrains.com> wrote in message
news:31534666.1134158103978.JavaMail.javamailuser@localhost...

Anyone know where the template code is for the getters and setters that

IntelliJ generates? Thanks,
>

Marc



0

Why are they hardcoded?

Also, if I want my getters and setters to all be single line statements, for example:

public String getName() {return name;}

How can I do that?

0

It's hardcoded, but you still can controll name generation(if needed):
IDE Settings >> Global Code Style, select "Code Generation"

Hier you can say, for example to prefex your fields with "m_"
In this case, for a field named "m_string", Idea will generate following getter/setter: getString and setString.
Without above setting it would be : getM_string and setM_string

For your single line problem, go to "Alignment and Braces" section, there should be an option to keep simple statements / code blocks as one line (not sure if there is a special setting for getters/setters

0

"For your single line problem, go to "Alignment and Braces" section, there should be an option to keep simple statements / code blocks as one line (not sure if there is a special setting for getters/setters"

Unfortunately, this does not effect generated getters and setters even if you reformat the code with Ctrl-Alt-l. Evidently, IDEA doesn't think getters/setters are simple enough. :) Oddly, if you do "Delegate Methods..." this respects the settings for keeping simple statements on one line. So, maybe this is a bug?

Frankly, I would like an option in IDEA that simply lets you make all your getters and setters collapsed as a group by default. Right now they only let you collapse an individual getter or setter. There's no need whatsoever to see a getter or setter so I have no idea why it has to fill my editor with this crap.

0

Please sign in to leave a comment.