Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Javascript Editor Type Validation(Unable to resolve type in included libraries/project sister files)
Javascript Editor Type Validation [message #665843] Sat, 16 April 2011 23:46 Go to next message
Matt Taylor is currently offline Matt TaylorFriend
Messages: 3
Registered: April 2011
Junior Member
The latest version of the javascript editor appears to be able to do some rudimentary 'includes' of libraries and other javascript files for the purposes of validation.

Unfortunately it doesn't seem to handle the 'new' keyword very well.

If I have the following in the included file:

function foo(){};

the following validates (and I can even ctrl-click to the definition in the other file):

var v = foo();

However if I do this:

var v = new foo();

The editor gives a 'foo cannot be resolved to type' error (I have 'check for unresolved types/fields' enabled for javascript validation).

(the above is legit javascript and it validates fine if I have the definition of 'foo()' in the same file)

My question is: Is this just too much to expect from the editor or is this a bug? Or maybe there is some setting I am missing?

Thanks in advance for any answers.

Re: Javascript Editor Type Validation [message #665865 is a reply to message #665843] Sun, 17 April 2011 13:59 Go to previous messageGo to next message
Ian Tewksbury is currently offline Ian TewksburyFriend
Messages: 48
Registered: July 2009
Location: RTP, NC, USA
Member
Matt,

This is not a bug, this is the way the JavaScript type inferencing is currently designed. The two most common ways we determine if something is a type is if we detect the following syntax:

function foo() {
this.bar = "test" <----the reference to 'this' tips us off this is a type and not just a function
}

function foo() {}
foo.prototype.myFunc = function() {} <-- the use of prototype tips us off this is a type.

Just having 'function foo() {}' just looks like a function to us and there is no information there hinting this could be a type.

My suggestion to you, if you do not want to see the validation message any more, would be to use one of the two syntaxes above or turn off the validation.

If you have any other further questions please do not hesitate to ask.

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: Javascript Editor Type Validation [message #666071 is a reply to message #665865] Mon, 18 April 2011 21:40 Go to previous message
Matt Taylor is currently offline Matt TaylorFriend
Messages: 3
Registered: April 2011
Junior Member
Thanks for the great reply Ian.

I'm using the slightly condensed

foo.prototype.foo = {}

form and it works like a champ (it isn't exactly meaningful/correct javascript, but it is enough to tell the validator that foo is a type, which is good enough for a stub that will never see the light of a browser Smile ).

Matt
Previous Topic:WSDL editor (WSDL 2.0 ?)
Next Topic:Unexpected context restarts
Goto Forum:
  


Current Time: Tue Mar 19 03:06:45 GMT 2024

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

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

Back to the top