如何创建 Intellij 和 Eclipse 兼容的代码样式和代码格式配置(用于 Java 代码)?

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

How to create an Intellij and Eclipse compatible code style and code formatting configuration (for java code)?

eclipsecoding-stylecode-formattingintellij-idea

提问by user141634

Few weeks ago I tried Intellij and I found it really awesome. Now, at my project there are two programmers (including me) using Intellij and few other programmers who are going to keep using Eclipse. Since this project is already very large and it's going to grow a lot, we need to use compatible Code Style and Code Formatting between Intellij and Eclipse. We do not want to have problems when one user edits some file and reformats it before saving. With Eclipse "alone" we used to have some exported configuration, and before anybody starts to work, the first step is just to import this configuration. We already tried to use External Code Formatter, but it didn't work on Intellij 9.

几周前,我尝试了 Intellij,发现它真的很棒。现在,在我的项目中,有两个程序员(包括我)使用 Intellij,而其他几个程序员将​​继续使用 Eclipse。由于这个项目已经非常大,而且还会增长很多,我们需要在 Intellij 和 Eclipse 之间使用兼容的 Code Style 和 Code Formatting。当一个用户编辑某个文件并在保存之前重新格式化时,我们不希望出现问题。使用“单独”的 Eclipse,我们曾经有一些导出的配置,在任何人开始工作之前,第一步就是导入这个配置。我们已经尝试使用外部代码格式化程序,但它在 Intellij 9 上不起作用。

So, I have a bunch of questions here:

所以,我在这里有一堆问题:

  1. Is there any way to import eclipse formatting configuration on Intellij 9?
  2. Anybody could share their experience managing this kind of situation? Do you guys have any other suggestion to manage this situation?
  1. 有没有办法在 Intellij 9 上导入 eclipse 格式配置?
  2. 任何人都可以分享他们管理这种情况的经验吗?你们有什么其他建议来管理这种情况吗?

回答by Aliaksandr Autayeu

There is an updated plugin for IDEA, called Eclipse Code Formatter: http://plugins.intellij.net/plugin/?idea&id=6546

IDEA 有一个更新的插件,称为 Eclipse Code Formatter:http: //plugins.intellij.net/plugin/?idea&id= 6546

回答by Jesse Webb

I would recommend someone spends the time to configure their IntelliJ's code style to be the same as Eclipse. This will take a little time and effort but once it is done, you can export it just like in eclipse so that any other IDEA users can import it.

我建议有人花时间将他们的 IntelliJ 代码风格配置为与 Eclipse 相同。这需要一点时间和精力,但是一旦完成,您可以像在 eclipse 中一样导出它,以便任何其他 IDEA 用户可以导入它。

You could also search online to see if anyone has already done this and you can simply download the code style config and use it.

您也可以在线搜索以查看是否有人已经这样做了,您可以简单地下载代码样式配置并使用它。

The only alternative I can think of would be to find a standardized code style template that is available for both eclipse and IntelliJ, like the Recommended Sun Java Code Style.

我能想到的唯一替代方法是找到一个可用于 eclipse 和 IntelliJ 的标准化代码样式模板,例如推荐的 Sun Java 代码样式。

回答by Pascal Thivent

There seems to be a pluginfor that (emerged from this discussion).

似乎有一个插件(从这个讨论中出现)。