Bug 218857 - Java indentation - statement following a=b?c():d;
Summary: Java indentation - statement following a=b?c():d;
Status: RESOLVED DUPLICATE of bug 65463
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-13 15:02 EST by Gary CLA
Modified: 2008-02-15 03:11 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 Gary CLA 2008-02-13 15:02:09 EST
Build ID: M20071023-1652

Steps To Reproduce:
 Notice the "x = y;" and return lines.  They are indented as if they was inside the previous statement.  Select the entire method and hit Control-I to reindent the selection.  If you remove the "()" from the q function call then the indentation becomes correct again.

    public int lineCount () {

        e  =
            c
            ? q () 
            : a;

            x = y;

            return lines.size ();
    }

More information:
Comment 1 Martin Aeschlimann CLA 2008-02-14 03:49:01 EST
Can you give exact steps how you came to this code? Did you use 'Format' or 'Correct Indentation'?
Comment 2 Gary CLA 2008-02-14 12:48:31 EST
The way I write Java code is,
   <characters...><Enter-key><Tab-key>
   <characters...><Enter-key><Tab-key>
   ...
and so on.  I rarely use Control-I (reindents a selected region).  I do 99.9% of everything with just the Tab key.  (I use the Emacs bindings if that makes a difference.)

The Format operation, which according to the Preference pages is bound to Control-Shift-F is an operation I didn't know existed until you mentioned it.

I don't see a Correct Indentation operation on the Keys Preference page so I don't know which operation that would be.  The two formatting operations I use are the ones bound to Tab and to Control-I.  To reindent a region I usually do,
    <tab><beginning-of-line><next-line>
    <tab><beginning-of-line><next-line>
    ...
rather than selecting a region and typing Control-I to reindent the entire region.

I discovered this example by simply noticing the problem as I was typing it in (I was using names like regionStartOffset rather than names like "b" but...).  When I got to the line where I wanted to type "x = y;" I hit the Tab and noticed that the cursor was in the wrong place.  I went ahead and typed in the "x = y;" and tried to reindent the line with <beginning-of-line><Tab> and it stayed where it was.  I played with it, couldn't get it to stay at any other column, and finally decided it was an indentation bug and not a syntax mistake like a forgotten ")" or something.  Then I started simplyfying the code.  I removed comments, made all of the identifiers single letters, turned complex expressions like a+b+c into single names like c, eliminated function call parameter, etc. until I ended up with the simple example I sent in.
Comment 3 Martin Aeschlimann CLA 2008-02-14 12:53:37 EST
That's 'Source > Correct Indentation'
Comment 4 Dani Megert CLA 2008-02-15 03:11:11 EST

*** This bug has been marked as a duplicate of bug 65463 ***