Bug 308980 - [content assist]An initializer inside a non-array field declaration confuses content assist
Summary: [content assist]An initializer inside a non-array field declaration confuses ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M7   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 310187 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-04-13 06:30 EDT by Ayushman Jain CLA
Modified: 2010-04-26 04:45 EDT (History)
2 users (show)

See Also:
srikanth_sankaran: review+


Attachments
proposed fix v1.0 + regression tests (16.27 KB, patch)
2010-04-13 13:40 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v1.0 + updated regression tests (16.55 KB, patch)
2010-04-20 05:31 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v2.0 + regression tests (18.75 KB, patch)
2010-04-21 15:53 EDT, Ayushman Jain CLA
srikanth_sankaran: iplog+
srikanth_sankaran: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2010-04-13 06:30:57 EDT
Build Identifier: 3.6M6

In the following cases, try invoking content assist after the |

1) public class Test {
     int field1 = 1;
     int abc = new int[]{fie|
   }

2) public class Test {
     public static final AClass a1 = new AClass(
		new byte[][] {\n" +
		{0x00,0x3C},{0x04,0x2C}});
     public static final AC| " +
   }		
 class AClass{
	public byte[][] field1;
	public AClass(byte[][] byteArray) {
		field1 = byteArray;
	}
 }

Content Assist doesnt work in both cases.

Reproducible: Always

Steps to Reproduce:
1.Use any of the two cases above
2.Invoke content assist via CTRL-SPACE.
3.See that expected proposals dont turn up
Comment 1 Ayushman Jain CLA 2010-04-13 13:40:46 EDT
Created attachment 164755 [details]
proposed fix v1.0 + regression tests

The problem is that in RecoveredField#updateOnOpeningBrace(), the logic does not consider the case that an initializer might occur inside a field declaration even if the field is not an array type. At present, we close the field declaration when we encounter the initializer and attach the initializer to the parent type instead. So an initializer in a field declaration ends up as an initializer in the parent type.

The problem manifest in the AST obtained after diet parse (if it enters recovery), and also when content assist is invoked after the declaration of a field containing an initializer.

The patch addresses these issues. The change in RecoveredField#updateOnClosingBrace is necessary to ensure that we dont set the field to have been initialized even if we're still in the declaration (declarationSourceEnd is not set until the field declaration is not exited completely).
Some tests in CompletionParserTest2 and DietRecoveryTest had to be remastered.
Comment 2 Ayushman Jain CLA 2010-04-13 13:43:38 EDT
Btw, I'd mentioned "local variable" in the bug title by mistake. This problem is only in case of field declarations.
Srikanth can you please review? Thanx!
Comment 3 Srikanth Sankaran CLA 2010-04-19 05:04:49 EDT
(In reply to comment #0)
> Build Identifier: 3.6M6


> Content Assist doesnt work in both cases.

Actually it does work as expected on HEAD. Ayush, please post
the correct test and rework the patch as needed.
Comment 4 Ayushman Jain CLA 2010-04-20 05:27:46 EDT
> Actually it does work as expected on HEAD. Ayush, please post
> the correct test and rework the patch as needed.

Sorry i gave the wrong test case.

The one to reproduce the problem is :


public class Try {
	public static final AClass a1 = new JustTry(
										           new byte[][] {
										           {0x00,0x3C},
										           {0x04,0x2C}}) {
											       int justReturn(int a) {
												   return a;
											       }
										       };
       public static final AC |
}
class AClass{
		public byte[][] field1;
		public AClass(byte[][] byteArray) {
			field1 = byteArray;
		}
}

abstract class JustTry extends AClass{
	public byte[][] field1;
	JustTry(byte[][] byteArray){
		field1 = byteArray;
	}
	abstract int justReturn(int a);
}


Also for the case 1, we do get the completion, but we dont get the correct completion AST.

Changes in CompletionParserTest2 reflect all the places where an initializer bracket inside a non array field initializer would make the parser skip out the completion node from the AST. Eg:
public class X {
	Object o = new X[]{zzz;
}

would give us
public class X {
	Object o ;
        {
        }
        public X(){}
}.
Comment 5 Ayushman Jain CLA 2010-04-20 05:31:12 EDT
Created attachment 165399 [details]
proposed fix v1.0 + updated regression tests

Updated the regression test in CompletionTests
Comment 6 Ayushman Jain CLA 2010-04-21 15:53:39 EDT
Created attachment 165632 [details]
proposed fix v2.0 + regression tests

the above fix was only for SingleTypeReferences. So, on Srikanth's suggestion, extending it for all non-array type reference cases.
Comment 7 Srikanth Sankaran CLA 2010-04-22 00:39:33 EDT
Released in HEAD for 3.6M7
Comment 8 John Cortell CLA 2010-04-23 13:37:14 EDT
*** Bug 310187 has been marked as a duplicate of this bug. ***
Comment 9 Srikanth Sankaran CLA 2010-04-26 04:45:42 EDT
Verified for 3.6M7 using build I20100424-2000