Bug 152444 - [formatter] Source Formatter could not format chain-style method call correctly
Summary: [formatter] Source Formatter could not format chain-style method call correctly
Status: VERIFIED DUPLICATE of bug 198074
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 3.5 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-01 06:01 EDT by yuhao CLA
Modified: 2010-01-25 01:49 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yuhao CLA 2006-08-01 06:01:02 EDT
Some libraries, such as builder classes in Apache Common-Lang project, use chain style method to simplify code, like following:

return new ToStringBuilder( this )
 	.append( "name", getName() )
 	.append( "category", getCategory() )
 	.append( "download", getDownloadUrl() )
 	.append( "detail", getDetailUrl() )
 	.append( "publisher", getPublisher() )
 	.append( "time", getPublishTime() )
 	.append( "users", getUsers() )
 	.toString();

In the code, each method call is on a new line. clearly as it is. But when using Eclipse JDT source editor to format this code, it is formatted into such an ugly like:
 
return new ToStringBuilder( this ).append( "name", getName() ).append(
"category", getCategory() ).append( "download", getDownloadUrl() )
.append( "detail", getDetailUrl() ).append( "publisher",
getPublisher() ).append( "time", getPublishTime() ).append(
"seeds", getSeeds() ).append( "users", getUsers() ).toString();

 
I've studied options on Preferences -> Java -> Code Style -> Formatter page, but there seemed that nothing is used to determine whether you can put each chain-style method call on a new line.

I know that there may be questions about what means "chain-style". For example, the following code

getWorkbenchWindow().getActivePage().openEditor( ... )

This may be looked as a chain-style; but, as it isn't a very long statement, and could be filled in a single line, so this code can be formatted as normal.

There is a another way that I prefer: I enter some special markers in my code, and Eclipse source formatter could ignore formatting when it found these markers----Then I'm responsible for format the code by hand. e.g:

// @region(do-not-format)
return new ToStringBuilder( this )
 	.append( "name", getName() )
 	....
// @end-region

Anyway, my wish is there should be some way to support chain-style coding.
Comment 1 Olivier Thomann CLA 2006-08-14 11:50:58 EDT

*** This bug has been marked as a duplicate of 59891 ***
Comment 2 Frederic Fusier CLA 2010-01-08 10:46:42 EST
Since 3.5, you can use the 'Never Join Lines' preference on the 'Line Wrapping' tab to keep untouched by the formatter such code pattern.

*** This bug has been marked as a duplicate of bug 198074 ***
Comment 3 Srikanth Sankaran CLA 2010-01-25 01:49:26 EST
Verified for 3.6M5 using build I20100122-0800