简体   繁体   English

使用Java Eclipse代码格式化程序对if()中的条件进行缩进

[英]Indentation of conditions in if() using Eclipse Code Formatter for Java

I would like to set code style in Eclipse Formatter that will align (indent) conditions in if instruction to the same column (in case of conditions in different lines). 我想在Eclipse Formatter中设置代码样式,该样式会将if指令中的条件对齐(缩进)到同一列(如果条件在不同的行中)。

This is the example of what I would like to achieve: 这是我要实现的示例:

if (very_awesome_variable == quite_awesome_value_1 ||
    very_awesome_variable == quite_awesome_value_2 ||
    very_awesome_variable == quite_awesome_value_3) {
    // do something
} else if (very_awesome_variable == quite_awesome_value_4 ||
           very_awesome_variable == quite_awesome_value_5 ||
           very_awesome_variable == quite_awesome_value_6) {
    // do some other thing
}

This is what I have currently: 这是我目前拥有的:

if (very_awesome_variable == quite_awesome_value_1 ||
    very_awesome_variable == quite_awesome_value_2 ||
    very_awesome_variable == quite_awesome_value_3) {
    // do something
} else if (very_awesome_variable == quite_awesome_value_4 ||
    very_awesome_variable == quite_awesome_value_5 ||
    very_awesome_variable == quite_awesome_value_6) {
    // do some other thing
}

I honestly don't see any option for configuring indentation of such thing. 老实说,我看不到用于配置此类缩进的任何选项。

I also believe that conditions in first block are indented in my way only because I use 4 spaces indentation and if ( is exactly 4 characters long. It looks like general indentation configuration is applied here. 我还认为,仅因为我使用了4个空格缩进,并且if (正好是4个字符长,所以以我的方式缩进了第一块条件。这看起来像在这里应用了一般缩进配置。

I would be happy even if I could turn off indentation for such lines and do it manually, so auto formatter will not break this again. 即使我可以关闭此类行的缩进并手动进行操作,我也很高兴,因此自动格式化程序不会再次破坏这种情况。

Go into window - preferences java -> code style -> formatter 进入窗口-首选项Java->代码样式->格式化程序

You can then edit the indentation, simply use the search box to find "if" options 然后,您可以编辑缩进,只需使用搜索框查找“如果”选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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