eclipse and line wrapping

Main menu:

Topics

Recent Posts

Feeds

RSS Feed RSS - Posts

July 2017
M T W T F S S
« Jun   Aug »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Past Posts

Java/Java EE

JDBC

Other

eclipse and line wrapping

July 2nd, 2017 by Jeanne Boyarsky

Last month, a co-worker referenced an Eclipse setting that I wish I’ve known about for years.  With streams, I typically indent code like:


list.stream().filter(j -> j.disabled)

.map(j -> j.name)

.forEach(System.out::println);

Then I’d let Eclipse format the code and it would turn into a one (or two) line wall of text. I’ve been “solving” that problem by adding comments before some of the methods so Eclipse couldn’t wrap it. Some of those comments are useful for those new to streams. However many are redundant. You probably don’t need a comment that the last line outputs :).

Then my co-worker taught me that there is an Eclipse setting to control the line breaks. Wish this was on by default!

How to configure

If you don’t already have a custom Eclipse formatter:

  1. Eclipse preferences
  2. Java > Code Style > Formatter
  3. New
  4. Enter a name
  5. Click ok

Control line breaks

  1. Edit the profile
  2. Line wrapping tab
  3. Check “Never join already wrapped lines”

Write a comment