IDEA intellij how to stop constants reformatting?

Viewed 63

I have class below and I would like to avoid constants reformatting inside of it. I've tried to use formatter:off, but there is no luck

public class Test {

    // @formatter:off
    private static final String TEST_FIRST_NAME = "firstname";
    private static final String TEST_SECOND_NAME = "secondname";

    public static final Test1 TEST1 = new Test1(TEST_FIRST_NAME);
    public static final Test2 TEST2 = new Test2(TEST_SECOND_NAME);
    // @formatter:on

    @Data
    @AllArgsConstructor
    static class Test1 {

        private String name;
    }

    @Data
    @AllArgsConstructor
    static class Test2 {

        private String name;
    }
}

After reformatting constant change the order to:

   // @formatter:off
    private static final String TEST_FIRST_NAME = "firstname";
    public static final Test1 TEST1 = new Test1(TEST_FIRST_NAME);
    private static final String TEST_SECOND_NAME = "secondname";
    public static final Test2 TEST2 = new Test2(TEST_SECOND_NAME);
    // @formatter:on

Markers are enabledenter image description here:

Please advice how to avoid this

1 Answers

You have to enable this feature. Settings -> Editor -> Code Style

code formatting

Related