ECLIPSE NEWBIE: How to preserve line breaks on re-formatting?

Dear Eclipse Experts,

I'm just getting started with Eclipse...  

Is there a way to tell the reformatter (Ctrl+Shift+F) to leave line breaks alone?  When I have something like:

Do This AND
Do That AND
Do Another

I'd like those to remain on three separate lines.  Is that possible?

Thanks!
BrianMc1958
BrianMc1958Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

radarshCommented:
Go to Window -> Preferences -> Java -> Code Style -> Formatter
and edit the template. Line breaks can be in different places. You'll have to configure
appropriately.

________
radarsh
BrianMc1958Author Commented:
Dear radarsh,

Thanks.  I'm there, but I'm afraid I can't find what I'm looking for.  More specifically, I want this type of statement to retain the line breaks:

String s =
  "First Thing " +
  "Second Thing " +
  "Third Thing  ";

I can't find how to do that.  I'm sure I'm missing something simple...

--BrianMc1958
radarshCommented:
I'm afraid it is not there for eclipse 3.1. Even I have a very similar problem. But, no solution seems
to exist. I think it is a bug in Eclipse. :((

________
radarsh

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Mujtaba_Alam_KhanCommented:
I dont know if this will work or not ,but try it, it just might

String s =
  "First Thing \n" +
  "Second Thing \n" +
  "Third Thing  \n";

-Muj ;-)
radarshCommented:
Muj,

That will change the value of the string s itself. Which is undesirable.
Consider a scenario where you have to write a huge query as a static final
String constant. One would want it to be neatly formatted. But, eclipse doesn't
allow us to retain line breaks...

________
radarsh
BrianMc1958Author Commented:
Thanks, folks.  I'm now seeing that the preserve-line-breaks option was REMOVED from Eclipse a couple years ago. WHY?  WHY WHY WHY???

OK.  Sorry.  Does anyone know a way around this problem?  It's actually important to me, as line breaks are sometimes needed to make sections of the code at all readable.

Thanks again,
BrianMc1958
Mujtaba_Alam_KhanCommented:
from what I see the string seem to be used for display propers.. and nothing more..

why would you want a line break ...

example:

String s =
  "First Thing " +
  "Second Thing " +
  "Third Thing  ";

same as saying String s = "First Thing " + "Secong Thing " + "Third Thing ";  //

-Muj ;-)
BrianMc1958Author Commented:
I often have long Strings that match up field names and field values, like:

...
"FirstField = " + firstField +
"SecondField = " + secondField +
...
Mujtaba_Alam_KhanCommented:
Ok I see this is an SQL query .. but along one..

So again what is the problem..

why not just right one long query in a straight line.. normally I do that and dont bother with puting + +..

-Muj ;-)
radarshCommented:
>>why not just right one long query in a straight line
That would spoil the readability of the Query!

One thing you can do is, select regions of code you want to format, and hit Ctrl+Shift+F

Do not select the query. This is what even I do sometimes.

________
radarsh
BrianMc1958Author Commented:
Thanks, folks.
Mujtaba_Alam_KhanCommented:
>> That would spoil the readability of the Query!
Normal the IDE should break them up and put + + where ever needed.

Ok here is another suggetion why not split the Long query into small String and + at the end...
example:

String select = "SELECT * FROM WHERE firstField = ";
String ffield =  "'+firstField+'";
etc..

String sql = select + ffield + etc...

Only a suggesion ..

-Muj ;-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.