Author Topic: B6: Less would be more: Reformatting of Java8 lambda expressions  (Read 2608 times)

Marcel

  • Senior Community Member
  • Posts: 261
  • Hero Points: 26
I was surrounding a method call containing a lambda expression with a try/catch block and SE proceeded to make the result 'prettier'.

Before:
Code: [Select]
public class SomeClass {
  /* .... */
  public SomeClass() {
    setup((a,b,c)->{doMagic(a, b, b);});
  }
  /* .... */
}

After:
Code: [Select]
public class SomeClass {
  /* .... */
  public SomeClass() {
    try {
      setup((a,b,c)->{
        doMagic(a, b, b);
      });
    } catch () {
    }
  }
  /* .... */
}

You get a similar effect by entering 'try ' with auto-completion.
I realize that SE is beautifying this by the book, but I think the result is not quite as readable. Could you add some beautifier option to leave the expression alone if it is contained on a single line and just align it like a simple function argument.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: B6: Less would be more: Reformatting of Java8 lambda expressions
« Reply #1 on: October 29, 2014, 01:04:53 PM »
Hmm.  Technically, "Allow one line code blocks" under Newlines -> Statement Blocks should cover this case, but does not.  So I'm going to treat this as a bug.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: B6: Less would be more: Reformatting of Java8 lambda expressions
« Reply #2 on: October 30, 2014, 04:26:48 PM »
Actually, turning off on Newlines -> Statement Blocks -> "Allow one line code blocks" keeps the lambda on one line for me.  Does that not work for your configuration, or do you want a separate setting for that?

Addition: I did find a parsing problem for Java 8 lambdas that I'm going to fix that could possibly mess it up anyway.
« Last Edit: October 30, 2014, 05:24:31 PM by patrick »

Marcel

  • Senior Community Member
  • Posts: 261
  • Hero Points: 26
Re: B6: Less would be more: Reformatting of Java8 lambda expressions
« Reply #3 on: October 31, 2014, 12:05:05 AM »
Patrick - toggling the option didn't make any difference, the result stayed the same.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: B6: Less would be more: Reformatting of Java8 lambda expressions
« Reply #4 on: October 31, 2014, 01:17:14 PM »
Ok, there are two things I fixed that should take care of that.  The first was a parsing problem that didn't really recognize the lambda.  The second was a problem where the setting would not take effect when beautifying selections, alias expansions, or other types of snippets.

With those in place, that setting should cover lambdas too.  The fixes will be in the next build.