Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331551 - [typing] Enter before right parenthesis indents differently from Ctrl+I
Summary: [typing] Enter before right parenthesis indents differently from Ctrl+I
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Rajesh CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 10:04 EST by Rajesh CLA
Modified: 2011-02-08 11:25 EST (History)
2 users (show)

See Also:
deepakazad: review+


Attachments
Patch (2.56 KB, patch)
2011-02-04 10:21 EST, Rajesh CLA
no flags Details | Diff
Patch (1.02 KB, patch)
2011-02-08 01:13 EST, Rajesh CLA
no flags Details | Diff
Patch with tests. (2.36 KB, patch)
2011-02-08 08:15 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 Rajesh CLA 2010-12-01 10:04:43 EST
Pressing enter before ')' indents the new line, but using Ctrl-I on the new line removes the indent. NewLine and Ctrl-I should show consistent indentation.
Comment 1 Dani Megert CLA 2010-12-01 11:38:54 EST
Test Case 1:
1. paste
----------%<----------
	int foo() {
		return "".length();
	}
----------%<----------
2. place caret after '(' on the return line
3. press 'Enter'
4. Ctrl+I
==> indent gets destroyed


Test Case 2:
1. paste
----------%<----------
public class Test {
	private void helper2(boolean[] booleans) {
		if (booleans[0]) {

		}
	}
}
----------%<----------
2. place caret before ')' on the if line
3. press 'Enter'
4. Ctrl+I
==> indent gets destroyed
Comment 2 Rajesh CLA 2011-02-04 10:21:45 EST
Created attachment 188325 [details]
Patch

Besides adding a new test, I have modified 'testAnonymousIndentation2' in JavaHeuristicScannerTest.java.
Comment 3 Dani Megert CLA 2011-02-07 03:48:26 EST
Deepak, please make the first review.
Comment 4 Deepak Azad CLA 2011-02-07 07:44:09 EST
Rajesh, is there a reason for this check "if ((line != -1) && (line != fLine))" ? 

The tests pass with the following code, and I cannot think of a case where this would fail.
-----------------------------------------------------------------------
if (matchParen) {
	if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
		fIndent= fPrefs.prefContinuationIndent;
		return fPosition;
	} else {
-----------------------------------------------------------------------
Comment 5 Rajesh CLA 2011-02-08 01:13:13 EST
Created attachment 188497 [details]
Patch

(In reply to comment #4)
> Rajesh, is there a reason for this check "if ((line != -1) && (line != fLine))"
> ? 
> 
> The tests pass with the following code, and I cannot think of a case where this
> would fail.
> -----------------------------------------------------------------------
> if (matchParen) {
>     if (skipScope(Symbols.TokenLPAREN, Symbols.TokenRPAREN)) {
>         fIndent= fPrefs.prefContinuationIndent;
>         return fPosition;
>     } else {
> -----------------------------------------------------------------------

Being over cautious and trying to be sure that it is a continuation scenario. But the following 2 lines (785/786) in the execution path already ensure this which is why none of the potential failure cases never occur - 

"if (isFirstTokenOnLine)
		matchParen= true;"

Thx. New patch removes the check.
Comment 6 Deepak Azad CLA 2011-02-08 06:43:29 EST
(In reply to comment #5)
> Created attachment 188497 [details] [diff]
> Patch

Please attach a patch with tests included. 

+1 for the fix.
Comment 7 Rajesh CLA 2011-02-08 08:15:52 EST
Created attachment 188512 [details]
Patch with tests.
Comment 8 Deepak Azad CLA 2011-02-08 08:46:51 EST
(In reply to comment #7)
> Created attachment 188512 [details] [diff]
> Patch with tests.

Committed to HEAD.
Comment 9 Deepak Azad CLA 2011-02-08 08:48:37 EST
.
Comment 10 Dani Megert CLA 2011-02-08 11:25:32 EST
Thanks for the patch Rajesh.