Parameters indentation (on new line)

Answered

Is there a way to format function parameters to a new line but without indentation, or with a classic indentation ?

I found the same question in this SO post: https://stackoverflow.com/questions/39396319/is-there-a-way-to-get-intellij-to-back-indent-method-declaration-parameters
But the answer is not clear.

If we need to import a checkstyle config, where can I find a config which do such a thing ?
Thx

0
8 comments

You can try importing google_checks.xml from the CheckStyle distribution.

Can you share the source file which gets formatted incorrectly with this configuration?

0

Google_checks.xml does not do what I would like.

Currently :

public ResponseEntity<List<AuditEvent>> getAll(@RequestParam MultiValueMap<String, String> queryParams, UriComponentsBuilder uriBuilder, Pageable pageable) {

What I would like :

public ResponseEntity<List<AuditEvent>> getAll(
@RequestParam MultiValueMap<String, String> queryParams,
UriComponentsBuilder uriBuilder,
Pageable pageable) {
Page<AuditEvent> page = auditEventService.findAll(pageable);

Note the indentation, it is one more than the code inside the function to avoid confusion.

But in fact, the needs can be extended to many other similar use-cases :

Currently :

return new AuditEvent(persistentAuditEvent.getAuditEventDate(), persistentAuditEvent.getPrincipal(),
persistentAuditEvent.getAuditEventType(), convertDataToObjects(persistentAuditEvent.getData()));

What I would like :

return new AuditEvent(
persistentAuditEvent.getAuditEventDate(),
persistentAuditEvent.getPrincipal(),
persistentAuditEvent.getAuditEventType(),
convertDataToObjects(persistentAuditEvent.getData()));
0

The following formatting looks like what you describe:

3

Yes indeed, but there is no parameters indentation so the code in the function is aligned with parameters, is there a way to add an indentation for parameters ?

0

> so the code in the function is aligned with parameters

It's not.

Code style.

Result:

0

Thanks !
I think you would want to say "It is" ! Because your config do exactly what I would like :)

To resume :
 - Method and declaration parameters > new line after '('
 - Tabs and indent > continuation indent (should be the double of indent)

0

Glad that you've figured it. My comment was a reply to yours "so the code in the function is aligned with parameters". Sorry for the confusion.

0

I think it's achieved through the indentation parameters in the first tab. In my case I have:

In the XML file:

<indentOptions>
      <option name="INDENT_SIZE" value="4" />
      <option name="CONTINUATION_INDENT_SIZE" value="8" />
      <option name="TAB_SIZE" value="4" />
    </indentOptions>

Code snippet:

    public void foo1(int i1, int i2,
            int i3, int i4, int i5,
            int i6, int i7) {
    }

    public static void longerMethod()
            throws Exception1,
                   Exception2,
                   Exception3 {
        // todo something
        int
                i = 0;
        int[] a = new int[]{1, 2,
                0x0052, 0x0053,
                0x0054};
        int[] empty = new int[]{};
        int var1 = 1;
        int var2 = 2;
//...
0

Please sign in to leave a comment.