Intellij-IDEA: How to sort members alphabetically?
Asked Answered
D

1

39

I am using Intellij-IDEA 12. Most of team mates use Eclipse and while saving it sorts members automatically first based on Visibility and then Alphabetically. I want to mimic the same functionality in Intellij. But it seems that when I choose arrange members alphabetically, it overrides visibility (and all other) rules. How can I sort members based on Visibility (Public - Default - Private ) and within that sub-group sort them Alphabetically?

Edit: This assumption made in the question is wrong. Like mentioned in the Answer by @Maba, creating separate rows and marking them as "Order Alphabetically" works as expected. ( I had separate rows for fields but failed to create separate rows for Methods and hence the confusion.)

Daliladalis answered 2/7, 2013 at 20:41 Comment(2)
Did you try out my answer?Malcolmmalcom
I did. That was the first thing I had tried.Daliladalis
M
39

Create separate rows for the different method visibilities in the Arrangement part of the Code Style.

enter image description here

enter image description here

enter image description here

enter image description here

Malcolmmalcom answered 3/7, 2013 at 7:17 Comment(4)
In IntelliJ 15 I had to modify the order type of the default matching rules to obtain the expected behavior.Saccular
Note that combining the alias by visibility and Order: order by name did not sort the methods first by visibility and within visibilities by name. I had to add a rule for each visibility and select Order: order by name.Maximo
How can I apply an order choice to one or more rules at once?Enunciate
Worth mentioning that to see the pane with the Order dropdown you need to right-click on the matching rule and select "Edit rule". However, this wasn't a good solution for me as I didn't want my code formatter to order fields every time I format the code - only for a one-off. I ended up sorting them manually this time but would hope there might be an easier way.Dewyeyed

© 2022 - 2024 — McMap. All rights reserved.