@wjans的答案对于普通枚举效果很好,但不适用于带有参数的枚举。为了进一步扩展他的答案,以下是在Eclipse Juno中为我提供最明智的格式的设置:
Window
>Preferences
>Java
>Code Style
>Formatter
- 请点击
Edit
- 选择
Line Wrapping
标签 - 选择
enum
声明树节点 - 设置
Line wrapping policy
为Wrap all elements, every element on a new line (...)
,现在它在括号中表示3之3。 - 取消选中,
Force split, even if line shorter than maximum line width (...)
这样它现在在括号中显示3之3。 - 选择
Constants
树节点 - 检查一下
Force split, even if line shorter than maximum line width
这会将枚举treenode的3个子节点设置为相同的包装策略和相同的强制拆分策略(除了
Constantstreenode之外),因此带有参数的枚举将在各自的行上设置格式。仅当参数超过最大行宽时,它们才会换行。
例子:
@wjans
enum Example { CANCELLED, RUNNING, WAITING, FINISHED}enum Example { GREEN( 0, 255, 0), RED( 255, 0, 0)}上述解决方案:
enum Example { CANCELLED, RUNNING, WAITING, FINISHED}enum Example { GREEN(0, 255, 0), RED(255, 0, 0)}


