4

Eclipse 允许您自定义代码格式化程序并导出/导入它们。有没有办法让我创建一个格式化程序,将其保存在源代码管理中,并在某处设置一个属性,以便在您打开项目时自动将其加载到 eclipse 中?

我们想使用自定义格式化程序,但如果它不能通过团队自动配置,则不会。我们不希望有人忘记导入格式化程序并最终使用另一个设置格式化代码。只能想象这会在未来产生一些不那么有趣的冲突。

4

2 回答 2

3

右键单击项目,选择“属性”,然后选择“Java -> 格式化程序”,选中“启用项目特定设置”,然后根据需要配置格式化程序。然后整个配置将保存在项目目录中,您可以轻松地将其置于版本控制之下。

于 2014-01-24T20:03:17.970 回答
2

As meriton said, you can modify the default formatter used, and it will be saved to your project directory. Specifically the .settings folder to two different files: one file called org.eclipse.jdt.core.prefs that stores the specific formatter instructions, and another "pointer" file called org.eclipse.jdt.ui.prefs that "points" to your modified code formatter.

org.eclipse.jdt.core.prefs looks like:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
(etc)

org.eclipse.jdt.ui.prefs looks like:

eclipse.preferences.version=1
formatter_profile=_Eclipse [modified]
formatter_settings_version=12

Note: I named my modified formatter "modified" (it seemed appropriate). I'm using Kepler, so your mileage may vary, void where prohibited, see dealer for details...

Make sure to save the .settings folder, and these two files to your SCM system (along with your .project file, which will be in the root folder).

Have fun!

于 2014-01-24T20:27:37.013 回答