Bug 249704 - [code assist] autocomplete with anonymous classes does stop working
Summary: [code assist] autocomplete with anonymous classes does stop working
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M7   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-05 11:10 EDT by moormaster Mising name CLA
Modified: 2010-04-26 06:16 EDT (History)
2 users (show)

See Also:
Olivier_Thomann: review+


Attachments
proposed fix v1.0 + regression tests (4.02 KB, patch)
2010-04-06 11:07 EDT, Ayushman Jain CLA
Olivier_Thomann: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description moormaster Mising name CLA 2008-10-05 11:10:43 EDT
Build ID: M20080911-1700

Steps To Reproduce:
1. see the commented lines in the sourcecode and try if autocomplete still works:



import java.util.Arrays;

public class Test
{
	Object obj = new Object()
	{
		public void method()
		{
			Object obj = new Object()
			{
				public void anotherMethod()
				{
					try
					{
						// do something which throws something
					}
					catch (Throwable e)
					{
					}

					Arrays.sort(new String[]{""});
				}

				// until here autocomplete still works
			};
			// from here it doesnt work anymore for the whole rest of this
			// method

			// ...

		}
	};
}




More information:
I was working on a bigger project while detecting this bug... i tried to create a minimal example and this is the result. I have tried to remove some things for example the String constant or the try-catch block... but as soon as I do that the bug does not occur anymore :D
Comment 1 Srikanth Sankaran CLA 2010-03-01 06:19:54 EST
Ayush, please take a look. May have some common ground with
bug# 292087
Comment 2 Ayushman Jain CLA 2010-03-09 05:06:34 EST
The parser doesnt seem to generate the completion node in this scenario. Commenting out either the try catch or the array initializer suddenly makes code assist work. Array initializer in a local declaration statement also doesnt seem to cause any grief.

Will investigate further.Doesnt seem to have much in common with bug# 292087
Comment 3 Ayushman Jain CLA 2010-04-06 11:04:31 EDT
This problem is not due to anonymous type per se. The above reported case is one of the random cases in which this problem can manifest. The problem is as follows:

During the recovery parse when we're inside the array initializer, in CompletionParser.prepareForBlockStatements() called via AssistParser#resumeAfterRecovery(), we prematurely pop elements from elementKindStack and reach upto the enclosing block of the array initializer. So in the above reported case, when we are at the closing brace of the array initializer, the parser thinks that the brace closes the enclosing block instead, and thus pops it off from elementKindStack, even when it shud've popped off the array initializer instead. So we end up in the incorrect scope, and as the subsequent closing braces are encountered, the wrong element is popped each time.

Thus, this problem can occur in cases like above, where there are a number of block delimiters. Notice that any modification in the above example makes content assist work again.
Comment 4 Ayushman Jain CLA 2010-04-06 11:07:07 EDT
Created attachment 163912 [details]
proposed fix v1.0 + regression tests

The fix basically prevents popping a block delimiter when the parser is looking inside the array initializer.

Added test CompletionTest#testBug24970
Comment 5 Olivier Thomann CLA 2010-04-06 15:24:36 EDT
Looks good. I'll release later today.
Comment 6 Olivier Thomann CLA 2010-04-07 08:43:38 EDT
Released for 3.6M7.
Regression test added in:
CompletionTests#testBug249704
Comment 7 Srikanth Sankaran CLA 2010-04-26 06:16:33 EDT
Verified for 3.6M7 using build I20100424-2000