Core_F
Core_F

Reputation: 3442

Eclipse Formatter: Line wrapping for method names not working?

where I work we are using the same code style for eclipse in the team and in addition we have SonarQube running to find style errors (and more). We've noticed a problem with our max. line length, which is set to 140 characters:

https://i.sstatic.net/NaqVy.png

Eclipse won't wrap our methods and constructors and we have several that are more than 140 characters long. It's just a beauty issue, but I it would be nice to get rid of hundreds of issues in SonarQube.

I've googled for the error and found several bug entries at https://bugs.eclipse.org, but most of them are very old. Does anyone have a workaround or solution for this?

Eclipse Luna Release (4.4.0)
Ubuntu 14.04

edit:
Ok, I did some testing. It looks like the line length is a problem, when the opening bracket is the only char beyond 140 characters. So if the closing bracket for the parameters is the 139th char and the opening bracket for the method the 141 char, then it won't wrap the line.

Upvotes: 0

Views: 1069

Answers (2)

Core_F
Core_F

Reputation: 3442

Found the answer and an easy workaround:

Eclipse ignores the line wrap, if the only char higher than the maximum is the opening brace "{". So the easiest solution for us, as we don't want to update our profile: We just increased the line length rule in SonarQube to 143.

Upvotes: 0

Pranalee
Pranalee

Reputation: 3409

This is on windows. But I guess eclipse should have similar options on linux. Eclipse->Window->Preference->Java->Code Style->Formatter->Line wrapping.

You can also create profile in Formatter with specific setting for everything and share with your team.

enter image description here

Upvotes: 1

Related Questions