I
I
Igor2018-11-09 11:08:29
IntelliJ IDEA
Igor, 2018-11-09 11:08:29

How to format code according to my criteria in IntelliJ IDEA?

Let's say we have this code:

static class Request {
    private final String data;

    public Request(String requestData) {
        this.data = requestData;
    }

    public String getData() {
        return data;
    }
}

I would like to be able to quickly shorten similar code to this with a hotkey:
static class Request {
    private final String data;
    public Request(String requestData) { this.data = requestData; }
    public String getData() { return data; }
}

How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pushkarev, 2018-11-09
@AXP-dev

Almost everything can be edited in these tabs (in this case, I have php, you will have java):
5be54b9fd3ece310877017.png

E
Egor, 2018-11-09
@RATlius

You don't need to change anything. These features already exist. In your case it is:
Ctrl + "+" - expand the method;
Ctrl + "-" - collapse the method;
You'd be better off following the suggested pattern, because if you refactor all code to be shortened like this, then even large methods that consist of more than one line will be formatted as above, resulting in confusion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question