Documentation on Eclipse Code Formatter Xml
Asked Answered
A

2

6

I'm looking to find a good source of documentation on the different parameters in the eclipse code formatter. I've found some good examples of specific parameters on stack overflow but can't find any comprehensive parameter list or a list of different spacing options. For example one setting in the Google formatter file is

<setting id="org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter" value="1040"/>

I've seen values for the alignment of various thing of 16, 48, 80, 81, 1040, and 1585 yet can't seem to find any concrete examples what each of these tries to do. I know 16 is attempting to put everything on one line and 80 does the same but if a line break happens it moves all parameters to their own line.

Any help here would be appreciated.

Albertype answered 11/6, 2021 at 18:26 Comment(0)
S
2

Currently, vscode-java use Eclipse Formatter style like Google Formatter that you mentioned.

Despite the setting you already know to assign specific value for parameter alignment. There's another setting to control if parameters are wrapped joined in one line or kept in different lines:

<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1" />
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>

Detailed information please view Java formatting: Keep lines but fix indentation.

You may try changing the google_style.xml on your machine to find what you want.

Sowell answered 16/6, 2021 at 2:38 Comment(0)
E
1

I ran into this as well. Unfortunately, there isn't a comprehensive resource that says what all of the XML settings do.

I suggest skimming through the eclipse codebase to try to understand more about specific settings. Some files that helped me a lot:

  • DefaultCodeFormatterConstants.java has the actual text name of the XML settings. If you search the end of the setting name (e.g. alignment_for_annotations_on_parameter), this is the file you'll find it in. All of the variables will be used elsewhere in the code instead of the setting XML name.
  • DefaultCodeFormatterOptions.java is the actual object that gets passed around. Specifically, the Alignment class describes the values of the alignment_for_* settings; they're bit flags stored as integers. So as you mentioned, 80 keeps everything on one line unless there's a line break, then it puts each param on it's own line. 80 = 64 + 16, which is the M_NEXT_PER_LINE_SPLIT constant.

With those two files, searching the code in the formatter folder, and some experimentation (changing the values and seeing how it formats your code), you should be able to get some answers. Ideally, you could directly map those XML settings to their explanations in the eclipse UI, but I haven't been able to do that.

For the Google formatter file specifically, it seems that a lot of the options don't have any effect. Some settings seem to have been deprecated or have changed names, and others, like *.count_dependents, never existed in the eclipse formatter. Google attempted to merge some improvements upstream but they never made it in, so that file has a lot of settings that don't do anything in eclipse now.

Egis answered 13/2 at 0:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.