Groovy code format - how to format closure

Hello,

I was trying to figure how to configure the format tool for Groovy in order to have pretty looking chained closures.

Unfotunatelly I can't manage to get what I want.

Do you know how can I achieve the following (or something close to it):

Expected:


void sample() {
    List<String> list = [/*init data here*/]
    list.grep {
      String s ->
        s.size() > 3 && s.size() < 6     
    }
    .each {
      String s ->
        s.reverse()
    }
}

But once format called I have that:

void sample() {
    List<String> list = [/*init data here*/]
    list.grep {
      String s ->
      s.size() > 3 && s.size() < 6
    }
      .each {
      String s ->
      s.reverse()
    }
}



Problem 1) I would like to have some indent after the closure parameters (this is a minor problem)
Problem 2) The second closure is drawn in the middle of the code, so I would like to have the call de-indented. And the closure code should be indented as any other code block instead of being aligned on the call itself.

Do you know any good format config to avoid such messy looking code ?

Thanks.
3 comments
Comment actions Permalink

Hi Guillaume,

Cool idea, I've created an issue IDEA-93149 for closure formatting and an issue IDEA-93150 for method call chain formatting.

Max

0
Comment actions Permalink

Thanks for creating the Jiras. I was checking them and noticed than it has been already done !

Thanks a lot Jetbrains !

0
Comment actions Permalink

Yes, you will be able to check formatting in the next EAP Leda build http://eap.jetbrains.com/idea

0

Please sign in to leave a comment.