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

7 comments
Comment actions Permalink

What prevents you from configuring that rules by yourself? :)

Btw, what are eclipse ordering rules?

Denis

0
Comment actions Permalink

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

0
Comment actions Permalink

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

0
Comment actions Permalink

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
0
Comment actions Permalink

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

  1. enum | public
  2. interface | public
  3. class | public
  4. enum | private
  5. interface | private
  6. class | private
  7. enum | protected
  8. interface | protected
  9. class | protected
  10. enum | package private
  11. interface | package private
  12. class | package private
  13. field | public | static
  14. field | private | static
  15. field | protected | static
  16. field | package private | static
  17. method | public | static
  18. method | private | static
  19. method | protected | static
  20. method | package private | static
  21. field | public
  22. field | private
  23. field | protected
  24. field | package private
  25. constructor | public
  26. constructor | private
  27. constructor | protected
  28. constructor | package private
  29. method | public
  30. method | private
  31. method | protected
  32. method | package private


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:

  1. {enum|interface|class} | public
  2. {enum|interface|class} | private
  3. {enum|interface|class} | protected
  4. {enum|interface|class} | private package


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)

0
Comment actions Permalink

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

0
Comment actions Permalink

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

0

Please sign in to leave a comment.