Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » How to let JSDT know the variable type?  () 1 Vote
How to let JSDT know the variable type? [message #648732] Fri, 14 January 2011 10:06 Go to next message
Phillip Gussow is currently offline Phillip GussowFriend
Messages: 2
Registered: January 2011
Junior Member
Hi,

I'm working with a tool called Cordys and they have a concept called XForms.

In this Xform I can create a 'Model' and give that a name. Let's call that myModel.

In that XForm I can attach a JS file to do custom scripting. This means that in my .js file I can do something like:
myModel.reset();

or
myModel.getDataset();


What I have done is for all those Model options create a separate js file and add all functions to that JS.

So if I do:
var myModel = new Model();
myModel.re     //Code completion works like a charm!

Then it works perfectly and code completion kicks in as it should.

Now my actual problem is that the var myModel = newModel() is NOT present in the JS file.

So what I'm looking for is an easy way to tell the JSDT what type it should assume for the variable.

In Pseudo Code this is what I would like to do:
/**
 * @type Model
 */
var myLocalVar = myModel;


I know i.e. Zend does it like this for PHP:
<?php
/**
 * @param int myInt The integer parameter for the method
 */
function something($myInt)
{
    ...
}
?>


So the bottom line:

Can I let the code assistant explicitly know which type a variable is?


Thanks in advance!
Re: How to let JSDT know the variable type? [message #648863 is a reply to message #648732] Fri, 14 January 2011 18:45 Go to previous messageGo to next message
Ian Tewksbury is currently offline Ian TewksburyFriend
Messages: 48
Registered: July 2009
Location: RTP, NC, USA
Member
Phillip,

JSDT supports the JSDoc standard. I am not an expert on JSDoc but from what I can tell there is no way to specify the type of a variable with JSDoc but all is not lost.

Assuming you have a "myModel" variable you could do something like this:
/**
 * @returns Model
 */
function getModel() {
    return myModel;
}

var myLocalVar = getModel();

Now JSDT will detect the return type of getModel as Model and then set the correct type on the local variable.

I hope this helps. Let us know if you need any further assistance.

Blue Skies,

~Ian


Ian Tewksbury
WTP JavaScript Tools
IBM Rational
-----
“When once you have tasted flight, you will forever walk the earth with your eyes turned skyward, for there you have been, and there you will always long to return.” ~Leonardo da Vinci
Re: How to let JSDT know the variable type? [message #648866 is a reply to message #648732] Fri, 14 January 2011 18:50 Go to previous messageGo to next message
Ian Tewksbury is currently offline Ian TewksburyFriend
Messages: 48
Registered: July 2009
Location: RTP, NC, USA
Member
Phillip,

Ignore my last message, there is an easier way, actually just the way you suggested works.

We support both 1.0 and 2.0 JSDoc defined here http://sourceforge.net/projects/jsdoc/ and here http://code.google.com/p/jsdoc-toolkit/ respectively.

In the 2.0 specification there is an @type annotation.

So this works:

/**
 * @type Model
 */
var myLocalVar = myModel;

And then you shoudl be able to get the contenet assist just as you would if you did

var myLocalVar = new Model();


Blue Skies,

~Ian


Ian Tewksbury
WTP JavaScript Tools
IBM Rational
-----
“When once you have tasted flight, you will forever walk the earth with your eyes turned skyward, for there you have been, and there you will always long to return.” ~Leonardo da Vinci
Re: How to let JSDT know the variable type? [message #648869 is a reply to message #648732] Fri, 14 January 2011 18:58 Go to previous messageGo to next message
Ian Tewksbury is currently offline Ian TewksburyFriend
Messages: 48
Registered: July 2009
Location: RTP, NC, USA
Member
Phillip,

As a side note if you ever want to see what type JSDT is inferring any local variables or the return types for functions you can enable the following functionality for the Outline view:

Window -> Preferences -> JavaScript -> Appearance -> Show inferred function return types

Blue Skies,

~Ian


Ian Tewksbury
WTP JavaScript Tools
IBM Rational
-----
“When once you have tasted flight, you will forever walk the earth with your eyes turned skyward, for there you have been, and there you will always long to return.” ~Leonardo da Vinci
Re: How to let JSDT know the variable type? [message #649037 is a reply to message #648732] Mon, 17 January 2011 11:37 Go to previous message
Phillip Gussow is currently offline Phillip GussowFriend
Messages: 2
Registered: January 2011
Junior Member
Hi Ian,

Thanks for your reply and thanks for the solution! It works perfectly and saves me a lot of work!

Phillip
Previous Topic:validation of a file with a new extension "myxml"
Next Topic:Newbie question on creating Web Service
Goto Forum:
  


Current Time: Thu Apr 25 05:36:47 GMT 2024

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

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

Back to the top