| Summary: | [ast rewrite] strange formatting after change to enhanced for loop | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Martin Aeschlimann <martinae> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | deepakazad, markus.kell.r, satyam.kandula |
| Version: | 3.2 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
HEAD, probably a similar problem as bug 350285 - new workspace - paste into Package Explorer: package test1; import java.util.Iterator; import java.util.List; public class E { public void m(List<? extends Number> nums) { for (Iterator<? extends Number> iterator = nums.iterator(); iterator .hasNext();) { Number number = iterator.next(); System.out.println(number.doubleValue()); // comment System.out.println(number.doubleValue()); } } } - format the whole CU (using the default profile) - put caret into 'for' - apply quick assist "Convert to enhanced 'for' loop" => result has non-indented body statements: public class E { public void m(List<? extends Number> nums) { for (Number number : nums) { System.out.println(number.doubleValue()); // comment System.out.println(number.doubleValue()); } } } The problem does not occur when the entire "for (...) {" header is on a single line. In ConvertIterableLoopOperation#convert(..) line 314, we set the body of the new EnhancedForStatement to the result of ASTRewrite#createMoveTarget(..). I suspect the ASTRewrite gets confused because the indentation of the starting line of the block is larger than the indentation of the body statements. In the original string, the line where the blocks starts has an indentation of 4. In the modified string, the line where the block starts has an indentation of 2. Thus, the indentation logic thinks that the code needs to be moved left by 2 and so the problem. (In reply to comment #2) Test case provided at bug 350285 comment 12 fails for the same reason as this. This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
20050920-0010 code in attachment 26800 [details] results in public void endTest(Test test) throws CloneNotSupportedException { for (TestListener nextElement : cloneListeners()) { nextElement.endTest(test); } }