Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 349008 - [1.7] Ugly formatting for try with resources
Summary: [1.7] Ugly formatting for try with resources
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-10 06:15 EDT by Deepak Azad CLA
Modified: 2011-08-05 02:54 EDT (History)
5 users (show)

See Also:


Attachments
proposed fix v1.0 + regression tests (2.91 KB, patch)
2011-06-14 15:49 EDT, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-06-10 06:15:19 EDT
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.
Comment 1 Ayushman Jain CLA 2011-06-10 06:46:22 EDT
(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.
Comment 2 Deepak Azad CLA 2011-06-10 07:17:25 EDT
(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'.
Comment 3 Ayushman Jain CLA 2011-06-14 15:49:21 EDT
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
Comment 4 Ayushman Jain CLA 2011-06-15 01:23:51 EDT
Released in BETA_JAVA7 branch.

Opened bug 349396 for a new line wrapping option
Comment 5 Jay Arthanareeswaran CLA 2011-06-27 06:23:36 EDT
Verified