Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 237081 - [typing] Correct indentation wrong after if (test) try ... catch ...
Summary: [typing] Correct indentation wrong after if (test) try ... catch ...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Rajesh CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-13 10:20 EDT by utilisateur_768 CLA
Modified: 2011-09-12 12:18 EDT (History)
3 users (show)

See Also:
deepakazad: review-
deepakazad: review+


Attachments
Patch with test. (3.29 KB, patch)
2011-02-16 00:50 EST, Rajesh CLA
no flags Details | Diff
Patch with tests. (3.83 KB, patch)
2011-02-18 00:01 EST, Rajesh CLA
deepakazad: iplog+
deepakazad: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description utilisateur_768 CLA 2008-06-13 10:20:23 EDT
Build ID: I20080523-0100 

Steps To Reproduce:
1. Copy the code below in a new java editor
2. Select all, and ctrl+I (Correct Indentation)
3. The global assignment statement should be aligned with the "if", while it is aligned with the "try"




More information:
import java.io.File;


public class TestCorrectIndentation {
	private boolean _GLOBAL;

	public void foo() {
		try {
			File file = new File("foo");

			if (file.exists())
				try {
					// do stuff
				} catch (RuntimeException ex) {
					System.err.println("Impossible faire une URL pour le fichier " + file);
				}

				// one level of increment should not be there
				_GLOBAL = _GLOBAL
				&& test();
		} finally {
			// nothing
		}
	}

	private boolean test() {
		// TODO Auto-generated method stub
		return false;
	}
}
Comment 1 Dani Megert CLA 2008-06-13 10:51:20 EDT
Can reproduce using 3.4 RC4.

Simpler test case:

public class Bug237081 {
	public void foo() {
		if (true)
			try {
			} catch (RuntimeException ex) {
			}
			foo();
	}
}
Comment 2 Dani Megert CLA 2011-01-21 04:24:41 EST
Rajesh, please check if this is still the case with your recent patches.
Comment 3 Rajesh CLA 2011-01-24 00:01:31 EST
(In reply to comment #2)
> Rajesh, please check if this is still the case with your recent patches.

Yes, this is a pre-existing issue that is not yet solved by the latest patch.
Comment 4 Rajesh CLA 2011-02-16 00:50:15 EST
Created attachment 189069 [details]
Patch with test.
Comment 5 Dani Megert CLA 2011-02-16 02:59:39 EST
Deepak, please do the first review and make sure we don't introduce the known regressions (see bug 65317 comment 32).
Comment 6 Deepak Azad CLA 2011-02-16 09:24:52 EST
Patch works when there is only a catch block. But what happens if there is a finally block ? :)

---------------------------------------------------------------------
public class Bug237081 {
	public void foo() {
		if (true)
			try {
			} catch (RuntimeException ex) {
			} finally {
			}
			foo();
	}
}
--------------------------------------------------------------------

Please also add a test for the finally case.
Comment 7 Rajesh CLA 2011-02-17 05:46:59 EST
Actually, there is a bigger issue here - that of multiple catch blocks. If the user does ctrl+I on a line which has catch block(s) before it and after it, then the algorithm has to scan not only backwards but also forwards to ascertain where the caret is.
Will need to spend more time on this.
Comment 8 Deepak Azad CLA 2011-02-17 06:29:11 EST
(In reply to comment #7)
> Actually, there is a bigger issue here - that of multiple catch blocks. If the
> user does ctrl+I on a line which has catch block(s) before it and after it,
> then the algorithm has to scan not only backwards but also forwards to
> ascertain where the caret is.
> Will need to spend more time on this.

hmm... I think the patch works fine. Do you have an example code snippet ?
Comment 9 Dani Megert CLA 2011-02-17 08:32:05 EST
(In reply to comment #8)
> (In reply to comment #7)
> > Actually, there is a bigger issue here - that of multiple catch blocks. If the
> > user does ctrl+I on a line which has catch block(s) before it and after it,
> > then the algorithm has to scan not only backwards but also forwards to
> > ascertain where the caret is.
> > Will need to spend more time on this.
> 
> hmm... I think the patch works fine. Do you have an example code snippet ?
I see the same i.e. the patch works fine for multiple catch blocks but not yet for a finally block.
Comment 10 Rajesh CLA 2011-02-18 00:01:25 EST
Created attachment 189249 [details]
Patch with tests.

The earlier comment was in the context of how I was implementing 'finally'. Now its a very simple change from the previous patch and seems to work fine. Also added tests.
Comment 11 Deepak Azad CLA 2011-02-18 00:59:04 EST
Patch is good. Committed to HEAD.
Comment 12 Deepak Azad CLA 2011-02-18 00:59:23 EST
.
Comment 13 Mihai Caraman CLA 2011-09-12 12:15:54 EDT
Build id: 20110218-0911
Problem persists after for,if,while,etc...
Comment 14 Dani Megert CLA 2011-09-12 12:18:18 EDT
(In reply to comment #13)
> Build id: 20110218-0911
> Problem persists after for,if,while,etc...

Please file a new bug if you see this in I20110912-0800 or newer.