| How to extend javascript type inference [message #723531] |
Thu, 08 September 2011 14:30  |
Ning Wang Messages: 10 Registered: July 2011 |
Junior Member |
|
|
Hi folk,
I have asked a similar question on ATF and were suggested to post it here. Javascript type inference has done pretty awesome job on inferring type based on javascript docs annotation.
For example,
/*
* @param {String} a [required]
* @return {myobj}
*/
function foo(a) { return new mynewobj(a); }
function bar() {
var ret = foo ("hello");
var ret1 = ret
ret1 // rec's type is myobj
}
But myobj is a generic object, it is extended based on the parameter passing into mynewobj. In order to make the type inference more useful, I want to augment the inferred type "myobj" with the extra information passed to mynewobj.
I noticed that org.eclipse.wst.jsdt.core.inferrenceSupport is the extension point for type inference. In this case, I don't need to modify how type is populated along the AST, but only need to inject extra info to the initial type that is returned from foo based on its formal parameter. Is this doable with the above extension point or I have to modify the wst.jsdt.core code?
Any suggestion is highly appreciated.
Ning
|
|
|
|
|
|
|
|
|
| Re: How to extend javascript type inference [message #725007 is a reply to message #724727] |
Tue, 13 September 2011 14:10   |
Ning Wang Messages: 10 Registered: July 2011 |
Junior Member |
|
|
Type propagation is to propagate type along dataflow from a type define site to type use site. I look at the code of resolveExpressionType that does bottom up traverse to find out the type define site from a use site.
I think the algorithm works this way:
Step 1. do top down traversal, finds unresolved types from JsDoc, and associate these types with the corresponding ASTNodes.
Step 2. resolves unresolved types
Step 3. do bottom up traversal for each statement and associates ASTNode with resolved type.
Is my understanding correct?
Thanks.
[Updated on: Wed, 14 September 2011 18:37] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.01832 seconds