Google java format in IntelliJ IDEA

4.4k Views Asked by At

I am using the Google-java-formatter in IntelliJ IDEA. I tried all the option present under setting > editor > code Style > java but not able to change this behavior.

private void insertOfflinePreferences(String loginId, String clientId, List<AlertPrefsNgBO> alertPrefsNgBOS) {

List<SubscriptionAlertEntity> subscriptionAlertEntities = subscriptionAlertRepository.getSubscriptionAlertEntities(login);

This line is getting formatted as

private void insertOfflinePreferences(
  String loginId, String clientId, List<AlertPrefsNgBO> alertPrefsNgBOS) {


List<SubscriptionAlertEntity> subscriptionAlertEntities =
          subscriptionAlertRepository.getSubscriptionAlertEntities(login);

I don't want the line change. It is doing same for the stream operations in java.

2

There are 2 best solutions below

2
On

If I understand well, you want the IntelliJ to stop wrapping your lines ?

For that you can set the Hard Wrap field to a higher value. The default is 120, which means that every line of more than 120 characters will be wrapped.

You can find this parameter in Settings>Editor>Code Style (And not in Settings>Editor>Code Style>Java)

0
On

Quoting the github page:

Note: There is no configurability as to the formatter's algorithm for formatting. This is a deliberate design decision to unify our code formatting on a single format.

Either use google-java-formatter, or don't. (I simply stopped caring about GJF's choices years ago, because I'm used to it; and even in cases where it doesn't format it exactly how I'd like, the formatting is not totally disagreeable).