Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kayu5h opened this issue Mar 15, 2022 · 7 comments · Fixed by #2450
Closed

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

kayu5h opened this issue Mar 15, 2022 · 7 comments · Fixed by #2450
Assignees

Comments

@kayu5h
Copy link

kayu5h commented Mar 15, 2022

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.

2022-03-15.20-46-46.mp4
@rgrunber
Copy link
Member

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 : #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.

@kayu5h
Copy link
Author

kayu5h commented Mar 16, 2022

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.

@rgrunber
Copy link
Member

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.

@kayu5h
Copy link
Author

kayu5h commented Mar 17, 2022

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.

@kayu5h kayu5h closed this as completed Mar 17, 2022
@testforstephen
Copy link
Collaborator

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 #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.

@rgrunber rgrunber changed the title Bugs and Feature Request. Add individual "Generate Getters" & "Generate Setters" to Source Action menu Mar 17, 2022
@rgrunber
Copy link
Member

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

@rgrunber rgrunber reopened this Mar 17, 2022
@rgrunber rgrunber removed the question label Mar 17, 2022
@CsCherrYY
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants