Bug 244820

Summary: Content assist after 'instanceof' should also work in assignment
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert, Olivier_Thomann, srikanth_sankaran
Version: 3.5Flags: srikanth_sankaran: review+
Target Milestone: 3.6 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + updated regression tests srikanth_sankaran: iplog+, srikanth_sankaran: review+

Description Markus Keller CLA 2008-08-21 10:29:40 EDT
I20080812-0800

Content assist after 'instanceof X' should also propose members of type X in assignments or local variable declarations:

	void m(CharSequence cs) {
		String lower= null;
		if (cs instanceof String) {
			cs.to // good
		}
		if (cs instanceof String) {
			return cs.to // good
		}

		if (cs instanceof String) {
			lower= cs.to // bad
		}
		if (cs instanceof String) {
			String low= cs.to // bad
		}
	}

In the 'good' examples, e.g. String#toLowerCase() is proposed. In the 'bad' examples, only methods from CharSequence and Object are proposed.

[BTW: After 'cs.tol', completion currently fails if common prefix completion is enabled, see bug 244818.]
Comment 1 Srikanth Sankaran CLA 2010-03-31 06:11:48 EDT
Ayush, Please take a look. Why is this not a duplicate of
bug# 287939 ? The second bad case cited by Markus works ok
on HEAD while the first one is still broken.
Comment 2 Ayushman Jain CLA 2010-04-14 07:39:59 EDT
(In reply to comment #1)
> Ayush, Please take a look. Why is this not a duplicate of
> bug# 287939 ? The second bad case cited by Markus works ok
> on HEAD while the first one is still broken.

Both cases work correctly using 3.6M6. This can be safely closed as a dup of bug 287939.
Comment 3 Markus Keller CLA 2010-04-14 08:12:22 EDT
By itself, the first of the 'bad' examples works fine in I20100413-1521. But if you take the complete example from comment 0, it still doesn't work. Can we keep this bug for that problem?

The second of the 'bad' examples still works fine.
Comment 4 Ayushman Jain CLA 2010-04-20 05:57:27 EDT
This will be handled along with bug 304006. Added in bug 304005 comment 5

*** This bug has been marked as a duplicate of bug 304006 ***
Comment 5 Ayushman Jain CLA 2010-04-20 05:58:34 EDT
Correction in above comment
Added in bug 304006 comment 5
Comment 6 Srikanth Sankaran CLA 2010-04-20 06:19:28 EDT
Ayush,

Since this test case has no connection to the tests you have in
bug# 304006 comment#0, please provide the fix here rather than
using bug#304006 as an umbrella bug for all instanceof completion
issues.

This will simplify code review, verification and "software 
archeology" in the future should the need arise.
Comment 7 Ayushman Jain CLA 2010-04-20 08:12:04 EDT
Created attachment 165415 [details]
proposed fix v1.0 + updated regression tests

Here because of the existing errors in the compilation unit prior to where the completion is requested, the expressionStack doesnt contain the instanceof expression enclosing the 3rd bad case. This is because the stack is reset during recovery, which in this case starts from after the if (cs instanceof String) statement. So in this case we have to rely on the elementObjectInfoStack to find the instanceof expression. The uncertainty in the recovery mode prevents us from relying on any of the two stacks entirely.
Comment 8 Srikanth Sankaran CLA 2010-04-21 08:07:16 EDT
(In reply to comment #7)
> Created an attachment (id=165415) [details]
> proposed fix v1.0 + updated regression tests

Patch looks good. Released to HEAD for 3.6M7
Comment 9 Srikanth Sankaran CLA 2010-04-26 05:48:25 EDT
Verified for 3.6M7 using build I20100424-2000