Chr*_*way 38 java eclipse code-formatting
对于一系列合格调用的Eclipse格式化规则(即Builder模式样式),我非常沮丧.例如,以下是我创建新的Apache Commons CLI Options对象的一些代码的首选格式:
Options options = new Options()
.addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit")
.addOption(OptionBuilder.withLongOpt(OPTION_PROPERTIES)
.hasArg()
.withArgName("FILE")
.withType(File.class)
.withDescription("specify a user properties file")
.create());
Run Code Online (Sandbox Code Playgroud)
即,参数在必要时被包装和缩进,除非必要,所有合格的调用都被包装并缩进(如果有多个).如果参数列表包含在限定调用内,则调用应首先包装.
Eclipse中的默认格式(参数和调用"仅在必要时换行")会产生以下混乱:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit").addOption(
OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName(
"FILE").withType(File.class).withDescription(
"specify a user properties file").create());
Run Code Online (Sandbox Code Playgroud)
进入"Java代码样式 - >格式化程序 - >行换行"和换行设置为"包装所有元素,除了第一个元素,如果没有必要",调用产生:
Options options = new Options().addOption(
OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false,
"print version and exit")
.addOption(
OptionBuilder.withLongOpt(OPTION_PROPERTIES).hasArg().withArgName(
"FILE").withType(File.class).withDescription(
"specify a user properties file").create());
Run Code Online (Sandbox Code Playgroud)
我不喜欢OptionBuilder表达式没有被包装,或者"FILE"包裹而没有包装withArgName.
将缩进更改为"在列上缩进"会产生:
Options options = new Options().addOption(OPTION_HELP_SHORT, OPTION_HELP,
false, "print usage information")
.addOption(OPTION_VERSION_SHORT,
OPTION_VERSION, false,
"print version and exit")
.addOption(
OptionBuilder.withLongOpt(
OPTION_PROPERTIES)
.hasArg()
.withArgName("FILE")
.withType(File.class)
.withDescription(
"specify a user properties file")
.create());
Run Code Online (Sandbox Code Playgroud)
这打破了我更喜欢的界限,但把事情推到了太远的地方.
有没有办法说服Eclipse应用我喜欢的格式样式或更接近它的东西比上述任何一种?
Tho*_*sen 32
使用评论:
Object o = foo() //
.bar() //
.toString();
Run Code Online (Sandbox Code Playgroud)
Mak*_*lev 10
2021 年更新。可以更改,导航到:代码样式 -> 格式化程序 -> 换行 -> 换行设置 -> 函数调用 -> 限定调用,并将值更改为“如果不需要,则换行除第一个元素之外的所有元素”
| 归档时间: |
|
| 查看次数: |
8358 次 |
| 最近记录: |