Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Eclipse formatter to not insert blank line between field declarations?

I am using Eclipse 3.5.1 (Galileo) and am having trouble with one of the auto-formatting settings.

At the moment when I auto-format a blank line is inserted between each and every field declaration. The behaviour I'm looking for is to organise field declarations without a blank line between. Except in the case where there is already one or more blank lines between the declarations, in that case I'd like the formatter to respect the space, and reduce >=1 lines to 1 line.

I know this was possible at some point with Eclipse (can't remember the version but I have used a setting for this), but I can't seem to find the correct settings in Window->Preferences->Java->Code Style->Formatter.

Which setting do I configure to enable this behaviour?


EDIT: It seems the behaviour I'm describing is the default, and for some reason I couldn't find a way to return to that without removing the .settings directory. It also couldn't be reproduced, which suggests that it's something weird with the project settings (it's checked out from an open source project). Although I've found a hacky way to fix this, I'm still looking for suggestions and will be able to verify and accept an answer.

like image 799
Grundlefleck Avatar asked Jan 20 '10 14:01

Grundlefleck


2 Answers

Format-Config

The Eclipse i am using is:

Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 2
Build id: 20120216-1857

As the picture above shows, there is a 'Between import groups' under the Blank Lines tab and it works for me. You can check it out.

like image 195
George Avatar answered Oct 23 '22 01:10

George


Strange, I cannot reproduce that behavior with my own formatter profile (eclipse3.5.1).

There was a setting back in 2003 (bug 38523) to "Insert new line after each parameter if line is too long", but this has been integrated into the "Line Wrapping" panel a long time ago.

Are you sure the newlines are not added because of a wrapping issue (due to a maximum line length too short)?

The tab "Blank Lines" does have an "Existing blank lines" section, with a "Number of empty lines to preserve" field which can be set to 1, and should address the later part of your requirements.
In that same tab "Blank Lines", check also the value of the "Before field declarations": "1" could explain the blank lines you see.

alt text
(source: comscigate.com)


The formatter options are in the org.eclipse.jdt.ui.prefs file, which is:

  • either in your workspace (.metadata.plugins\org.eclipse.core.runtime.settings)
  • or in the .settings of your project.

You can try and empty that file to check if the problem remains. It that clear up the issue, try adding some lines into that file, up to the point where the problem comes back.

.............................. 17Jan2020 Just remove the blank line after first field declaration. ..............................

like image 32
VonC Avatar answered Oct 23 '22 01:10

VonC