Reputation: 5397
I started using Visual Studio Code with the "Java Extension Pack" for programming with Java.
Like other IDEs VS Code can generate some types of boilerplate code, like getters and setters for attributes:
The resulting code for this example looks like this:
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
I find those JavaDoc comments redundant and would like to modify the code generation mechanism so that the JavaDoc is omitted for getters and setters.
How would I do that? I couldn't find anything about it anywhere.
Upvotes: 2
Views: 2055
Reputation: 36
I faced the same problem and I solved this using thtis setting
"java.codeGeneration.generateComments": false
Upvotes: 2
Reputation: 503
not sure if you can modify existing code snippets (or ones added through plugins) but you can always create your own identical snippets, minus the JavaDoc in the menu bar, select Preferences>Snippets, in the dropdown type Java, and follow along with the example that is in the editor window that will open up. Image of snippet setting location
Edit: put this in the java.json snippet file for a custom get/set method name
"Getter and Setter": {
"prefix": "getset",
"body": [
"public String get$0() {",
"return description;",
"}",
"",
"public void set$0(String description) {",
"this.description = description;",
"}"
],
"description": "create getter and setter"
}
put this in the java.json snippet file for a getter/setter with custom method and variable names
"Getter and Setter": {
"prefix": "getset",
"body": [
"public String get$1() {",
"return $0;",
"}",
"",
"public void set$2(String $0) {",
"this.$0 = $0;",
"}"
],
"description": "create getter and setter"
}
note for this one, your cursor will start at the position of ALL the $0's so you only need to type 'description' or whathaveyou once, but you can press TAB to scroll to the position of $1 and $2 to change the getSOMETHING and setSOMETHING method names. every time you hit tab, it will jump to the next position. pressed once-> cursor at $1. pressed again -> cursor at $2. you can generate this code block by typing 'getset' in your files, or you can change what will call this by changing 'getset'. hope this helps!
Upvotes: 1