Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 404879 - [typing] Regression on auto-insert of {}
Summary: [typing] Regression on auto-insert of {}
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 4.3 M7   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-04 05:24 EDT by Ed Willink CLA
Modified: 2013-04-05 06:20 EDT (History)
2 users (show)

See Also:
daniel_megert: review+


Attachments
Patch (1.75 KB, patch)
2013-04-04 09:21 EDT, Noopur Gupta CLA
daniel_megert: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Willink CLA 2013-04-04 05:24:42 EDT
Up until M6 given source text such as (@ is the cursor position)

     @xxxx

it was possible to insert type

     if (yyyy != null) {@xxxx

then new line to get

     if (yyyy != null) {
        xxxx
     }

Now (in M6) and in eclipse-SDK-I20130402-0800-win32.zip we get

     if (yyyy != null) {
        
     }xxxx

Super-irritating.
Comment 1 Noopur Gupta CLA 2013-04-04 06:02:21 EDT
Reproducible in Build id: I20130326-0800.

Steps to Reproduce:
1. Type: System.out.println();
2. Go to the previous line and type: if(true) {|
3. Press Delete key on keyboard such that the text now is: 
if(true) {|		System.out.println();
4. Press Enter key and the text changes to:
if(true) {
			
		}System.out.println();
Comment 2 Dani Megert CLA 2013-04-04 06:27:17 EDT
Probably caused by fix for bug 395071.
Comment 3 Noopur Gupta CLA 2013-04-04 09:21:11 EDT
Created attachment 229328 [details]
Patch

The bug was caused during the fix for bug 395071, by replacing the condition "if (hasNewToken && openingParen != -1)" with "if (openingParen != -1)". In the earlier condition, hasNewToken was false for this case and hence luckily the corresponding expression was not executed. But hasNewToken was producing incorrect result for other cases mentioned in that bug. 

This bug is present only in the case where we have a pair of '(' and ')' after the position where Enter is pressed. 
Then, openingParen contains the position of '(' from the pair present after the current position and in the next iteration causes the condition "if (openingParen != -1)" to be true. 

However, if we encounter a pair after the current position where Enter is pressed, openingParen should be reset to -1. 

Fixed this and also added a test case in JavaAutoIndentStrategyTest.

Dani, please check.