Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317270 - [InferEngine] Support different names pointing to the same object
Summary: [InferEngine] Support different names pointing to the same object
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-18 03:48 EDT by Jacek Pospychala CLA
Modified: 2013-06-19 11:10 EDT (History)
1 user (show)

See Also:


Attachments
patch (2.62 KB, patch)
2010-06-18 04:11 EDT, Jacek Pospychala CLA
no flags Details | Diff
patch v2 (2.94 KB, patch)
2010-07-02 06:01 EDT, Jacek Pospychala CLA
no flags Details | Diff
proof of concept only (1.47 KB, patch)
2011-03-17 06:45 EDT, Nitin Dahyabhai CLA
no flags Details | Diff
screenshot (162.17 KB, image/jpeg)
2011-03-17 07:25 EDT, Jacek Pospychala CLA
no flags Details
screenshot (61.64 KB, image/png)
2011-03-17 07:26 EDT, Jacek Pospychala CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Pospychala CLA 2010-06-18 03:48:16 EDT
For a following code:

/**
 * @constructor
 */
Type1 = function() {}
Type1.prototype.coolDynFunc = function() {}
 
Type2 = Type1;

Both Type1 and Type2 should be recognized as types with a constructor and coolDynFunc member.
So in Outline user should see:

-Type1
 +- Type1()
 +- coolDynFunc()
-Type2
 +- Type2()
 +-coolDynFunc()
 
and in content assist both types should be supported equally.
Comment 1 Jacek Pospychala CLA 2010-06-18 04:11:56 EDT
Created attachment 172199 [details]
patch

a dirty way to do that is simply copy the original type.
I call it dirty, because copying one object to another seems a wrong solution. Unfortunately currently there seems no easy way to express that more than one name points to an existing type. When copying functions, special handling is required for constructor, to make sure it has the same name as containing type.
Comment 2 Jacek Pospychala CLA 2010-07-02 06:01:19 EDT
Created attachment 173282 [details]
patch v2

updated patch to better handle methods, attributes and mixins.
Comment 3 Chris Jaun CLA 2011-03-16 16:03:28 EDT
This patch is no longer applying cleanly and I can't figure out where it is supposed to go.

Are we sure that we always want to copy the object if the right hand side is inferred as a type? Seems like an awfully broad condition.
Comment 4 Jacek Pospychala CLA 2011-03-17 04:09:54 EDT
hi Chris,
no, the patch is not perfect, that was the smallest change I could think of within JSDT model. We added this in some adopter product and so far it worked well enough.
The better solution than copy would be to keep only one instance of type definition and list of names referring to that type.
Comment 5 Nitin Dahyabhai CLA 2011-03-17 06:45:28 EDT
Created attachment 191398 [details]
proof of concept only

Technically, wouldn't it be more correct to simply have the fields of Type2's InferredType be assigned the fields from Type1's InferredType?
Comment 6 Jacek Pospychala CLA 2011-03-17 07:23:50 EDT
I recall a few issues:
1. constructor. If we copy type A to type B, then constructor method ("A()") was no longer recognized as constructor but as a regular function B.A(). So in patch, I was updating constructor method name from A.A() to B.B().

2. type methods 
I tried simple dest.methods = src.method on inferred types, but this was causing visible problems in content assist.
More precisely, method parameter names were not recognized correctly - e.g.  for "A.each(func)" was "B.each(arg0)" instead of "B.each(func)".  (will attach screenshot)
This was caused by the way how attributes names were read - taking into account both method AST and parent type. (Not sure if this is an issue anymore)

3. type attributes
In earlier patch I see that I tried dest.attributes = src.attributes on inferred types too. But when making changes related to methods (pt 2. above), I changes attributes similarly as well... so probably there was similar issue with attributes too, but I don't have details any more.
Comment 7 Jacek Pospychala CLA 2011-03-17 07:25:03 EDT
Created attachment 191401 [details]
screenshot

screenshot showing the issue with method parameters, in previous comment
Comment 8 Jacek Pospychala CLA 2011-03-17 07:26:18 EDT
Created attachment 191402 [details]
screenshot

wrong screenshot...
Comment 9 Nitin Dahyabhai CLA 2011-04-27 22:29:36 EDT
Retaining the argument names properly is certainly something that needs to be done (along with any jsdoc we might have found while parsing).  Was that problem seen when trying your patch or mine?