Java 如何修改 Eclipse 代码格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1601793/
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
How do I modify Eclipse code formatting?
提问by skiphoppy
When I reformat code with Eclipse, it turns method headers like this:
当我用 Eclipse 重新格式化代码时,它会变成这样的方法头:
public void myMethod(String param) {
into method headers like this:
进入这样的方法标题:
public void myMethod(
String param) {
When I was brought on here I'd never used Eclipse before, and I imported project settings provided by someone else. I have seen that on small new projects I've worked on Eclipse does not do this, so it must be in the settings I've imported. But I've gone through every panel I can find, as well as every hidden file I can find in the workspace, and I can't figure out what is causing this.
当我被带到这里时,我以前从未使用过 Eclipse,我导入了其他人提供的项目设置。我已经看到我在 Eclipse 上工作的小型新项目没有这样做,所以它必须在我导入的设置中。但是我已经浏览了我能找到的每个面板,以及我能在工作区中找到的每个隐藏文件,但我无法弄清楚是什么导致了这种情况。
How do I turn it off? I don't want a newline before parameters in my method signatures, and I can't imagine why anyone would!
我该如何关闭它?我不希望我的方法签名中的参数前有换行符,我无法想象为什么有人会!
采纳答案by tangens
Have a look at Window>Preferences>Java>Code Style>Formatter.
看看Window> Preferences> Java> Code Style> Formatter。
There you can configure almost everything. Your case is found at
在那里您几乎可以配置所有内容。您的案例位于
Line Wrapping>Method Declarations>Parameters.
Line Wrapping> Method Declarations> Parameters。
回答by MarkPowell
Go into preferences: Java-> Code Style-> Formatter
进入首选项:Java-> Code Style->Formatter
Restore Defaults or edit what's there.
恢复默认值或编辑那里的内容。
Additionally, Code Style-> Code Templateswill allow you to define generate code formatting.
此外,Code Style->Code Templates将允许您定义生成代码格式。
Note that this is for Eclipse Workspace as a whole, the same Preferencescan be accessed under the project preferences if you want to get more fine grained at a per project level.
请注意,这是针对 Eclipse Workspace 整体而言的,Preferences如果您想在每个项目级别获得更精细的粒度,可以在项目首选项下访问相同的内容。
回答by Colin Gislason
In my version of Eclipse, I found the option under Window->Preferences->Java->Code Style->Formatter, then clicked the Edit..button.
在我的 Eclipse 版本中,我找到了Window-> Preferences-> Java-> Code Style->下的选项Formatter,然后单击了Edit..按钮。
In the new window, go to the Line Wrappingtab and find Method Declarations. You want to change the Line wrapping policy. The Force splitcheck box seems to do the same.
在新窗口中,转到Line Wrapping选项卡并找到Method Declarations。你想改变Line wrapping policy. 该Force split复选框,似乎这样做。
回答by Imran khan
In eclipse you can define your code formatting use Code Style,
在 Eclipse 中,您可以定义代码格式使用Code Style,
for MAC System :--> Eclipse--> Preference-- > java--> code Style
对于 MAC 系统:--> Eclipse--> Preference--> java-->code Style
for Window System :--> Window->Preferences->Java->Code Style->Formatter
对于窗口系统:--> Window-> Preferences-> Java-> Code Style->Formatter