Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij Code Completion for all setter/getter methods of local variable object

I did try searching for this, but honestly the terms to actually search are escaping me. A small code snippet followed by the question.

Public class Person {     String firstName;    String lastName;     public void setFirstName(String firstName) {       this.firstName = firstName;    }     public String getFirstName() {       return firstName;    }    ... } 

In another object that uses this person object I would like to be able to expand all the setters methods in Intellij.

public class PersonAssembler {      public static Person assemblePerson(SomeOtherObject someOtherObject) {      Person person = new Person;      //intellj would provide this below.     person.setFirstName();     person.setLastName();     //end of what intellj provides.      return person; } 

Is this even possible? I have looked through the keyboard short cuts, etc. I have been using intellij for a while, so just wondered if anyone had some insight on this.

I was hoping for column edit mode, then code completion and perhaps a shift+down arrow to select multiple completions, but no luck. Which is not surprising. I would hate to have to write that in the GUI.

Edit: I added some clarification and honestly forgot about this question. The answers have nothing to do with the actual question if read carefully. I am not speaking of the Generate context menu.

like image 795
Blake Dunn Avatar asked Jun 07 '13 16:06

Blake Dunn


People also ask

How do I automatically set getters and setters in IntelliJ?

You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor , Getter , Setter or Getter and Setter .

How do I enable code completion in IntelliJ?

Start typing. By default, IntelliJ IDEA displays the code completion popup automatically as you type. If automatic completion is disabled, press Ctrl+Shift+Space or choose Code | Code Completion | Type-Matching from the main menu. If necessary, press Ctrl+Shift+Space once again.

Why Autocomplete is not working in IntelliJ?

I have tried the following according to this thread (Intellij IDEA CE 12 Android XML Code Completion not working): Go to File->Power Save Mode and disable it - it is off. Go to Preferences->Editor->Code Completion and check Autopopup code completion - this has been checked. Go to File->Invalidate Caches and restart.


2 Answers

In your project, right-click anywhere on the typing screen, and click 'Generate...' and then 'Getter and Setter'. Then, hold down CTRL and click on the fields you wish to create getters and setters for, then click on 'OK'.

like image 73
Michael Jarvis Avatar answered Oct 20 '22 03:10

Michael Jarvis


This is an old question, but maybe it helps someone.

Also, it's not a "single-click" action, but...

Steps to follow:

  • Go to Class file
  • Open Structure view (left panel)
  • Select all setters (sort alphabetically if needed) and copy
  • Go back to your destination class/method
  • Paste copied
  • Edit (in column mode) to include person. at the beginning of each class and () at the end.
like image 33
rodrigobb Avatar answered Oct 20 '22 05:10

rodrigobb