views:

797

answers:

2

Whenever I use the Eclipse source code formatter / beautifier (via the menu item Source - Clean Up or CTRL - SHIFT - f) it reformats statements that I have broken into multiple lines back into one line that is longer than 80 chars, eg I have:

public CDataCacheContainer loadDataset(CDataFileDef dsd) 
   throws IOException {

and it becomes

public CDataCacheContainer loadDataset(CDataFileDef dsd) throws IOException {

which is longer than 80 characters and looks poor when printed.

Can I prevent eclipse from doing this? Or is there an alternative eclipse source code formatter that wraps at 80 characters nicely?

EDIT 1: In Eclipse under Window - Preferences - Java - Code Style - Formatter - Edit the maximum line width was set at 80. I've changed it to 78 and also enabled wrapping on Assignment expressions and this has helped. Now the only expression that isn't wrapping is this one:

datasetsNode.add(new TreeUtil.PanelViewNode(this, table)); // NOPMD

and others like it.

A: 

Make sure that the in your preferences under Java > Code Style > Formatter you create a new active profile. Edit it and under line wrapping make sure you have Maximum Line Width set to 80.

rmarimon
+2  A: 

Preferences > Java > Formatter > Edit > Line Wrapping. You can customize the maximum line width and change the line wrapping policy.

Dean Povey
Thanks for pointing this out. The maximum line width was set at 80, I changed it to 78 and also enabled wrapping on Assignment expressions and this helped! Now the only expression that isn't wrapping is this one:datasetsNode.add(new TreeUtil.PanelViewNode(this, table)); // NOPMDand others like it.
tukushan