Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331028

Summary: [typing] Indentation broken in enhanced for loop
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: TextAssignee: Dani Megert <daniel_megert>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P2 CC: daniel_megert, deepakazad, rthakkar, ulrich.hobelmann
Version: 3.7   
Target Milestone: 3.7 M4   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Markus Keller CLA 2010-11-24 10:05:40 EST
Broken in M3, HEAD, and in HEAD with patch from bug 330556 comment 8
OK up to at least 3.7 M1.

Auto-indentation is broken when copying lines with Ctrl+Alt+ArrowDown.

Example (using default code formatter):

package p;

import java.util.List;

class A {
	void x() {
		List<? extends Number> nums = getNums();
		for (Number n : nums) {
			Number n2 = (Number) n; // copy with Ctrl+Alt+ArrowDown
			System.out.println(n);
		}
	}

	private List getNums() {
		return null;
	}
}

=> Copied line indented too much:

		for (Number n : nums) {
			Number n2 = (Number) n;
				Number n2 = (Number) n;
Comment 1 Markus Keller CLA 2010-11-24 10:21:55 EST
The copying is not necessary to reproduce. Ctrl+I also indents wrongly:

		for (Number n : nums) {
			Number n2 = (Number) n;
				Number n2 = (Number) n;
				System.out.println(n);
		}
Comment 2 Dani Megert CLA 2010-12-03 03:08:54 EST
I've reverted all recently made indent fixes.
Comment 3 Deepak Azad CLA 2010-12-07 08:19:10 EST
Verified for 3.7M4 with I20101206-1800.
Comment 4 Ulrich Hobelmann CLA 2011-06-03 07:21:24 EDT
The problem also affects for-loops with a single statement instead of a block:

for (Integer id : ids)
    process(id);
        int nextLine;

Using 3.7RC2 here (20110526-1053).

(Does that mean reopen, since it's supposed to be fixed in M4?)
Comment 5 Dani Megert CLA 2011-06-03 07:24:32 EDT
(In reply to comment #4)
> The problem also affects for-loops with a single statement instead of a block:
> 
> for (Integer id : ids)
>     process(id);
>         int nextLine;
> 
> Using 3.7RC2 here (20110526-1053).
> 
> (Does that mean reopen, since it's supposed to be fixed in M4?)

Please file a new bug.