Vscode eclipse formatter setting to align method parameters

1.2k Views Asked by At

Which eclipse-formatter setting in vscode will accomplish the following formatting, focusing specifically on the parameter alignment?

Current

    public ResponseEntity retrieveAgreement(final String one, final Long someId,
            final Long anotherId, final Long otherPAram) {
        // Omitted
    }

Desired

    public ResponseEntity retrieveAgreement(final String one, 
                                            final Long someId,
                                            final Long anotherId, 
                                            final Long otherParam) {
        // Omitted
    }
2

There are 2 best solutions below

2
On BEST ANSWER

About Java Formatting, you can refer to Formatting and Linting.

Download GoogleStyle.xml and edit the following settings:

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

Then in vscode settings.json, set

"java.format.settings.url": "<local path to java-google-style.xml>",

You can keep the formatting style that you want instead of parameters being formatted to one line: enter image description here

0
On

This setting helped achieve the desired alignment format.

<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="18"/>

<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>

<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/>

<setting id="org.eclipse.jdt.core.formatter.alignment_for_record_components" value="18"/>

This is taken after changing up the settings in an Eclipse IDE. enter image description here