Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » How to extend javascript type inference
How to extend javascript type inference [message #723531] Thu, 08 September 2011 18:30 Go to next message
Ning Wang is currently offline 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 #724303 is a reply to message #723531] Mon, 12 September 2011 03:00 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2267
Registered: July 2009
Senior Member
I think you would have to modify the code since we've been operating under the precept that the doc wins.

---
Nitin Dahyabhai
Eclipse WTP, IBM

[Updated on: Mon, 12 September 2011 03:01]

Report message to a moderator

Re: How to extend javascript type inference [message #724641 is a reply to message #723531] Mon, 12 September 2011 17:57 Go to previous messageGo to next message
Ning Wang is currently offline Ning Wang
Messages: 10
Registered: July 2011
Junior Member
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 18:01 Go to previous messageGo to next message
Ning Wang is currently offline Ning Wang
Messages: 10
Registered: July 2011
Junior Member
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 19:02 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2267
Registered: July 2009
Senior Member
See http://www.slideshare.net/cbridgha/eclipsecon-2011-supporting-javascript-toolkits-with-jsdt

---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: How to extend javascript type inference [message #724716 is a reply to message #724672] Mon, 12 September 2011 23:48 Go to previous messageGo to next message
Ning Wang is currently offline Ning Wang
Messages: 10
Registered: July 2011
Junior Member
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] Tue, 13 September 2011 01:17 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2267
Registered: July 2009
Senior Member
I'm not sure what you mean by "type propagation".

---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: How to extend javascript type inference [message #725007 is a reply to message #724727] Tue, 13 September 2011 18:10 Go to previous messageGo to next message
Ning Wang is currently offline 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 22:37]

Report message to a moderator

Re: How to extend javascript type inference [message #725030 is a reply to message #725007] Tue, 13 September 2011 18:42 Go to previous message
Ning Wang is currently offline Ning Wang
Messages: 10
Registered: July 2011
Junior Member
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: Thu Sep 18 03:40:36 GMT 2014

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

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