Bug 310747 - [content assist] Irrelevant proposals while completing inside array initializer.
Summary: [content assist] Irrelevant proposals while completing inside array initializer.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-28 00:58 EDT by Srikanth Sankaran CLA
Modified: 2011-03-08 08:50 EST (History)
1 user (show)

See Also:
srikanth_sankaran: review+


Attachments
proposed fix v1.0 + regression tests (7.08 KB, patch)
2010-05-13 07:19 EDT, Ayushman Jain CLA
no flags Details | Diff
patch updated for HEAD (6.89 KB, patch)
2011-02-03 11:41 EST, Ayushman Jain CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2010-04-28 00:58:44 EDT
3.6M7

Follow up of bug# 292087

public class Test {
    private Runnable member[] = {
        // completion here brings up useless proposals
    };    
}

In the snippet above, completing at the indicated point
proposes the methods of java.lang.Object. Choosing these
proposals will immediately result in an error and as such
make no sense there.
Comment 1 Srikanth Sankaran CLA 2010-04-28 01:02:41 EDT
Ayush please investigate - What makes sense here ?
See also bug# 292087 comment# 9 -- Thanks.
Comment 2 Ayushman Jain CLA 2010-05-13 07:19:13 EDT
Created attachment 168368 [details]
proposed fix v1.0 + regression tests

There are precisely 2 problems in this case:
1) Random strings from the comment line that follows the position where we're asking for completion are being proposed. This happens due to the incorrect modification of CompletionScanner$currentPosition and CompletionScanner$startPosition in AssistParser.moveRecoveryCheckPoint(). The root cause of this lies in the incorrect setting of CompletionParser$lastCheckPoint at CompletionParser.buildMoreCompletionContext : 878. 
What happens is - currently on encountering the completion token inside array initializer, the currentPosition points to the position of the token after the completion token ie. points to '/'. When the above mentioned line in buildMore.. sets the lastCheckPoint to this position and recovery restarts, AssistParser.moveRecoveryCheckPoint() advances the scanner by one token, and the old position is taken using lastCheckPoint. Due to this the scanner now points ahead of the first '/' of the line comment(It should actually point AT the '/'), in effect skipping the first '/' entirely. Because of this missed token the parser is not able to determine that the second '/' marks the starting of the line comment and goes ahead to ACTUALLY PARSE THE COMMENT ITSELF! 
So the fix for this is to just get rid of the offending line in buildMore...()

2) The proposals are not sorted according to the expected type, leading to useless proposals showing up first and useful ones down in the list. The fix for this is in CompletionEngine.computeExpectedTypes(). It is clear from line 3388 that we are ignoring adding expected types if the variable initialization is an array initializer. The fix takes care to add the relevant expected type in this case also.
Comment 3 Srikanth Sankaran CLA 2010-05-19 05:23:19 EDT
Patch looks good. Targetting 3.7 M1.
Comment 4 Ayushman Jain CLA 2011-02-03 11:41:11 EST
Created attachment 188253 [details]
patch updated for HEAD
Comment 5 Ayushman Jain CLA 2011-02-03 11:43:51 EST
Released in HEAD for 3.7M6
Comment 6 Olivier Thomann CLA 2011-03-07 11:19:40 EST
I still get some weird proposals. Reopening to get clarifications.
Comment 7 Ayushman Jain CLA 2011-03-08 00:52:01 EST
(In reply to comment #6)
> I still get some weird proposals. Reopening to get clarifications.

The problem, when reported, was that in the case given in comment 0, we used to get bogus proposals, which included words from within the comment " // completion here brings up useless proposals". So one would see proposals like "completion", "here", "brings", etc.  With the fix, we don't get these anymore. There are some extra proposals here because there's nothing precise to propose in this case.
OTOH, if you try

public class Test {
	public Test memberGet() {
		return new Test();
	}
	public Test memberField;
    private Test member[] = {
    		
        // complete here
    };    
}

you would now get memberField, and memberGet as the topmost proposals, which is correct. Again, there are some other proposals of the type Object, but thats ok.

Let me know if you observed some other weird behaviour
Comment 8 Olivier Thomann CLA 2011-03-08 08:49:53 EST
Then closing as fixed.
Comment 9 Olivier Thomann CLA 2011-03-08 08:50:05 EST
Verified for 3.7M6.