vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Add individual "Generate Getters" & "Generate Setters" to Source Action menu

Open kburnwall opened this issue 4 years ago • 7 comments

Feature Request: We already have an option for generating Getter and Setter together. But we don't have an option to generate Getter and Setter separately while IntelliJ Idea by Jet Brains already has this feature. :( image

Can you please disable this option for adding this line when Overriding a method? image The line starting with TODO is a very annoying feature. I always have to remove it. There does not seem to be a big problem here, but still.

Bug: Whenever I generate a constructor in the active cursor line. The constructor is always generated after the last character (excluding the space). Here's a video clip explaining my issue if you didn't get it.

https://user-images.githubusercontent.com/90521537/160248863-b5c9d328-cab6-449d-afff-c13b26f983d3.mp4

kburnwall avatar Mar 15 '22 15:03 kburnwall

You should be able to generate the individual getter/setter methods for a field by triggering auto-completion directly in the class body and completing the name of the field.

This is getting popular, so maybe we should consider it : https://github.com/redhat-developer/vscode-java/issues/1792 . Allowing users to customize (or eliminate) things like the auto-generated method stub is possible. We just currently haven't provided it yet, although we do for file & type comments. To do it I think we'd need to provide a setting, and then read+update it at https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/preferences/PreferenceManager.java#L185 .

I just looked in https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/GenerateConstructorsHandler.java#L169, and although cursor position is taken into account, I think we only insert relative AST elements. Things like whitespace aren't represented in that so I don't think we have a way to insert at the exact cursor position.

rgrunber avatar Mar 16 '22 00:03 rgrunber

Would I be able to simply get the choice for generating Getter/Setter exclusively while clicking 'Source Action' very much like in IntelliJ IDEA? image As you can see in IntelliJ, we have a choice both for creating Getter and Setter at the same time and one for producing them independently.

Additionally, simply a little solicitation from me. Whenever we create an object in IntelliJ and begin giving values to the variables. IntelliJ shows us the Data Type and the names of the variables present in that Class. image It would be great if VS Code had this option. Also, much obliged for answering so rapidly.

kburnwall avatar Mar 16 '22 09:03 kburnwall

It shouldn't be difficult to support just "Getter" & "Setter", although for now there are ways to generate these directly from completion (much like a snippet).

The option to get those hints is known as signature help, and can be enabled in settings, java.signatureHelp.enabled=true .

@testforstephen , @fbricon , Is there a reason signature help is disabled by default ? Might be good to consider changing this for the sake of visibility.

rgrunber avatar Mar 16 '22 13:03 rgrunber

I used snippets for getters and setters and that is the reason I advised you to add it. I still think it would be better. Even though, much appreciated.

kburnwall avatar Mar 17 '22 08:03 kburnwall

Is there a reason signature help is disabled by default ? Might be good to consider changing this for the sake of visibility.

Currently when you are typing a method, the completion feature also suggests a full list of the overloaded methods, that's kind of duplicated with signature help. That's why signature help is disabled by default. See more discussion here https://github.com/redhat-developer/vscode-java/issues/2063

Also it makes sense to add two separate "Generate Getters" and "Generate Setters" menus in Source Action. For example, I use constructor to set the field values, but using getters to expose the accessors.

testforstephen avatar Mar 17 '22 09:03 testforstephen

Re-opening as a request to implement the individual source action items.

rgrunber avatar Mar 17 '22 19:03 rgrunber

+1 for the individual source actions. I'm going to implement this.

CsCherrYY avatar May 11 '22 08:05 CsCherrYY