Rearranging code Eclipse-style in IntelliJ IDEA 12
Hello
I'm the only one in my team who uses IntelliJ. The remainder of the team use Eclipse. It's been suggested that I start ordering my code according to the style utilized by Eclipse.
I was hoping someone here has (or knows where to get) an already-defined set of rules (as defined in Settings > Code Style > Java > Arrangement) that will mimick Eclipse's default style of code ordering.
Thanks
-- Cam
请先登录再写评论。
What prevents you from configuring that rules by yourself? :)
Btw, what are eclipse ordering rules?
Denis
What are you driving at Denis? :)
I could define them myself, but before going down that avenue I thought I'd see if someone had a screen cap or breakdown of the configuration on-hand. The alternative would entail either downloading eclipse and experiementing with it, or having a coworker order a class containing a varying number of methods, members, etc. (each with varying modifiers) and deriving the order from that. If I end up doing this, I'll post what I find in a reply to this thread, but until then I'm hoping someone will just happen to have this information and post it here.
-- Cam
Ok, I see.
I asked about eclipse ordering because I'm thinking about adding an ability to setup arrangement rules from a predefined set. Just not sure whether it would be demanded.
Denis
I don't have this need but you can create rules, hopefully it would only take you a few minutes to do.
![]()
**eclipse sort order **
Attachment(s):
eclipse sort order.PNG
Hello,
After installing Eclipse and experimenting with different class contents, I came up with the following arrangement config (Settings > Code Style > Java > Arrangement) that seems to best match Eclipse's default ordering. There are a couple of issues I am unable to overcome, which I outline later on, but first the config:
All of the following rules should be ordered by name
All three of the grouping rules should be unchecked
Problem #1:
Eclipse treats enums, classes, and interfaces as a single type, and it sorts these items alphabetically. So if you have enums A and D, interfaces B and F, and classes C and E, Eclipse will produce the following (sorted alphabetically by type name):
public enum A {}
public interface B {}
public class C {}
public enum D {}
public class E {}
public interface F {}
As far as I can tell, there is currently no way to achieve this using the current version of IDEA 12's arrangement tool. Using the configuration I supplied above, IDEA would sort it as:
public enum A {}
public enum D {}
public interface B {}
public interface F {}
public class C {}
public class E {}
I would ideally like to replace my first 12 lines of the config with something similar to:
Problem #2:
Eclipse orders constructors with the same access level by the number of arguments they take, where as IDEA 12 orders them in the order that they appear in the file.
E.g.
While the following would remain untouched after sorting the code in IDEA 12:
public Foobar(String a, String b) {}
public Foobar(String a) {}
public Foobar(String a, String b, String c) {}
In Eclipse, it would appear as
public Foobar(String a) {}
public Foobar(String a, String b) {}
public Foobar(String a, String b, String c) {}
Ultimately these problems are minor for me, but I thought I'd mention them anyways. The above config I derived will work fine for me most of the time. I can manually tweak the code in the cases where it doesn't quite work (but only when my coworkers complain :) )
Message was edited by: Cameron Donaldson (minor typo)
Hi Cameron,
Firs of all let me thank you for the input!
Regarding the mentioned problems:
About enums/classes/interfaces treated the same - looks like you'll be able to achieve that behavior when IDEA-95126 is complete, i.e. it will be possible to specify type as 'not method and not field and not constructor'.
Note that all of the tickets mentioned above are scheduled for the v.12.1 (ETA is spring of 2013)
Denis
Hi Denis
I'm glad I could help. I'm sure I'm not the only IntelliJ user out there being coerced into using Eclipse ordering ;), so hopefully the above config details proves useful to others.
Thanks for the tracker tickets. I'll start watching them so I can keep an eye on their progress.
-- Cam