Custom Eclipse Default Formatter

Eclipse allows you to customize code formatting and export / import them. Is there a way to create a formatter, save it in the original control and set a property somewhere that will automatically load this in eclipse when the project opens?

We want to use a custom formatter, but not if it cannot be configured automatically through the command. We don’t want anyone to forget to import the formatter and ultimately format the code using a different setting. One could only imagine that this would create some funny conflicts in the future.

+4
source share
2 answers

Right-click the project, select "Properties", then "Java β†’ Formatter", check the box "Enable specific project settings" and configure your formatter as you want. The entire configuration will be saved in the project directory, which you can easily install under version control.

+3
source

As meriton said, you can change the default format used and it will be saved in your project directory. In particular, there is a folder .settingsfor two different files: one file with a name org.eclipse.jdt.core.prefsin which specific formatting instructions are stored, and another file "pointer" with a name org.eclipse.jdt.ui.prefsthat "points" to your changed formatting code.

org.eclipse.jdt.core.prefs as follows:

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 as follows:

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

. "" ( ). Kepler, , , , ...

.settings SCM ( .project , ).

!

+2

Source: https://habr.com/ru/post/1523596/


All Articles