Ternary operation alignment
This what Idea alignes
return MenuItemType.GROUP_ITEM.getTypeCode().equals(item.getItemType()) ? new AppMenuGroupItem(strAppIds.get(
item.getAppId()), item.getItemType(), item.getTitle(), null, item.getIcon()) : new AppMenuItem(strAppIds
.get(item.getAppId()),
item.getStrId(),
item.getItemType(),
item.getTitle(),
item.getWindowClass(),
item.getJsniEvent(),
item.getIcon(),
item.getUrl());
and this what I would expect (or something similar)
return MenuItemType.GROUP_ITEM.getTypeCode().equals(item.getItemType()) ?
new AppMenuGroupItem(strAppIds.get(item.getAppId()),
item.getItemType(),
item.getTitle(),
null,
item.getIcon()) :
new AppMenuItem(strAppIds.get(item.getAppId()),
item.getStrId(),
item.getItemType(),
item.getTitle(),
item.getWindowClass(),
item.getJsniEvent(),
item.getIcon(),
item.getUrl());
Is there anything can be done, thanks
请先登录再写评论。
Hi Vladimir,
Please try the following:
That produces the following result:
Denis
I want chop :) not wrap and result is inconsistent as I can tell.
I'm afraid I don't quite understand what do you want to achieve - 'wrap ternary operation' makes the second and third operands to be located on new lines; 'chop method call arguments if long' makes method call arguments to 'chop' if they exceed right margin.
I get the following result by formatting your code written in one line:
Before
After (right margin is set to 120)
After (right margin is set to 160)
You can see that both operands are chopped when right margin is set to 120 (because they both exceed it) but only the second operand exceeds 160 visual columns, hence, it is the only one chopped at the second case.
Please clarify desired formatter's behavior if the current one doesn't suit your needs.
Denis
Setting: Chop down when long, align when multiple
I have a right margin set to 120 and would extect alignment as in the second part of the original post
return MenuItemType.GROUP_ITEM.getTypeCode().equals(item.getItemType()) ?
new AppMenuGroupItem(strAppIds.get(item.getAppId()),
item.getItemType(),
item.getTitle(),
null,
item.getIcon()) :
new AppMenuItem(strAppIds.get(item.getAppId()),
item.getStrId(),
item.getItemType(),
item.getTitle(),
item.getWindowClass() + (url != null ? "#" + url : ""),
item.getWindowClass(),
item.getJsniEvent(),
item.getIcon(),
item.getUrl());
And I'm getting below
return MenuItemType.GROUP_ITEM.getTypeCode().equals(item.getItemType()) ? new AppMenuGroupItem(strAppIds.get(
item.getAppId()), item.getItemType(), item.getTitle(), null, item.getIcon()) : new AppMenuItem(strAppIds
.get(item.getAppId()),
item.getStrId(),
item.getItemType(),
item.getTitle(),
item.getWindowClass() +
(url !=
null ?
"#" +
url :
""),
item.getJsniEvent(),
item.getIcon(),
url);
What is your original text before formatting? Is it the one where the whole ternary operator is writtenn in one line?
Please provide original text and your code style settings.
Denis
Yes, everything was one line, setting.jar is attached
Attachment(s):
x-settings.jar
Just uncheck the following property and you're done - 'Wrapping and Braces - Method call arguments - Take priority over call chain wrapping'
Denis
Thanks, but I'm not sure I want to do this, I want to take priority over call chain but at the same time I want to a?b:c operation to be properly aligned as well, not a big deal but nice to have.
Thanks
Hi Vladimir,
I'm afraid it's not possible to achieve that with the current formatting facilities.
Looks like you need the feature discussed here.
Denis