user4118620
user4118620

Reputation:

How to stop flattening of fluent APIs in IntelliJ

I'm using IntelliJ IDEA 13.1.5 to write Java code that uses fluent APIs and I noticed that when I close a block around a "fluent" portion of code then IDEA automatically flattens the "fluent" code into a single line.

For example, if I have this method:

public int sendMessage(Message message) {
  Response response = JerseyClientHelper.target(serverUrl)
            .header("User-Agent", userAgent)
            .post(Entity.entity(message));
  return response.getStatus();
}

and I try to wrap it in a new 'if' block, then I would type the if condition and open the block:

public int sendMessage(Message message) {
  if (message != null) {
    Response response = JerseyClientHelper.target(serverUrl)
              .header("User-Agent", userAgent)
              .post(Entity.entity(message));
    return response.getStatus();
    // Didn't type the '}' to close the block yet
}

but as soon as I type the } to close the block, IntelliJ flattens the code into a single line:

public int sendMessage(Message message) {
  if (message != null) {
    Response response = JerseyClientHelper.target(serverUrl).header("User-Agent", userAgent).post(Entity.entity(message));
    return response.getStatus();
  }
}

Is there a way to disable the automatic flattening of fluent APIs? I've looked in the "Code Style -> Java" and "Code Style -> General" sections but couldn't find anything that would be specifically related to this.

Upvotes: 13

Views: 3532

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47290

settings > code style > java > wrapping and braces > chained method calls

(in version 14)

it looks like this

myInstance.call()
          .again()
          .eclipseIsRubbish(true)
          .cestfin();

Upvotes: 22

Related Questions