3

I have a strange issue with outlining of JavaScript files in Eclipse 4.2 using JSDT 1.4.1. I have a closure defined like this:

var myClosure = (function() {
    var calcGridLocation,
        detectCollision;

    /**
     * Calculate the grid cell coordinates from the offset of an element and the editorgrid offset
     *
     * @param {jQuery object} obj jQuery object of the object whose location will be calculated
     * @param {String} [subgrid=""] Specify the currently active subgrid
     * @returns {Object} Coordinate object with x, y and obj properties, obj hols a jQuery object of the target cell, null for locations outside the editorgrid
     * @memberOf myClosure
     */
    calcGridLocation = function(obj, subgrid) {
        var gridOffset,     // Offset (relative to document) of the editorgrid
            objOffset,      // Offset (relative to document) of the provided object
            rv = {};        // Return value object

        if(subgrid === null || subgrid === undefined) {
            subgrid = "";
            // Get the grid's offset
            gridOffset = $("#editorgrid").offset();
        }
        else {
            // Get the grid's offset
            gridOffset = $("#" + subgrid).offset();

            subgrid += "_";
        }

        // Get the object's offset
        objOffset = obj.offset();

        // Calculate the grid coordinates of the object
        if(objOffset === undefined || gridOffset === undefined) {
            debugger;
        }
        rv.x = Math.floor((objOffset.left - gridOffset.left) / cellSize);
        rv.y = Math.floor((objOffset.top - gridOffset.top) / cellSize);

        // Check if the location is a valid grid location
        if(rv.x >= 0 && rv.x < tblCellCount && rv.y >= 0 && rv.y < tblRowCount) {
            if(obj.hasClass("gridCell")) {
                rv.obj = obj;
            }
            else {
                // Get the grid cell object and return the return value object
                rv.obj = $("#" + subgrid + "c_" + rv.y + "_" + rv.x);
            }

            return rv;
        }
        else {
            // Return null, no valid grid location
            return null;
        }
    }; //calcGridLocation = function()


    /**
     * Detect a collision of an object with other dragboxes
     *
     * @param {jQuery object} obj Object to check for collisions
     * @returns {Object} Object with collision, obstacle, shift.x and shift.y attributes
     * @memberOf myClosure
     */
    detectCollision = function(obj) {
        // Some code here
    }; //detectCollision = function()
})();

After some researching I found out that I need the jsDoc annotations to make the functions show up in Eclipse. The first functions shows up but the second does not. It is just not listed.

And the really weird thing: If I remove the contents of the first function completely, the second function will show up just fine. Is there some mistake in my syntax that does cause this behaviour? The complete script works fine when I test my project in the browser (Google Chrome) and gets validated by jsLint (except some things where I do not accept the jsLint way of writing code).

Additional information

Eclipse does not show several functions of this closure, the above is just a minimal example. The "lost" functions seem to be quite random, sometimes a single one is missing, sometimes several in a row. Also there are functions between the missing ones that are shown in the outline like this: shown, shown, missing, shown, missing, missing, ...
I double checked that every single function has the @memberOf jsDoc annotation which should make it visible in the outline.
The missing functions are not recognized as function blocks by the editor so I cannot fold them (the shown function can be folded). Removing the content from the calcGridLocation function enables code folding on the detectCollision function.

marandus
  • 1,228
  • 1
  • 13
  • 21
  • Any particular reason for `var foo = function() { ... }` instead of simply `function foo() { ... }`? – Matt Ball Jan 07 '13 at 15:44
  • I adopted that style of closure definition from another library I used in this project since I didn't know much about closures and stuff when I started this. So I have no idea if it has any particular reason but I guess most likely the answer is "no" – marandus Jan 07 '13 at 22:19
  • Recommended reading: http://kangax.github.com/nfe/ – Matt Ball Jan 07 '13 at 22:19
  • 1
    Interesting read. I just changed the inner functions to the `function name(){...}` style of definition and I guess now I know why it was done that way before: jsLint marks every function call or using any function as a parameter (for jQuery handlers) as error because it is used before it was defined. Well, it didn't solve my problem too... – marandus Jan 08 '13 at 10:43

0 Answers0