Idea logo

The IntelliJ IDEA Blog

The Capable & Ergonomic Java IDE by JetBrains


Arrange Your Code Automatically with IntelliJ IDEA 12

You probably might have noticed that code always tends to be organized in a particular way. For instance, fields always go before methods, static fields go before instance fields and so forth. This is the easiest way to read your code.

Previously IntelliJ IDEA did not provide any native support for arranging code automatically. There was a third-party Rearranger plugin for Java language. Now we plan to bundle it into the IDE with native support for Java and other programming languages.

How to:

You can use either of the following ways to rearrange your code:
1. Call Rearrange code action explicitly.
2. Enable Rearrange entries in Code Reformat options.


Arrangement settings are available now in Code Style settings on a separate tab.


  • Allows you to keep getters and setters together
  • Allows you to group overridden methods by class and interface. For instance, your class implements MouseListener and KeyListener, so you want to keep your methods grouped by the interface where they are declared.
  • Keeps dependent methods together. For instance, service() method calls util() method, and you want to keep util() after service().
  • Defines elements order as a list of rules where every rules has a set of matchers like modifier or type. For example, a rule can be like type field and modifiers public, static and final.

Coming soon:

  • Better user interface in Arrangement settings.
  • Order elements alphabetically.
  • Name conditions like type field with name like ‘*weight.
  • Arrangement for ActionScript and XML.

The new feature is already available in the latest IntelliJ IDEA 12 EAP. Please feel free to share your feedback and submit bug reports in our issue tracker.

Keep you code arranged with pleasure!

Comments below can no longer be edited.

