| Summary: | [1.7] Ugly formatting for try with resources | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Deepak Azad <deepakazad> | ||||
| Component: | Core | Assignee: | Ayushman Jain <amj87.iitr> | ||||
| Status: | VERIFIED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | amj87.iitr, daniel_megert, jarthana, markus.kell.r, satyam.kandula | ||||
| Version: | 3.7 | ||||||
| Target Milestone: | 3.7.1 | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
(In reply to comment #0) > [..] > 2 things > - Closing { of the try block should be aligned with 'try' Yes. > - Indentation of reader3 and reader 4 should probably be same as reader 2 Not really. Try a method declaration with each parameter defined in a new line. Will investigate. (In reply to comment #1) > > - Indentation of reader3 and reader 4 should probably be same as reader 2 > Not really. Try a method declaration with each parameter defined in a new line. Actually, the 'Line wrapping' tab in the formatter preferences defines the different ways a parameters in a method declaration should be wrapped. We should define similar settings for try with resources. Even then we will need to choose a default line wrapping policy, and I think it should correspond to 'Indentation of reader3 and reader 4 should probably be same as reader 2'. Created attachment 197976 [details]
proposed fix v1.0 + regression tests
This fix corrects the indentation issue. Resources are indented such that r3 and r4 have same indentation as r2, and the try block and following brackets are also correctly indented.
I will open a separate bug for line wrapping options
Released in BETA_JAVA7 branch. Opened bug 349396 for a new line wrapping option Verified |
With the default formatter settings format the following code. ---------------------------------------------------------------------------- void foo() throws Throwable { try (FileReader reader1 = new FileReader("file1"); FileReader reader2 = new FileReader("file2"); FileReader reader3 = new FileReader("file3"); FileReader reader4 = new FileReader("file4")) { int ch; while ((ch = reader1.read()) != -1) { System.out.println(ch); } } } ---------------------------------------------------------------------------- 2 things - Closing { of the try block should be aligned with 'try' - Indentation of reader3 and reader 4 should probably be same as reader 2 Indenter (Ctrl+I) is a bit better than the formatter in this case.