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

Generate Getter and Setters from code completion #100

Closed
scgm11 opened this issue Nov 23, 2016 · 15 comments
Closed

Generate Getter and Setters from code completion #100

scgm11 opened this issue Nov 23, 2016 · 15 comments
Assignees
Milestone

Comments

@scgm11
Copy link

scgm11 commented Nov 23, 2016

Be able to add automatic getter, setters on a class and also override methods if extending a class

@gorkem
Copy link
Contributor

gorkem commented Nov 23, 2016

Is this a request to get code actions or code lenses for generating getters and setters ? Overrides are covered on #85 for completions

@scgm11
Copy link
Author

scgm11 commented Nov 23, 2016

the idea is like intellij or netbeans right click in a class give you de generate code.. getter and setters for selected variables or others like overrides if the class is extended

@dineiar
Copy link

dineiar commented May 3, 2017

Looking forward to this.

@dineiar
Copy link

dineiar commented May 3, 2017

For now, I put this code under java.json (File > Preferences > User Snippets > Java):

"Getter/Setter": {
	"prefix": "getset",
	"body": [
		"public ${1:int} get${2:Attribute}() {",
		"\treturn this.${3:attribute};",
		"}",
		"public void set${2:Attribute}(${1:int} ${3:attribute}) {",
		"\tthis.${3:attribute} = ${3:attribute};",
		"}"
	],
	"description": "Generate getter/setter for class attributes"
}

Write "getset" and VSCode offers the snippet, then use Tab to navigate on the placeholders.

@fbricon
Copy link
Collaborator

fbricon commented Jul 24, 2017

so with @yaohaizh's PR, the setters and getters will be available as code completion proposal, not as a global command initially (we can work on that latter)

jul-24-2017 10-31-52

@gorkem
Copy link
Contributor

gorkem commented Jul 24, 2017

@yaohaizh this is looking great. Can we enable this as a code action too?

@fbricon fbricon changed the title Getter and Setters Generate Getter and Setters from code completion Jul 26, 2017
@fbricon fbricon added this to the End July 2017 milestone Jul 26, 2017
@phil294
Copy link

phil294 commented Jan 14, 2018

bulk generation like in jetbrains or eclipse would be pretty useful also.

@augustocdias
Copy link

And would be nice to have generators not only for getters and setters, but also for constructors, toString, hashCode, equals and overrides

@mogarick
Copy link

@phil294 and @augustocdias I think it'd be better if you open a new issue because this was closed a year ago and it's very likely the team is not paying attention to it one anymore.

@gentunian
Copy link

This isn't working when your field is boolean:

peek 2018-07-10 14-35

extension version: 0.28.0 (July 3rd, 2018)

@fbricon
Copy link
Collaborator

fbricon commented Jul 10, 2018

@gentunian for booleans, the convention is to have an is prefix instead of get

jul-10-2018 16-45-31

@gentunian
Copy link

@fbricon you're right! my bad :)

@arambekverdyan
Copy link

arambekverdyan commented Oct 17, 2018

And would be nice to have generators not only for getters and setters, but also for constructors, toString, hashCode, equals and overrides

There is a working extension which generates getters, setters, equals, and hashcode. Java Code Generator

@fbricon
Copy link
Collaborator

fbricon commented Dec 12, 2018

Starting in vscode-java 0.36.0, and thanks to @testforstephen's efforts, you'll be able to bulk generate accessors:
bulk_gen_accessors

@lindXdeep
Copy link

lindXdeep commented Dec 19, 2020

For now, I put this code under java.json (File > Preferences > User Snippets > Java):

"Getter/Setter": {
	"prefix": "getset",
	"body": [
		"public ${1:int} get${2:Attribute}() {",
		"\treturn this.${3:attribute};",
		"}",
		"public void set${2:Attribute}(${1:int} ${3:attribute}) {",
		"\tthis.${3:attribute} = ${3:attribute};",
		"}"
	],
	"description": "Generate getter/setter for class attributes"
}

Write "getset" and VSCode offers the snippet, then use Tab to navigate on the placeholders.

super thanks!)))

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

No branches or pull requests