我有一些Java代码,其中的SQL语句被写成Java字符串(请不要使用OR/M Flamewars,嵌入式SQL就是它-不是我的决定).
为了便于维护,我在几行代码中将SQL语句在语义上分解为几个串联字符串.因此,与其说:
String query = "SELECT FOO, BAR, BAZ FROM ABC WHERE BAR > 4";
我有点像:
String query =
"SELECT FOO, BAR, BAZ" +
" FROM ABC " +
" WHERE BAR > 4 ";
这种样式使SQL更易于阅读和维护(IMHO),尤其是对于更大的查询.例如,我可以将编辑器置于"覆盖"模式,并相当轻松地修改文本.
Note that this issue generalizes beyond the particular example of SQL. Any code that is written with any vertical formatting, particularly tabular constructs, is susceptible to destruction by a pretty printer.个
现在,一些项目成员使用Eclipse编辑器,当他们格式化整个源文件时,语义格式通常会被 destruct .
Is there a way to instruct Eclipse to ignore certain lines of source with respect to formatting?
我正在寻找一个类似于切换Eclipse格式化程序的特殊注释的东西.理想情况下,这样的 comments 可以配置为我们 Select 的任何内容,其他格式化程序也可以编程为尊重它:
// STOP-ECLIPSE-FORMATTING
String query =
"SELECT FOO, BAR, BAZ" +
" FROM ABC " +
" WHERE BAR > 4 ";
// START-ECLIPSE-FORMATTING
显然,一种"解决方案"是让我们的团队成员标准化一些外部格式化程序,比如Jalopy或JIndent,但这不是这个问题的主题(而且,这也不是我在这个项目上的决定):我专门在特别的基础上寻找一种方法来避免Eclipse格式化程序.
Ideally, a solution will allow me to insert instructions for the Eclipse formatter without requiring team members using Eclipse to do any IDE reconfiguration (other than possibly choosing a formatter agnostic command comment: STOP-ECLIPSE-FORMATTING
→ STOP-FORMATTING
).