Bug 28987 - [formatting] Continuation indent support
Summary: [formatting] Continuation indent support
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 enhancement with 4 votes (vote)
Target Milestone: 3.3 RC4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 38822 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-01-03 16:22 EST by Brian Pontarelli CLA
Modified: 2007-06-22 12:46 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Pontarelli CLA 2003-01-03 16:22:55 EST
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);
    }
}
Comment 1 Brian Pontarelli CLA 2004-05-12 14:14:56 EDT
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.
Comment 2 Denis Haskin CLA 2005-03-20 08:08:14 EST
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.
Comment 3 Tom Hofmann CLA 2005-05-31 10:15:14 EDT
*** Bug 38822 has been marked as a duplicate of this bug. ***
Comment 4 Tom Hofmann CLA 2005-05-31 10:23:39 EDT
moving to jdt-core for comments / closing
Comment 5 Olivier Thomann CLA 2005-08-31 10:46:25 EDT
Continuation indent support is in since 3.0. This is out of date.
Ok to close?
Comment 6 David Jackman CLA 2005-08-31 10:49:59 EDT
(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?
Comment 7 Olivier Thomann CLA 2005-08-31 10:56:02 EDT
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.
Comment 8 David Jackman CLA 2005-08-31 11:11:26 EDT
(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).
Comment 9 Jonathan Edwards CLA 2005-08-31 11:37:19 EDT
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);
Comment 10 Tom Hofmann CLA 2005-08-31 11:48:45 EDT
(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.
Comment 11 Jonathan Edwards CLA 2005-08-31 12:09:13 EDT
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.
Comment 12 Olivier Thomann CLA 2007-06-21 10:41:40 EDT
No action plan for more continuation indent support.