Community
Participate
Working Groups
The JDT is lacking any continuation indent support which is not only part of the Sun Java coding standards, but also very common in most editors. Continuation indent is the indentation of statements that span multiple lines. This normally means when a carriage return is encountered and the last non- whitespace character in the buffer (model, whatever is storing the text) is not a '{' or ';' character. Most commonly, statements are broken directly after the '=', ';', ')', '.' or ',' characters, after or before the '||', '&&', '|', '&' or '!' operators, after or before keywords like 'extends', 'throws', 'implements', etc. I'll use a notation where I show a snippet of code labeled before and a snippet of code labeled after. The before code is roughly what a long statement would look like. The after code is what the statement should look like after the developer breaks the statement to multiple lines and continuation indentation has taken place. For most examples, I'll provide one example with the before statement broken into two lines and second example witht eh before statement broken into three lines. Normally, continuation indent has multiple settings. These are something like this: Continuation indent to current indent level ------------------------------------------- before-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after 2-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } Continuation indent by current indent amount -------------------------------------------- before-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after 2-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } Continuation indent to current indent amount except deep indent methods ----------------------------------------------------------------------- before-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after 2-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } Continuation indent to a specific amount (2 spaces) --------------------------------------------------- before-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } after 2-> myMethod() { someClass.someMethod(variable1, variable2, "literal1", "literal2"); } Continuation indent based on parenthesis ---------------------------------------- before-> myMethod() { someClass.someMethod(someLocalMethod(variable1, "literal1"), "literal2"); } after-> myMethod() { someClass.someMethod(someLocalMethod(variable1, "literal1"), "literal2"); } after 2-> myMethod() { someClass.someMethod( someLocalMethod(variable1, "literal1"), "literal2"); } Select continuation indent by keyword (here the throws keyword is not continuation indented) ---------------------------------------------------------------------- before-> myMethod(String param1, String param2) throws MyException { someLocalMethod(); } after-> myMethod(String param1, String param2) throws MyException { someLocalMethod(); } after 2-> myMethod(String param1, String param2) throws MyException { someLocalMethod(); } Continuation indent double on method parameters and if statements (this follows Sun's coding standards) ------------------------------------------------------------------------------- before-> myMethod(String param1, String param2) throws MyException { someLocalMethod(); } after-> myMethod(String param1, String param2) throws MyException { someLocalMethod(); } another before-> myMethod(String param1, String param2) throws MyException { if (param1.equals("1") && param2.equals("2")) { someLocalMethod(param1, param2); } } another after-> myMethod(String param1, String param2) throws MyException { if (param1.equals("1") && param2.equals("2")) { someLocalMethod(param1, param2); } }
I'm not certain if this PR is tracking the new 'Code Formatter' configuration page in the JDT preferences. But here is some feed back that I have. I have the 200404220800 build. 1. The indentation policy could be a bit more flexible. The options that would be nice to have are 'no indent' and 2-N indents (where N = column width / indent size). 2. The dialog is split 50% for the options and 50% for the preview. This might be easier to use if it were a fixed width for the options (which have a fixed width) and expandable for the preview. Other than those comments, I really like the new feature. It is extremely flexible and powerful. A big win for Eclipse's JDT over other IDEs in my opinion. Thanks for putting this in.
It would also be very good to have some support for the chained method syntax that some APIs prefer (for example, jmock.org). (I know this can be a controversial issue for some people.) But for example, the jmock call: mockSubscriber.expects(once()).method("receive").with( eq(message) ).will(returnValue(true)); is typically formatted: mockSubscriber.expects(once()).method("receive") .with( eq(message) ) .will(returnValue(true)); but Eclipse won't do this and insists on doing this: mockSubscriber.expects(once()).method("receive") .with( eq(message) ) .will(returnValue(true)); which is much hardder to read.
*** Bug 38822 has been marked as a duplicate of this bug. ***
moving to jdt-core for comments / closing
Continuation indent support is in since 3.0. This is out of date. Ok to close?
(In reply to comment #5) > Continuation indent support is in since 3.0. This is out of date. > Ok to close? There are suggestions here for indentation rules/options that aren't addressed in the current version. Should these be re-submitted as new requests?
The description of continuation indent in the java conventions is that it is used to reduce misunderstanding in the code indentation. I don't see how we could expose that many different continuation indent and keep the code formatter preference page simple enough for the user.
(In reply to comment #7) > The description of continuation indent in the java conventions is that it is > used to reduce misunderstanding in the code indentation. That's not very clear. Are you saying the code continuation indentation options currently available are based on some existing Java standard that's published somewhere? > I don't see how we could expose that many different continuation indent and keep > the code formatter preference page simple enough for the user. I disagree. The current formatter preference page is organized and laid out well enough that adding additional options would not raise the complexity much, if at all. I don't think we're talking about an infinite number of options, but some additional rules that aren't covered in the current rules. Maybe the thing to do is have each proposed rule/option submitted separately rather than trying to deal with them here (especially since the main point of this request has been addressed).
There are some glaring cases where the existing indentation rules are clearly broken. For example: a = b + c; for (int i = 0; i < 1; i++); i = (true ? 1 : 0);
(In reply to comment #9) I believe you are confusing the formatter and the auto-indenter. This bug is about formatter problems (does it happen when using Source>Format?). See bug 65317 for continuation problems with auto-indentation.
Well, my original report of this problem was marked as a duplicate of this bug, which is why I am here. 65317 is about smart paste, which is not obviously the same thing. These problems occurs whenever you hit TAB to "Correct Indentation". I will just resubmit this as a new bug.
No action plan for more continuation indent support.