Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How place getter/setter methods at the bottom of a class definition in intellij

I use the Generate function in the context menu to create my getter and setter methods. But there seems no way to tell Intellij to place the generated methods after the last method in the file ie at the bottom of the class definition. This is possible in Eclipse. Anybody know how to do it automatically in Intellij?

like image 938
M.K. Avatar asked Mar 11 '14 10:03

M.K.


People also ask

How do I getter and setter method names in IntelliJ?

The getter and setter method names are generated by IntelliJ IDEA according to your code generation naming preferences. On the Code menu, click Generate Alt+Insert. In the Generate popup, click one of the following:

How do I create a getter and setter method?

Getter and Setter to generate both accessor and mutator methods. Select the fields to generate getters or setters for and click OK. You can add a custom getter or setter method by clicking and accessing the Getter/Setter Templates dialog. If a field is not in the list, then the corresponding getter and setter methods are already defined for it.

How to access The fullname setter and getter of a class?

Now, you can access the fullname setter and getter like a regular class property: Use TypeScript getters/setters to control the access properties of a class. The getter/setters are also known as accessors/mutators.

Can IntelliJ generate accessor and mutator methods for my classes?

IntelliJ IDEA can generate accessor and mutator methods ( getters and setters) for the fields in your classes. Generated methods have only one argument, as required by the JavaBeans API. The getter and setter method names are generated by IntelliJ IDEA according to your code generation naming preferences.


2 Answers

If you want to generate getters and setters via Generate menu, the only way is to place cursor at the bottom of your class (or wherever you want them to be)

But if your field is not used yet, there is another option: navigate to the field you need getter/setter for, press Alt+Enter (it calls intentions dialog) and choose "generate getter and setter" option. Then getter and setter will be generated at the bottom of the class (but not below inner classes if any).

like image 159
Alissa Avatar answered Nov 04 '22 08:11

Alissa


First of all a little hint. IntelliJ is designed to use without a mouse, so I prefer using the keyboard-shortcut Alt + Insert for code generating.

I don't know any possibility to generally define the place for inserting generated code. I recommend to place the cursor there, where you want to insert generated code and then generate it.

like image 45
rufer7 Avatar answered Nov 04 '22 08:11

rufer7