更改 Eclipse 格式化程序包装长字符串的方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11289076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 18:26:54  来源:igfitidea点击:

Change how eclipse formatter wraps long strings

javaeclipseformatter

提问by Mathias ?hsberg

I have set the eclipse java formatter to wrap lines that exceed 120 characters to conform to our team's coding standard. However, when I have a long string that is wrapped I want the plus sign (+) to appear as the last character on the first line e.g.

我已将 eclipse java 格式化程序设置为对超过 120 个字符的行进行换行,以符合我们团队的编码标准。但是,当我有一个长字符串被包裹时,我希望加号 (+) 显示为第一行的最后一个字符,例如

String s = "Very long line that should be " +
"wrapped across several rows"; 

The default behaviour is that the plus sign is placed on its own line e.g.

默认行为是加号放在它自己的行上,例如

String s = "Very long line that should be "
+
"wrapped across several rows";

So is it possible to specify where the plus sign should appear in the eclipse java formatter?

那么是否可以指定加号应该出现在eclipse java格式化程序中的位置?

回答by Deepak Azad

Preferences > Java > Code Style > Formatter > Line Wrapping > Binary Expressions > Wrap before Operator

The above controls where + is placed. (Though it should never be on a its own line)

以上控件 + 的位置。(虽然它永远不应该在自己的线上)