mfussenegger / nvim-jdtls

Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
GNU General Public License v3.0
979 stars 62 forks source link

How to generate getters/setters using nvim-jdtls #626

Closed zicohip closed 4 months ago

zicohip commented 4 months ago

Problem Statement

my code

package org.example;

public class Department {
    private long id;
    private String name;

}

i want to make like this code

package org.example;

public class Department {
    private long id;
    private String name;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Ideas or possible solutions

No response

mfussenegger commented 4 months ago

Call vim.lsp.buf.code_action() and choose "Generate Getters and Setters". You can also mark the fields in visual mode and call code action then, to only create them for a subset of fields.

Also: Use java records and don't make stuff mutable if it doesn't need to be. record Department(long id, String name).