6

(Edited) NOTE: this question is NOT about how Eclipse's code formatter wrap long String literals. It is the behavior of MANUALLY breaking/wrapping String literal


The default behavior when I break a String literal by hitting enter inside the literal, is Eclipse will append " + at the place I hit enter, and start the rest of my line in next line, with " prefixed.

                            // v ENTER HERE
String longString = "abcdefghij|klmno";

String longString = "abcdefghij" +
        "klmno";

However, normal coding style practice suggests line wrap before operator. Is there any way that I can tell Eclipse to break my String like this?

String longString = "abcdefhij"
        + "klmno";
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • 1
    see http://stackoverflow.com/questions/11289076/change-how-eclipse-formatter-wraps-long-strings – Deepak Azad Jul 20 '12 at 14:44
  • 2
    @DeepakAzad I am in fact not talking about the formatter setting. Even you have formatter setting with wrap before operator, it didn't change the behavior that eclipse wrap line when you are breaking a String literal by hitting Enter key. That's what I am looking for : How to make String literal line wrapping behavior align with Formatter's setting. – Adrian Shum Jul 23 '12 at 01:49
  • 1
    @AdrianShum: Did you _try_ the proposed duplicate? Perhaps the formatter settings affect your case also. If that is _not_ the case and you _did_ try, please modify your question. This might bring more people to think about your problem. – A.H. Jul 23 '12 at 12:48
  • I did and that's why in my question, I am focusing only in manually breaking string literal. If you have had a try on the seems-to-be duplicate, you will find an interesting phenomenon: code formatter will completely reformat the result of manual breaking string literal. Please advise how should I modify my question coz I thought I have have emphasized enough that's about manual breaking of string literal (and not about formatter) – Adrian Shum Jul 24 '12 at 04:53

2 Answers2

6

In 4.3 you can control this setting with the Wrap before operator checkbox for Binary expressions.

Formatter settings in Eclipse Luna

Lukas Glowania
  • 498
  • 6
  • 12
  • 1
    I believe such setting have always been there in code formatter. Just in case you didn't follow the question, in very first line in question I have already mentioned: `NOTE: this question is NOT about how Eclipse's code formatter wrap long String literals. It is the behavior of MANUALLY breaking/wrapping String literal` In older version of Eclipse, code formatting for manually breaking long line literal does not follow code formatter settings – Adrian Shum Oct 18 '14 at 03:00
  • I just answered to save somebody some time because this option in the formatter settings is a bit obfuscated. For me it was not clear that "Binary Expressions" affects string wrapping. – Lukas Glowania Oct 19 '14 at 18:30
0

Finally I found this is one missing feature of Eclipse.

Currently this issue is tracked under Eclipse's issue tracker : https://bugs.eclipse.org/bugs/show_bug.cgi?id=48433


Update: I am now using Eclipse 4.3, and found that this feature is now available. Position of + operator when you are manually breaking a long String will now follows your code formatter setting.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131