Community
Participate
Working Groups
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.
*** This bug has been marked as a duplicate of 59891 ***
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 ***
Verified for 3.6M5 using build I20100122-0800