简体   繁体   中英

IDEA intellij how to stop constants reformatting?

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 enabled在此处输入图片说明 :

Please advice how to avoid this

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

代码格式化

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM