Alternative or way to force eclipse source code formatter to break line at 80 characters?
Asked Answered
O

3

7

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.

Ornithopod answered 28/10, 2009 at 1:13 Comment(0)
L
17

From menu bar: Window > Preferences > Java > Code Style > Formatter > Edit (button) > Line Wrapping (tab). You can customize the maximum line width and change the line wrapping policy.

Lemal answered 28/10, 2009 at 1:32 Comment(1)
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)); // NOPMD and others like it.Ornithopod
F
0

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.

Formidable answered 28/10, 2009 at 1:30 Comment(0)
E
-1

I always do the following in my code if I want to enforce specific formatting:

public CDataCacheContainer loadDataset(CDataFileDef dsd) // throws IOException { // // ... }

Entrails answered 19/6, 2012 at 21:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.