Eclipse 代码格式化插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5473905/
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 16:04:15  来源:igfitidea点击:

Eclipse Code Formatter Plugin

eclipsepluginsformatter

提问by Pit Digger

Can some one suggest me a plugin to format HTML and JAVA code with proper indents etc ? Is there any built in option there in Eclipse ?

有人可以建议我使用适当的缩进等格式设置 HTML 和 JAVA 代码的插件吗?Eclipse 中是否有任何内置选项?

回答by atamanroman

Use Source -> Format or CTRL+SHIFT+F

使用 Source -> Format 或 CTRL+SHIFT+F

回答by Isaac Truett

Eclipse does have built in Java formatting:

Eclipse 确实内置了 Java 格式:

Preferences > Java > Code Style > Formatter

Preferences > Java > Code Style > Formatter

For HTML, you might try something like HTML Tidy. The Web Tools Platformproject also includes formatting.

对于 HTML,您可以尝试使用HTML Tidy 之类的东西。在Web工具平台项目还包括格式化。

回答by Ashok Goli

It's a combination of all the answers above, which suits me-

这是以上所有答案的组合,适合我-

  1. Go to Preferences > Java > Code Style > Formatterand set all the options you want by creating your own profile or using a default one. Personally I find the line-wrap limited to 80 a little too low. I set it to 200.
  2. Save the 'custom' preferences by giving it a new profile name (export it for future restoration)
  3. Select the code in your editor - then hit CTRL+SHIFT+F. That should format your code.
  1. Preferences > Java > Code Style > Formatter通过创建自己的配置文件或使用默认配置文件,转到并设置所需的所有选项。我个人认为 line-wrap 限制为 80 有点太低了。我设置为200。
  2. 通过给它一个新的配置文件名称来保存“自定义”首选项(将其导出以备将来恢复)
  3. 在编辑器中选择代码 - 然后点击CTRL+SHIFT+F。那应该格式化您的代码。

Worked wonders for me everytime.

每次都为我创造奇迹。

回答by Instantsoup

Java code formatting is built in. Go to Window->Preferences->Java->Code Style->Formatter. There's a built in profile set up and you can make your own.

Java 代码格式化是内置的。转到Window->Preferences->Java->Code Style->Formatter。有一个内置的配置文件设置,您可以创建自己的配置文件。

回答by Ravindranath Akila

http://sourceforge.net/projects/jalopy/

http://sourceforge.net/projects/jalopy/

Note that Jalopy has its settings under Window> Jalopy Preferences.

请注意,Jalopy 在 Window> Jalopy Preferences 下有其设置。

(This menu option appears only when all editor tabs are closed)

(此菜单选项仅在所有编辑器选项卡关闭时出现)

Eclipse doesn't have properbuilt-in code formatting. You might want to open your project in Idea IntelliJ or Netbeans and use their formatting to do a thorough job on it.

Eclipse 没有正确的内置代码格式。您可能希望在 Idea IntelliJ 或 Netbeans 中打开您的项目,并使用它们的格式对其进行彻底的处理。