我有一个checkstyle active,它会抱怨一行是否长于100列,并且我已将intelliJ配置设置为以100列为硬包装。
问题在于它并不总是强制执行此操作,从而导致checkstyle失败的情况,并且唯一的解决方法是在IDE中禁用格式设置并手动执行格式设置。
所以这是失败的简短示例(愚蠢)
class TestClass {
public static void main(String[] args) {
String superString = "s";
String bestString = "b";
Arrays.asList(superString.split(""))
.stream()
.map(superiorString -> Arrays.asList(bestString.split(""))
.stream()
.map(otherSub -> Arrays.asList(superiorString.split(""))
.stream()
.map(qwerty -> Arrays.asList(
otherSub.split(""))
.stream()
.map(dvorak -> null))));
}
}
这是我的智能配置:
<code_scheme name="stream-manager" version="173">
<option name="LINE_SEPARATOR" value="
" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="RIGHT_MARGIN" value="100" />
<option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" />
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
</JavaCodeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="RIGHT_MARGIN" value="100" />
<option name="KEEP_LINE_BREAKS" value="false" />
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BETWEEN_PACKAGE_DECLARATION_AND_HEADER" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
<option name="SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_WRAP" value="1" />
<option name="RESOURCE_LIST_WRAP" value="5" />
<option name="EXTENDS_LIST_WRAP" value="1" />
<option name="THROWS_LIST_WRAP" value="1" />
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="TERNARY_OPERATION_WRAP" value="5" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" />
<option name="WRAP_LONG_LINES" value="true" />
<option name="SOFT_MARGINS" value="80,120" />
</codeStyleSettings>
</code_scheme>
我只是缺少某些设置吗,或者这仅仅是格式化程序中的缺陷? 周围有什么办法吗?
答案 0 :(得分:1)
从Preferences > Editor > Code Style > Java
中选择Wrapping and Braces
标签,然后滚动到Chained method calls
,然后:
Wrap always
Wrap first call
选项Align when multiline
选项使用该配置,您的代码将采用以下格式:
public static void main(String[] args) {
String superString = "s";
String bestString = "b";
Arrays
.asList(superString.split(""))
.stream()
.map(superiorString -> Arrays
.asList(bestString.split(""))
.stream()
.map(otherSub -> Arrays
.asList(superiorString.split(""))
.stream()
.map(qwerty -> Arrays
.asList(
otherSub.split(""))
.stream()
.map(dvorak -> null))));
}
最宽处为68个字符。