Bug 284789 - [formatter] Does not line-break method declaration exception with parameters
Summary: [formatter] Does not line-break method declaration exception with parameters
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 303773
  Show dependency tree
 
Reported: 2009-07-27 13:55 EDT by Colm Smyth CLA
Modified: 2010-03-09 04:59 EST (History)
5 users (show)

See Also:


Attachments
Possible patch (12.18 KB, patch)
2010-02-19 11:09 EST, Frederic Fusier CLA
no flags Details | Diff
New proposed patch (22.17 KB, patch)
2010-02-23 05:22 EST, Frederic Fusier CLA
no flags Details | Diff
New proposed patch + doc (25.07 KB, patch)
2010-02-23 10:00 EST, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Colm Smyth CLA 2009-07-27 13:55:42 EDT
Build ID: 3.4.2

Steps To Reproduce:
1. Enter a method that returns a type with a long name, such as one based on generics e.g. public synchronzied List<FantasticallyWonderfulContainer<FantasticallyWonderfulClass>> getMeTheFantasticContainer()
2. Use Source/Format to reformat the method declaration
3. The line will not break at any of the keywords (public synchronized etc.) or within the return type (e.g. before the "<" of the generic type) or before the name of the method.

All of the points listed in 3 should be valid break points when line-breaking. This ensures that code formatted by Eclipse will meet coding standards, such as those enforced by CheckStyle


More information:
Comment 1 Frederic Fusier CLA 2010-02-19 11:09:08 EST
Created attachment 159574 [details]
Possible patch

This simplest patch which easily fixes the problem.

It only adds possible line break at the following positions of the method declaration:
1) after the modifiers
2) after the type parameters if any
3) after the return type
4) after the method name

The proposed wrapping is not configurable and always indent the wrapped line at the same column than the method declaration start.

E.g., the following snippet:
public interface X {
public List<SampleContainer<SampleClass>> getSampleContainer();
}
would be formatted as follow with a max line width=40:
public interface X {
    public
    List<SampleContainer<SampleClass>>
    getSampleContainer();
}

Would this proposal address your needs or would you need the wrapping configurable through the formatter preferences?
Comment 2 Frederic Fusier CLA 2010-02-22 11:00:40 EST
Talking with Olivier about this, we decided to add a new preferences for this behavior to let user decide what kind of wrapping he/she wants around these new points of breakage in the method declaration...

I'll be back soon with a new patch.
Comment 3 Frederic Fusier CLA 2010-02-23 05:22:50 EST
Created attachment 159906 [details]
New proposed patch

This patch adds a new formatter option to control the wrapping of the method declaration. Note that it also removes the break after the method name which looked a little bit weird after having made some tests...
Comment 4 Frederic Fusier CLA 2010-02-23 10:00:02 EST
Created attachment 159929 [details]
New proposed patch + doc

Same patch than the previous one + add an entry in the build notes...
Comment 5 Frederic Fusier CLA 2010-02-23 10:14:40 EST
(In reply to comment #4)
> Created an attachment (id=159929) [details]
> New proposed patch + doc
> 
Released for 3.6M6 in HEAD stream.
Comment 6 Srikanth Sankaran CLA 2010-03-09 04:59:45 EST
Verified for 3.6M6 using build I20100305-1011