Martin Stone
Martin Stone

Reputation: 13007

Can I make the Eclipse source formatter preserve the original spacing around operators?

Sometimes I like to space an expression non-uniformly. E.g., I prefer...

x*x + y*y

...to...

x * x + y * y

It seems that the Eclipse formatter won't allow this. I can tell it to put either zero or one space around every operator, but I can't see how to make it leave the spacing as I wrote it. Can this be done? (@formatter:off is too intrusive.)

Upvotes: 0

Views: 331

Answers (2)

Dave Newton
Dave Newton

Reputation: 160171

No, the formatter formats, unconditionally.

Upvotes: 3

Eng.Fouad
Eng.Fouad

Reputation: 117589

Go to:

Window -> Preference -> Java -> Code Style -> Formatter -> Edit -> White Space -> Expressions -> Operators

and then check the following 2 check boxes:

☑ before binary operators
☑ after binary operators

Upvotes: 0

Related Questions