java - 将行与左括号和右括号对齐

标签 java eclipse code-formatting eclipse-formatter

问题

我希望带有结束大括号/方括号/圆括号的行<具有完全相同的缩进/strong> 与匹配的开口大括号/方括号/圆括号。

经过一些搜索,我猜我的需求很特殊,但也许我只是遗漏了一些东西。是否可以将 Eclipse 自动格式化程序配置为以这种方式运行? (我花了几个小时来切换复选框,但到目前为止还不能让它以这种方式运行。)

例子

换句话说,我将 Eclipse 格式化为:

public String concatenate(String a,
        String b) {
    ...
}

这样:

public String concatenate(
    String a, String b
) {
    ...
}

// The same, but with some extra comments:

public String concatenate( // the line with "(" has no indent
    String a, String b
) { // so, the line with the matching ")" also should not
    ...
} // same goes for {} and []

最佳答案

看起来您应该能够在 Eclipse Neon Milestone 7 版本 (4.6M7) 中执行此操作,该版本添加了代码格式化程序(请参阅 What's New and Noteworthy 中的“代码格式化程序的新选项”部分了解该版本).

注意:里程碑版本是 Eclipse 版本的早期版本,可能不如最终版本稳定(Eclipse Neon 将于 2016 年 6 月发布)。

关于java - 将行与左括号和右括号对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36963330/

相关文章:

git - 如何在多分支项目中格式化代码?

java - 如何记录 Glide 的每个请求 url?

Eclipse RCP : programmatically associate file type with Editor?

ms-word - 在 word 2007 中粘贴源代码

eclipse - eclipse 调试hadoop wordcount,并发生异常

java - Eclipse 中的项目文件组织

java - 代码格式化程序 : cleaning up horribly formatted jsp code

java - App 在 Android 4.0 上崩溃,但在 2.3 上不崩溃——奇怪的异常

java - 使用 HornetQ 强制消息顺序

java - 如何在 log4j2 中动态打开或关闭 rootLogger 的一个附加程序?