Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320565

Summary: [editor] Open Declaration (F3) doesn't work for object literals
Product: [WebTools] JSDT Reporter: Vladimir Grishchenko <vladgri>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: RESOLVED WORKSFORME QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cmjaun, hyukmin0530.kwon, jaeheung.kim, kgurals
Version: unspecified   
Target Milestone: 3.5.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: reproduceable
Attachments:
Description Flags
proposed patch
none
testcase none

Description Vladimir Grishchenko CLA 2010-07-21 18:24:33 EDT
Build Identifier: I20100608-0911

F3 doesn't jump to method or property declared inside object literals.

var ol = {
		prop1: 'prop1val',
		prop2: 'prop2val',
		method: function() {
			return this.prop1 + this.prop2;
		}
};

ol.prop1;      //F3 doesn't work
ol.prop2;      //F3 doesn't work
ol.method();   //F3 doesn't work
ol.toString(); //F3 works

Reproducible: Always
Comment 1 Wooyoung Cho CLA 2012-05-16 01:50:11 EDT
Created attachment 215687 [details]
proposed patch

This patch changes the hashCode() and equals() of anonymous type so that element info can be found correctly from model cache.

Anonymous types are implicitly generated from object literals and their parents are set to the variable that the object is assigned to. Unlike anonymous types, parents of other types(generated by constructors) are just compilation units. Open Declaration checks whether the type exists by searching element from model cache(HashMap) with element(SourceType) as the key. But parent object of the SourceType is set to compilation unit not the variable element and it fails to find element info.
Current hashCode() and equals() compares two elements by comparing all parents. But at least anonymous types, only comparing type name is enough because their names are determined uniquely like __anonymous_xxx. This patch fixes this and searching model cache succeeds.

After applying this patch, open declaration for fields will be worked due to the method binding problem of #378432. The proposed patch for #378432 will also fix open declaration of methods.

#325377 is also related with this bug. This patch will fix some part(maybe hover) of #325377.
Comment 2 Wooyoung Cho CLA 2012-05-16 01:52:01 EDT
Created attachment 215688 [details]
testcase

The patch includes testcases for open declarations. This zip file is required to run the tests.
Comment 3 Chris Jaun CLA 2013-07-22 10:36:56 EDT
This is working now in WTP 3.5.1, without having to apply the attached patch. Checked against the 7/18 build.