tags:

views:

98

answers:

1

Eclipse 3.5 indents this code correctly:

    addWindowListener(new WindowAdapter()
    {
        @Override
        public void windowClosing(WindowEvent e)
        {
            dispose();
        }
    });

but as you can see, it indents this code incorrectly:

    final Action closewindowaction = new AbstractAction("Close window")
            {
        public void actionPerformed(ActionEvent e)
        {
            dispose();
        }
    };

The obvious difference is that the second example uses an assignment, but I've set assignment in line wrapping to use default indentation and I've set that default indentation to zero, so I don't see any reason why it should be misbehaving. Any idea how to fix this?

+1  A: 

What is your line wrap set to in the formatter? the second line is close to 67 characters long (it will obviously be more depending on the initial indentation), IIRC 80 is the default for line wrapping, so it might be Eclipse is wrapping the line for the opening brace.

Update: Based on your posted settings. It looks like you've got Never join lines in Line Wrapping->General Settings checked. If I uncheck that option I get the indentation you expected.

Rich Seller
128 characters, so it's not that.
rwallace
It's difficult to diagnose without seeing your formatter settings, FWIW the second snippet formatted fine on my box. The only other things I can think of is that your class has some syntax error elsewhere that is confusing the formatter.
Rich Seller
No syntax errors, but I have tinkered extensively with the formatter settings to get other things to come out right; it's probably something to do with that, if your setup formats the second example correctly. Is there a way to generate a list of formatter settings?
rwallace
Yes, when you *Edit* the Formatter profile, there's an *Export...* button next to the *Profile name:* field, it will export a ~300 line xml file
Rich Seller
Done. It's too big to put in a comment, so I've uploaded it to http://sites.google.com/site/winterwood314/eclipsesettings
rwallace
You're right, bizarrely, unchecking Never Join Lines does fix this problem. However, it messes up array initializers and multiline literal strings. Is there any way to get the effects for just this context without the others?
rwallace
It works ok if you have the open braces on the same line, looks like this might be a bug in the formatter when you have open braces on the next line. I'll have a further look at it when I get the chance.
Rich Seller
In the meantime, with Never Join Lines unchecked, I got array initializers to format correctly with a bit more tinkering, and I can live with the current behavior for string literals, so that works okay now. Thanks!
rwallace