IDEA 10.0.2 - Line wrapping issue

I'm sure I don't have my line wrapping settings quite right, but can you help me figure out what I need to do to get the following to wrap as I would like.  Here is what the formatting was previous to running IDEA's formatter.

        TestHelper.checkBorder(new LineBorderUIResource(LookAndFeelConstants.decodeColor("#XXXXXXX")),
                "XXXScrollPane.border", new JScrollPane());



After running the formatter ----

        TestHelper
                .checkBorder(new LineBorderUIResource(LookAndFeelConstants.decodeColor("#XXXXXXX")),
                        "XXXScrollPane.border", new JScrollPane());



What I would like to have it formatted as ------

        TestHelper.checkBorder(
                new LineBorderUIResource(LookAndFeelConstants.decodeColor("#XXXXXXX")),
                "XXXScrollPane.border", new JScrollPane());



Thanks for your help!
14 comments
Comment actions Permalink

Hi Angella,

Please try to set the following:

  • Project Settings -> Code Style -> Wrapping and Braces -> Method call arguments - 'Wrap if long';


Regards, Denis

0
Comment actions Permalink

I have that setting already.  Any other ideas?

0
Comment actions Permalink

Please provide your code style settings and exact file that you're reformatting.

Denis

0
Comment actions Permalink

I've saved them as Global Settings.  Can you direct me on how to export those?  Thanks!

0
Comment actions Permalink

The code style settings are stored at *.xml file under the following directory - ${user.home}/.IdeaIC10/config/codestyles

Also provide please exact source file that you're trying to format.

Denis

Update: provided path is the one used by Community Edition. Please use ${user.home}/.IntelliJIdea10/config/codestyles in case of Ultimate Edition

0
Comment actions Permalink

Try enabling this:

Project Settings -> Code Style -> Wrapping and Braces -> Method call arguments - 'Take priority over call chain formatting'

0
Comment actions Permalink

I turned that one off, because it was causing the formatting to not make commas take precedence when formatting, so a line like:

final JComboBox comboBox = new CustomComboBox(getText(), getComboBoxItems(something, something, somthing));


Became---------------------

final JComboBox comboBox = new CustomComboBox(getText(), getComboBoxItems(something,
     something, somthing));



Instead of ------------------------

final JComboBox comboBox = new CustomComboBox(getText(),
       getComboBoxItems(something, something, somthing));

0
Comment actions Permalink

Yes, I think I had a similar problem -- no combination of flags gave me a satisfactory result in 100% of the cases. I set it up to produce an acceptable result in most cases, and in the remaining cases reformat manually.

0
Comment actions Permalink

Hi Sergei,

Have you filled any tickets to IJ tracker for that?

Denis

0
Comment actions Permalink

I don't think I did. I simply put up with it, because in most of the cases formatting works fine for me, and I don't have too much poorly formatted code to deal with on a regular basis.

I like Angella's examples though, they are pretty illustrative of the formatting issues I face.

Having just given it a thought, my personal wrapping preference for long lines are:

  1. wrap after = in assignment
  2. then wrap top-level call chains
  3. then wrap top-level call arguments
  4. only then go inside method call parentheses and apply 2. and 3. to each of the arguments recursively, until they fit inside margins



An insanely complex example (I've just made it up, it is not some real code!):

final Comparator<String> comparator = MyStringComparator.newBuilder().caseSensitive(Boolean.valueOf(System.getProperty("case_sensitive", "true"))).build();


...becomes something like:

final Comparator<String> comparator =
     MyStringComparator.newBuilder()
          .caseSensitive(
               Boolean.valueOf(
                    System.getProperty(
                         "case_sensitive",
                         "true"
                    )
               )
          )
          .build();



The major problem I am having is how to formalise it into configuration options (and that's probably why I did not submit it before). I can still file a youtrack ticket with the above information, if you like.

Kind regards,
Sergei

0
Comment actions Permalink

We can elaborate that a little bit more and then create a ticket with the summarized results if necessary.

I see two use-cases that need clarification for now:

  1. 'Wrap priorities' - that might be good idea but I'm not sure if that would be interesting for significant number of IJ users. For example, I reformatted your example and got the following result (right margin is 120 columns):

    final Comparator<String> comparator = MyStringComparator.newBuilder().caseSensitive(
        Boolean.valueOf(System.getProperty("case_sensitive", "true"))
    ).build();
    

    I don't want to say that that alternative is better, it's just different. However, I'd prefer it because less number of lines are used to hold the same amount of code. I.e. the point is that it's not clear if such a facility would be demanded;
  2. It's not clear where is right margin at your example, i.e. the question is if you suggest the formatter to wrap every 'sub-expression' in case initial line exceeds right margin?


Denis

0
Comment actions Permalink

In my made up example, the right margin would be about 45 columns, just to demonstrate the wrapping of the nested calls and expressions. In reality, I also have right margin set at 120 columns, but even then I cannot always achieve satisfactory look after automatic reformatting. It may be the case that there's simply no universal recipe, which would apply in all cases.

However, you've got the main points:

  1. priorities when wrapping [partially implemented as 'Method call arguments - 'Take priority over call chain formatting']
  2. wrap outer syntactic constructs first before wrapping any nested constructs

The main problem with code formatting is that there are many ways to format the same code fragment, and it is always down to personal preferences and taste. The formatting engine must be very flexible and configurable to be able to accommodate all possible formatting options.

I have never used Jalopy, for instance. Maybe I need to have a look at what's available there, and attempt to suggest the missing features in youtrack.

But at the end of the day, I have already reached a stage, when I have no problems working with (and maintaining) a number of projects, in a variety of formatting styles. That's why this issue has always been at the bottom of my priority list.

0
Comment actions Permalink

Hi Sergey,

I agree that introducing 'wrap priority' facility would bring additional flexibility to the formatter. However, that doesn't seem too demanded (at least for now).

P.S. Sorry for the long delay.

Denis

0
Comment actions Permalink

Thanks for all of the feedback.  I have entered a bug on this formatting issue, which I expect will be downgraded to an enhancement.  Please vote if you agree with my assessment!

http://youtrack.jetbrains.net/issue/IDEA-66072

0

Please sign in to leave a comment.