`return` being merged with previous line

已回答

My code looks like this:

public List<NifiProcessorDto> getAll() {
List<NifiProcessor> nifiProcessorList = nifiProcessorService.getAll();
if (nifiProcessorList.isEmpty()) {
return NO_SERVICE_TYPES;
}
return nifiProcessorMapper.toNifiProcessorDtoList(nifiProcessorList);
}

After formatting the individual file, I get the following:

public List<NifiProcessorDto> getAll() {
List<NifiProcessor> nifiProcessorList = nifiProcessorService.getAll();
if (nifiProcessorList.isEmpty()) {
return NO_SERVICE_TYPES;
} return nifiProcessorMapper.toNifiProcessorDtoList(nifiProcessorList);
}

Note that the `return` statement was joined with the previous line.

However, if I format the entire directory, the `return` statement returns to the next line.

What setting is causing this to happen? I tried adding this method to the Code Style code sample and tweaking each setting, but I still can't find the offending setting, not do I understand why it behaves differently when formatting a single file vs formatting a directory.

0

Looks like a bug. Could you please share a small sample project to reproduce it with your code style saved in the project? You can zip and upload the project directory at https://uploads.services.jetbrains.com/ and specify the file name here. Thanks!

0

Serge, thanks for looking into this.

The file name is 

format-problem.zip

Also, I shortened a few object names and got another weirdness. Now an if statement was pulled up to the same line as a variable assignment!

List<Object> list = service.getAll(); if (list.isEmpty()) {
return NO_SERVICE_TYPES;
} return ...

Pretty funny! It's possible that I managed to create style settings that are nonsensical... :)
Please let me know if I can help further.

Also, are you able to tell me if this is a problem only with 2020.1.1? If it is, maybe I can downgrade (although I'd rather not, if possible!)

Thanks!

0

I found the problem!

It was the setting "Multiple expressions in one line".

Unfortunately, it's one that does not have an accompanying sample code effect, so you can't visualize the change.

0

This behavior is caused by the Multiple expressions in one line checkbox enabled in your code style settings, try to disable it:

1

It's a weird setting. If feels too "strong".

But also, why does it only apply to the individual file and not when formatting the entire file tree?

0

It applies to the entire tree as well. I've reformatted the project and got exactly the same results.

0

请先登录再写评论。