Bug 65317 - [typing] Auto-indent does not handle continuation properly
Summary: [typing] Auto-indent does not handle continuation properly
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 normal with 10 votes (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Rajesh CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 72339 75573 107833 108481 130526 153819 322913 332015 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-06-02 10:19 EDT by Anton Tagunov CLA
Modified: 2011-02-20 14:05 EST (History)
11 users (show)

See Also:
daniel_megert: review+


Attachments
My code formatter profile (18.74 KB, text/xml)
2004-06-02 10:25 EDT, Anton Tagunov CLA
no flags Details
Patch (6.05 KB, patch)
2010-09-08 16:25 EDT, Rajesh CLA
no flags Details | Diff
Fix (7.54 KB, patch)
2010-09-20 10:16 EDT, Rajesh CLA
no flags Details | Diff
Fix (7.21 KB, patch)
2010-09-23 06:22 EDT, Rajesh CLA
daniel_megert: review-
Details | Diff
Fix (12.30 KB, patch)
2010-10-04 14:27 EDT, Rajesh CLA
daniel_megert: review+
Details | Diff
Patch (31.57 KB, patch)
2011-01-31 05:18 EST, Rajesh CLA
daniel_megert: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Tagunov CLA 2004-06-02 10:19:50 EDT
Steps:

copy-paste the following fragment

boolean a = true ||
		false;
boolean b = false;


into method a() of the following class:

public class A
{
	void a()
	{
		
	}
}

Observed:

The resulting code identation is

public class A
{
	void a()
	{
		boolean a = true ||
		false;
boolean b = false;
		
	}
}


Expected:

public class A
{
	void a()
	{
		boolean a = true ||
				false;
		boolean b = false;
		
	}
}

Build: 200405280010
Comment 1 Anton Tagunov CLA 2004-06-02 10:25:53 EDT
Created attachment 11464 [details]
My code formatter profile
Comment 2 Kai-Uwe Maetzel CLA 2004-06-02 15:09:52 EDT
3.0 candidate
Comment 3 Kai-Uwe Maetzel CLA 2004-06-25 11:03:00 EDT
Removing target milestone, no further action for 3.0.
Comment 4 Tom Hofmann CLA 2004-07-27 04:49:10 EDT
*** Bug 66390 has been marked as a duplicate of this bug. ***
Comment 5 Tom Hofmann CLA 2004-07-27 04:50:06 EDT
See also bug 66390 for throws clause continuation.
Comment 6 Tom Hofmann CLA 2004-08-20 10:50:27 EDT
*** Bug 72339 has been marked as a duplicate of this bug. ***
Comment 7 Tom Hofmann CLA 2004-08-20 10:50:51 EDT
see also bug 72339 for another continuation case.
Comment 8 Tom Hofmann CLA 2005-02-11 11:49:39 EST
*** Bug 72247 has been marked as a duplicate of this bug. ***
Comment 9 Dani Megert CLA 2005-08-24 09:12:48 EDT
*** Bug 107833 has been marked as a duplicate of this bug. ***
Comment 10 Tom Hofmann CLA 2005-08-31 12:35:00 EDT
*** Bug 108481 has been marked as a duplicate of this bug. ***
Comment 11 Dani Megert CLA 2005-09-02 09:39:24 EDT
*** Bug 108583 has been marked as a duplicate of this bug. ***
Comment 12 Tom Hofmann CLA 2006-03-06 06:36:31 EST
*** Bug 130526 has been marked as a duplicate of this bug. ***
Comment 13 Dani Megert CLA 2006-03-24 11:08:03 EST
Has to be shifted to 3.3.
Comment 14 Tom Hofmann CLA 2006-08-14 08:42:38 EDT
Moving back to inbox.
Comment 15 Tom Hofmann CLA 2006-08-15 04:00:07 EDT
*** Bug 153819 has been marked as a duplicate of this bug. ***
Comment 16 Sergey Prigogin CLA 2006-11-19 20:01:22 EST
Another problematic fragment:

for (int i = 0;
        i < array.length; i++) {
    x = 5;  
}

Observed:

    for (int i = 0;
    i < array.length; i++) {
        x = 5;  
    }

Expected:

    for (int i = 0;
            i < array.length; i++) {
        x = 5;  
    }
Comment 17 Sergey Prigogin CLA 2007-02-26 13:30:56 EST
Could you please schedule this bug to be fixed before 3.3 goes out. People keep running into this problem again and again as the number of duplicate bugs indicates.
Comment 18 Dani Megert CLA 2007-02-27 03:10:31 EST
Sorry, we currently do not have time to work on this but gladly accept a good quality patch.
Comment 19 Dani Megert CLA 2010-08-18 03:48:29 EDT
*** Bug 322913 has been marked as a duplicate of this bug. ***
Comment 20 Rajesh CLA 2010-09-08 16:25:33 EDT
Created attachment 178439 [details]
Patch

This patch seems to handle many of the samples in the various duplicates of this bug (there are a couple such as method declaration that still remain). Markus, can you please provide your comments on the approach/direction of the patch so far.
Comment 21 Rajesh CLA 2010-09-20 10:16:10 EDT
Created attachment 179248 [details]
Fix

This patch covers the common continuation scenarios described in this and other duplicate bugs. Specifically it covers Return statements, Assignments, Comparisons, For loops and a bug with pasting statements containing continuation.
Comment 22 Dani Megert CLA 2010-09-22 08:47:06 EDT
Rajesh, the change causes the IndentActionTest to fail. Also, I quickly tried some examples which did not seem to work. I think the first thing to do, is to list the cases (with examples) that are broken and which we will fix with the patch and also add corresponding tests.
Comment 23 Rajesh CLA 2010-09-23 06:22:59 EDT
Created attachment 179443 [details]
Fix

(In reply to comment #22)
> I think the first thing to do, is to
> list the cases (with examples) that are broken and which we will fix with the
> patch and also add corresponding tests.

Following are the examples for the scenarios that the fix attempts to address -

1. Copy-paste the following fragment, it should indent the same-

boolean a = true ||
		false;
boolean b = false;

2. Copy-paste the following and place the cursor anywhere after 'return' and press Enter. Should indent with 2 tabs(default setting) relative to this line.

private String m() {
	return "I'm such a long string that you have to split me to see the whole line without scrolling around";
}

3. Copy-paste the following fragment and place cursor anywhere between parenthesis and press Enter. Should indent with 2 tabs relative to this line.

int[] array= {1,2,3};
for (int i = 0; i < array.length; i++) {
}

4. Copy-paste the following code it should maintain the indentation. Then place cursor somewhere in the 3rd line and press Enter - should indent correctly. Also, try 'Correct Indentation', it should maintain the indentation.

boolean test(int thisIsAVeryLongName, int anotherVeryLongName) {
	return (thisIsAVeryLongName == 1 && anotherVeryLongName == 1)
			|| thisIsAVeryLongName == 2; // 2 more tabs
}

5. Enter the following and press Enter. Should indent with 2 tabs relative to this line.

int i= 

or 

int i= 5 + 


Also, found a issue with the previous fix - attached new Fix.
Comment 24 Dani Megert CLA 2010-09-30 10:03:26 EDT
Comment on attachment 179443 [details]
Fix

With this patch we get test failures in org.eclipse.jdt.text.tests.JavaHeuristicScannerTest and org.eclipse.jdt.text.tests.IndentActionTest.

Also, please add the new tests for the cases we fix.
Comment 25 Rajesh CLA 2010-10-04 14:27:06 EDT
Created attachment 180194 [details]
Fix

Fixed the test breaks by modifying the tests to test continuation scenarios appropriately. Also, added many new Tests for the supported continuation scenarios.
Comment 26 Dani Megert CLA 2010-10-05 10:43:45 EDT
>Fixed the test breaks by modifying the tests 
I could not see that. Only saw that you deleted some tests which for a reviewer looks like cheating ;-). Can't you adjust those tests?

>org.eclipse.jdt.text.tests.IndentActionTest.
I could not see changes in there but the failure is gone. Why, i.e. what was wrong with the previous patch and what did you change in the "real" code that fixed this?

Also note that your patch introduces compile warnings. Please correct that.
Comment 27 Rajesh CLA 2010-10-06 00:46:02 EDT
(In reply to comment #26)
> >Fixed the test breaks by modifying the tests 
> I could not see that. Only saw that you deleted some tests which for a reviewer
> looks like cheating ;-). Can't you adjust those tests?

I did not delete the tests, they have been adjusted and renamed (previous name didn't make sense anymore)- look at testContinuationIndentation2 to 5. Hope that doesn't fall under cheating :)

> 
> >org.eclipse.jdt.text.tests.IndentActionTest.
> I could not see changes in there but the failure is gone. Why, i.e. what was
> wrong with the previous patch and what did you change in the "real" code that
> fixed this?

The change in the code was in isForStatement method where I removed skipping the scope of a RParen which was a bug under some scenarios.
Comment 28 Dani Megert CLA 2010-10-06 02:35:28 EDT
> I did not delete the tests, they have been adjusted and renamed (previous name
> didn't make sense anymore)- look at testContinuationIndentation2 to 5. Hope
> that doesn't fall under cheating :)
No, but it just makes the reviewer job harder because the compare editor is not able to show this.
Comment 29 Dani Megert CLA 2010-10-06 05:57:19 EDT
Looks good. I've fixed the warnings that your patch introduced.
Available in builds >= N20101006-2000.
Comment 30 Markus Keller CLA 2010-10-26 15:24:43 EDT
Verified in I20101025-1800, reopened dups that have not been fixed yet.
Comment 31 Dani Megert CLA 2010-11-29 11:25:49 EST
Continuation of Method calls is also not working yet (filed bug Bug 331353).
Comment 32 Dani Megert CLA 2010-12-03 03:04:03 EST
All recently made indent fixes had to be reverted due to several regressions (bug 331028, bug 330556 and bug 331734).
Comment 33 Dani Megert CLA 2011-01-28 09:25:20 EST
Committed Rajesh's modified patch (patch will be attached soon).
Comment 34 Rajesh CLA 2011-01-31 05:18:34 EST
Created attachment 187942 [details]
Patch
Comment 35 Deepak Azad CLA 2011-02-11 01:49:42 EST
*** Bug 332015 has been marked as a duplicate of this bug. ***
Comment 36 Deepak Azad CLA 2011-02-11 02:10:39 EST
*** Bug 75573 has been marked as a duplicate of this bug. ***