Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkstyle and Eclipse; Java string continuation

(I know this is a sort of lazy question, but it's oddly hard to search for...especially since checkstyle does so much, and Google search results are littered with checkstyle reports.)

Can someone tell me which checkstyle check reports "+ should be on a new line" when splitting long strings over multiple lines in Java?

On an aside, this SO question in a roundabout way asked if there is any way to get Eclipse to put the "+" symbol on the new line when it splits a string for you. Is there an easy way?

like image 825
Boden Avatar asked May 15 '09 18:05

Boden


1 Answers

Probably the operator wrap check is responsible for that "+ should be on a new line" message.
It is found in the "Whitespace" section.

if there is any way to get Eclipse to put the "+" symbol on the new line when it splits a string for you. Is there an easy way ?

The only way I know is to format the code which has just been produced:
when you hit "return" in the middle of a String, it does out the '+' at the end of the first line.
But you format the code, it does put back the '+' at the beginning of the second.

Since you can only format the section in which you are (like the current method you are editing), that tip does not mean you will format the all class anytime you want to put the '+' at its right place. Only the current block of code.
(it the the command "Format Element", and it has by default no key shortcut, so you can assign one)

like image 182
VonC Avatar answered Nov 15 '22 03:11

VonC