我无法找到 Eclipse 代码格式化程序的这些换行规则:
- 不以“throws”开始新行(因为很容易被误认为“throw”)
- 不以点开始新行(例如,当方法链接时)
我错过了这些还是它们不存在?以下是标准格式化程序生成的一些示例以及我希望得到的结果:
方法定义:在 throws 前面用右括号换行
标准:
String someMethodWithARatherLongName(String someParameter)
throws Exception;
期望:
String someMethodWithARatherLongName(String someParameter
) throws Exception;
方法链接:换行
标准:
return new StringBuilder("Hello ").append(name)
.append(", how are you today?").toString();
期望:
return new StringBuilder("Hello ").append(name).append(
", how are you today?").toString();
或者:
return new StringBuilder("Hello ").append(name
).append(", how are you today?").toString();
任何有关这些设置的具体帮助将不胜感激!
最佳答案
Not starting new lines with "throws" (since easily mistaken for "throw")
您可以通过换行 -> 方法声明 ->“抛出”子句
来实现此目的。将行换行策略更改为不换行,并且 throws 子句将与方法声明位于同一行。您也可以对构造函数声明执行此操作。
Not starting new lines with dots (e.g. when method chaining)
这在 Eclipse 中似乎是不可能的,但我也很欣赏这样的设置。
关于java - Eclipse 代码格式化程序缺少规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24085496/