Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320565 - [editor] Open Declaration (F3) doesn't work for object literals
Summary: [editor] Open Declaration (F3) doesn't work for object literals
Status: RESOLVED WORKSFORME
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5.1   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard: reproduceable
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-21 18:24 EDT by Vladimir Grishchenko CLA
Modified: 2013-07-22 10:36 EDT (History)
4 users (show)

See Also:


Attachments
proposed patch (16.89 KB, patch)
2012-05-16 01:50 EDT, Wooyoung Cho CLA
no flags Details | Diff
testcase (1.46 KB, application/zip)
2012-05-16 01:52 EDT, Wooyoung Cho CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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.