35 Responses to Arrange Your Code Automatically with IntelliJ IDEA 12

  1. Tropper says:

    October 1, 2012

    Nice, I’m using IDEA since version 8 now. But today is the first time I see the Enter action or operation dialog. Amazing 🙂

  2. Tomek N. says:

    October 1, 2012

    What do you think about arranging methods by their dependencies, i.e. calling method is always after the caller? This way the code can always be read top-to-bottom.

  3. Andrey Cheptsov says:

    October 1, 2012

    @Tomek. As far as I understand, it sounds like the third feature described in the post.

  4. harryhoppel says:

    October 1, 2012

    Niiiiiice! If I may humbly request a feature: I want to automatically move all Spring setters with @Required annotation to the bottom of the file. Will that be possible?

  5. Gilles Philippart says:

    October 1, 2012

    Brillant. Now If you could include pre-configured well-known sensible defaults : “Uncle Bob” style, “Java Standard Conventions” style …

  6. John Hurst says:

    October 1, 2012

    Standard defaults sounds good.

    Perhaps there is a JetBrains standard? 🙂 I would be interested in seeing it!

    John Hurst

  7. Denis.Zhdanov says:

    October 1, 2012

    @harry:I think it’s worth to provide java- specific annotation-based rules. Can I ask you to file a corresponding feature request to the IJ tracker?

  8. Denis.Zhdanov says:

    October 1, 2012

    @Gilles: good idea! Please submit corresponding request to the tracker. It would be cool if you provide links to the corresponding standards there.

  9. Pete says:

    October 1, 2012

    It might already be there but the ability to sort methods by the class they override or interface they implement.

  10. jkv says:

    October 2, 2012

    Shouldn’t it be in commit dialog as well?

  11. Erik Pragt says:

    October 3, 2012

    Calling rearrange from ‘Find action’ doesn’t work for me, IntelliJ throws a NPE. I’ve submitted the bug.

  12. Wes says:

    October 6, 2012

    Would something like a new line enforcement between fields be possible? Like allowing private ones to have a blank line in between public and for protected?

  13. Ivan says:

    October 22, 2012

    Please add ability to move methods variables into appropriate “sections”. E.g. like in “Rearranger” plugin in plugin repository.

  14. Denis.Zhdanov says:

    November 7, 2012

    Hi guys,

    FYI: the tickets mentioned below target the requested functionality. They are expected to be fixed prior to the v.12 release:

  15. Alex says:

    November 16, 2012

    nice feature, but not for me. It will distort legacy codebase. Maybe it will be applicable for the new code. But automatically rearrange is something absolutely stupid 🙂

  16. Daniela Waranie says:

    December 6, 2012

    I will upgrade from IDEA 11 to IDEA 12 when all features of this article are available to PHP developers.

  17. Maxim Mossienko says:

    December 6, 2012

    @Daniela Please vote rearranging in PHP for

  18. Wojtek Erbetowski says:

    December 7, 2012

    Great feature, we really missed this one when moving from Eclipse.

  19. kjordan says:

    January 14, 2013

    Can a similar thing to the “Keep dependent methods together” be added for field ordering? i.e. if one field uses another field as an argument to its constructor that that one is kept above it. I believe the old rearranger plugin did this and it’d be nice to avoid null pointer exceptions but keep them sort of sorted.

  20. Denis.Zhdanov says:

    January 15, 2013

    Good spot! Created corresponding ticket –


  21. Roedy Green says:

    January 15, 2013

    You can’t just reorder variables willy nilly if there are initialisation expressions. For safety the expressions would have to be moved to [static] init blocks where the order can be preserved.

    Teams kill each other over such conventions so it is useful to let people safely interconvert between a personal style and a check-in corporate style without introducing any initialisation order problems.

    I spent a fair bit of time fiddling my old rearranger so that it naturally sorted initialisations to work in the right order.

  22. mark says:

    May 10, 2013

    Pity it doesn’t seem to work for an entire module or an entire project.

  23. Shervin says:

    June 18, 2013

    I am trying to rearrange enum to be sorted alphabetically.
    In the Arrange settings, I have chosen it to order by name.
    However, it still doesnt arrange anything when I Rearrange the code.

    Bug? Or am I doing something wronge?

    • Arul says:

      October 17, 2014

      I also tried the same with IntelliJ IDEA 13.1.5. Its not working.

      • Danil says:

        April 19, 2016

        Same on build 145.597

        • Alexandru says:

          January 3, 2019

          There is a plugin which is doing that – available for Kotlin, named Flares.

  24. Michel Werren says:

    June 21, 2013

    A further option for getter / setters placement would be nice
    like this:

    1 method public
    2 method package private
    3 method protected
    4 method private
    5 method getter / setter

  25. Luka Obradovic says:

    July 30, 2013

    Rearrange features is great, but I can’t rearrange these:
    final static private int NODE_COUNT_CHUNK_SIZE = 4096;
    final static private int PAIR_COUNT_CHUNK_SIZE = 65536;
    final static private int CHAR_COUNT_CHUNK_SIZE = 1024 * 512;
    final static private int FLOAT_COUNT_CHUNK_SIZE = 1024;
    final static private int DOUBLE_COUNT_CHUNK_SIZE = 1024;

    Although I have “Matching rules” set for fields to be:
    [field] [private] [static] [final]

    it does not get rearranged 🙁

    Can you please help.


  26. Denis.Zhdanov says:

    July 31, 2013

    Hi Luka,

    The rearranger works at class level, i.e. replaces fields, methods, nested classes and interfaces etc. However, it doesn’t change, say, modifiers order for the same field.

  27. Jared Rummler says:

    December 2, 2015

    This plugin is not found when I search for the plugin using Android Studio. I know I can install it manually, but I would rather have the IDE manage my plugins. How do I get the plugin on Android Studio?

  28. Martin says:

    May 1, 2016

    Order elements alphabetically. Coming Soon?

  29. Ri7ab says:

    December 28, 2016

    I want to rearrange my code, like having first of all all the fields grouped together, he the constructor(s), then the methods and at the end the getters and setters, I could not figure out how to do it automatically. Is this also handled ? If yes, then how please ?

  30. DestinatioN says:

    February 15, 2017

    Is there a way to arrange html elements as well?

  31. Oleg says:

    June 21, 2017

    Looking forward for this feature for Kotlin code

  32. Tom says:

    January 31, 2018

    How do I set the re-arranger to keep constructors at the top in simple (no parameter) to complex order (many parameters)?

Discover more