Wrap chained method class with this qualifier

When setting as "wrap always" for chained method calls, anything with a this qualifier is, in my opinion, incorrectly wrapped before the first method call.

i.e.:
this.myVar
        .myMethod()
        .mySecondMethod();
instead of:
this.myVar.myMethod()
                .mySecondMethod();

If "align when multiline" is also on for chained method calls, it also doesn't seem to align to any period or variable name or keyword in particular, as shown above (in my case that's 2 tabs worth).

7 comments

Hi Kevin,

What language do you point here? Java, javascript, something else?

Denis

0

This is for Java.  I'm not sure if it's the same in other languages.

edit:  It only appears to be an option for chained method calls in Groovy and Java.

edit2:  The subject of this thread should be "chained method calls" not "chained method class" as I had typed it.

0

I'm afraid I don't quite understand the problem. Current algorithm wraps at the first appropriate place going from right to left - check a screencast which illustrates that. As far as I understand, you suggest to modify the algorithm to work ... how?

Denis

0

Hi Denis,

I think I know what he means - I am seeing the same problem here.

When users set "Chained methods calls" to "Wrap always", IDEA wraps right after the first call - no matter what.  This cause simple operations being treated as complex uneccessarily.

This has at least these following flaws:

  1. this.someVariable and this.someMethod() are consider 1 call - I believe "this" shoud be ignored.
    • this.username.toString() and this.getUsername().toString() are consider complex and toString() will be wrapped to the next line - even though only subsequent calls should be wrapped.
  2. The first object variable call also counts - I think if the first call is not a method call, it should be ignored.
    • System.out.println() will be formatted as
      • System.out
        • .println();


Regards,
Chau.

0

And btw, he was talking able "Wrap always".  Your screencast is about "wrap if long" I believe.

Please see my screenshot for how beatiful "Wrap always" is.  (This work in a lot of cases).



Attachment(s):
Wrap.PNG
0

Fair enough.

Feel free to submit corresponding ticket to the tracker.

Denis

0

Thanks, Denis.

For those of you who might want to keep an eye on this feature, I had opened an issue here - http://youtrack.jetbrains.com/issue/IDEA-102942

Cheers,
DTC.

0

Please sign in to leave a comment.