Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » How to extend javascript type inference
How to extend javascript type inference [message #723531] Thu, 08 September 2011 14:30 Go to next message
Eclipse UserFriend
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 #724303 is a reply to message #723531] Sun, 11 September 2011 23:00 Go to previous messageGo to next message
Eclipse UserFriend
I think you would have to modify the code since we've been operating under the precept that the doc wins.

[Updated on: Sun, 11 September 2011 23:01] by Moderator

Re: How to extend javascript type inference [message #724641 is a reply to message #723531] Mon, 12 September 2011 13:57 Go to previous messageGo to next message
Eclipse UserFriend
What is the initial design goal of org.eclipse.wst.jsdt.core.inferrenceSupport? What extension can you do with it?
Re: How to extend javascript type inference [message #724645 is a reply to message #724303] Mon, 12 September 2011 14:01 Go to previous messageGo to next message
Eclipse UserFriend
Another follow up question, any hint what class I should modify? Many thanks.
Re: How to extend javascript type inference [message #724672 is a reply to message #724645] Mon, 12 September 2011 15:02 Go to previous messageGo to next message
Eclipse UserFriend
See http://www.slideshare.net/cbridgha/eclipsecon-2011-supporting-javascript-toolkits-with-jsdt
Re: How to extend javascript type inference [message #724716 is a reply to message #724672] Mon, 12 September 2011 19:48 Go to previous messageGo to next message
Eclipse UserFriend
thanks for this link. the initial inferred types are setted by InferEngin, but the type propagation is done on demand through resolveExpressionType. Do I understand the workflow correctly?
Re: How to extend javascript type inference [message #724727 is a reply to message #724716] Mon, 12 September 2011 21:17 Go to previous messageGo to next message
Eclipse UserFriend
I'm not sure what you mean by "type propagation".
Re: How to extend javascript type inference [message #725007 is a reply to message #724727] Tue, 13 September 2011 14:10 Go to previous messageGo to next message
Eclipse UserFriend
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] by Moderator

Re: How to extend javascript type inference [message #725030 is a reply to message #725007] Tue, 13 September 2011 14:42 Go to previous message
Eclipse UserFriend
By the way, I use Expression.resolveTypeBinding() to find the type of a given expression. Is there any other method to get the type?
Previous Topic:Eclipse
Next Topic:target namespace of CMElementDeclaration
Goto Forum:
  


Current Time: Wed Jul 09 23:26:37 EDT 2025

Powered by FUDForum. Page generated in 0.28522 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top