4

When writing a javascript function in Eclipse, I would like to use the auto-commenting feature. I have seen it work on other people's computers, but it is not grabbing the @params on my machines.

When I have

var foo = function(bar){
    // do stuff
    return bar;
}

And on the line before the function I type /** and hit return, I get:

/**
 * 
 */
var foo = function(bar){
    // do stuff
    return bar;
}

I should get:

/**
 * 
 * @param bar
 */
var foo = function(bar){
    // do stuff
    return bar;
}

Any ideas? This seems like some setting in Eclipse is not set right, rather than a problem specific to Javascript.

Simulant
  • 19,190
  • 8
  • 63
  • 98
BishopZ
  • 6,269
  • 8
  • 45
  • 58

3 Answers3

3

Try declaring your functions like this:

function foo(bar){
   return bar;
};

Thing is that Eclipse generates documentation for declarations! An assignment expression you use to declare a function is no different than an expression like x=1; and Eclipse does not generate documentation for expressions.

I would recommend checking out this question. It explains the differences in function declarations.

Community
  • 1
  • 1
Bikush
  • 654
  • 8
  • 22
  • wow, thanks! I never knew the compile-time/run-time difference. I always use the foo = function style because it is easier to understand the scope that is being defined. Great info, thanks again! – BishopZ Sep 06 '12 at 18:35
1

Assuming Juno and a file on the project's Include Path, you want to Generate the "element" comment (either from the Outline view or Source menu or the Add JSDoc Comment command) rather than do so by typing it in, although when I tried it it didn't quite come out as neatly as I expected.

nitind
  • 19,089
  • 4
  • 34
  • 43
0

I am not using JavaScript, just pure Java, but the setup for generated Java-Code comments is here:

Window -> preferences -> Java -> Code Style -> Code Templates  ->
 Comments -> Methods

the default value is :

/**
 * ${tags}
 */

so i guess you need to set up somthing similar in Window -> preferences -> JavaScript -> ...

Simulant
  • 19,190
  • 8
  • 63
  • 98
  • Thanks for the ideas! I checked in that location and the default value is what is there. I guess my question is how to get it to identify the function input parameters as ${tags}? – BishopZ Aug 14 '12 at 21:56
  • There is one slight difference, don't think it matters, but -> Methods in the Java Code Templates is called -> Functions in the Javascript Code Templates. Same difference I assume. the value is the same as is listed above. – BishopZ Aug 14 '12 at 22:59