Micha Wiedenmann
Micha Wiedenmann

Reputation: 20873

Prevent eclipse from removing whitespaces

How can I prevent Eclipse from removing whitespace within a line?

Example:

final Map<String, String> capitalOf = new HashMap<String, String>();
capitalOf.put("France",       "Paris");
capitalOf.put("Italy",        "Rom");
capitalOf.put("Switzerland",  "Bern");

gets becomes after calling Format (Ctrl-Shift-F)

final Map<String, String> capitalOf = new HashMap<String, String>();
capitalOf.put("France", "Paris");
capitalOf.put("Italy", "Rom");
capitalOf.put("Switzerland", "Bern");

Upvotes: 0

Views: 59

Answers (1)

Torsten
Torsten

Reputation: 6204

You can edit the behavior of the Java Formatter in the white space section of the Preferences (Java - Code Style - Formatter).

Formatter Preferences

In your case you will have to rely on the formatter tags to turn off the formatting of your code:

    @formatter:off
    capitalOf.put("France",       "Paris");
    capitalOf.put("Italy",        "Rom");
    capitalOf.put("Switzerland",  "Bern");
    @formatter:on

For this to work, the off/on tags have to be enabled as shown below:

Formatter Off/On tags

Upvotes: 1

Related Questions