javavisual-studio-codeeclipse-formatter

Vscode eclipse formatter setting to align method parameters


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
    }

Solution

  • 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