JSDOC/ScopeNamer.js
[app.jsdoc] / JSDOC / ScopeNamer.js
index f82421a..e0be6a2 100644 (file)
@@ -8,7 +8,7 @@ Symbol = imports.Symbol.Symbol;
 /**
  * @class ScopeNamer
  * @extends Collapse
- * @namespace JSDOC
+ * @scope JSDOC
  * The point of this class is to iterate through the Collapsed tree
  * and add the property 'scopedName' to the tokens.
  *
@@ -88,20 +88,24 @@ ScopeNamer = XObject.define(
         this.args = this.args ? this.args.slice(0)  : [];
         Symbol.srcFile = this.filename;
         this.createJSDOC = true;
-        
+        this.global = '_global_';
        // console.dump(ar);
         
     }, 
     imports.JSDOC.Collapse.Collapse, 
     {
+        
+        global : false,
         /**
          * Call debugging
          * add/remove ';' after return to configure at present..
          * @param {String} str String to output
          */
         debugCall : function(str)  {
-            if (!this.filename.match(/BuildDocs\.js/)) return;
-            return   print(str);
+            
+            
+            //if (this.filename.match(/Scope\.js/)) return print(str);
+            return;
         }, 
         
         collapseTop : true,
@@ -118,7 +122,7 @@ ScopeNamer = XObject.define(
             //print (this.statements);
             //print (JSON.stringify(this.statements, null,2));
            
-            this.walkStatements('_global_', this.statements)
+            this.walkStatements(this.global, this.statements)
             
                 
                 
@@ -135,7 +139,7 @@ ScopeNamer = XObject.define(
             this.debugCall("walkStatements :" + scope ) ;            
             var _this = this;
             var res = false;
-            var isGlobal = scope == '_global_';
+            var isGlobal = scope == this.global;
            
             statements.some(function(st ) {
                 // handle change of scope..
@@ -143,7 +147,14 @@ ScopeNamer = XObject.define(
                         st[0].jsdoc &&
                         st[0].jsdoc.getTag('scope').length
                    ) {
+                    //print(st[0].jsdoc.getTag('scope'));
                     scope = st[0].jsdoc.getTag('scope');
+                    // might be an array..
+                    if (typeof(scope) != 'String') {
+                        scope = scope[0].desc;
+                        
+                    }
+                    _this.global = scope;
                 }
                 
                 
@@ -159,12 +170,12 @@ ScopeNamer = XObject.define(
         {
             this.tokens = stmt;
             this.rewind();
-            this.debugCall("walkStatement :" + scope + '@' + this.tokens[0].line );
+            this.debugCall("walkStatement :" + this.global +'/' +scope + '@' + this.tokens[0].line );
              
             var name;
             var sn;
             
-            var isGlobal = scope == '_global_';
+            var isGlobal = scope == this.global;
             
             
             
@@ -240,8 +251,37 @@ ScopeNamer = XObject.define(
                     
                     // only register names of objects if 
                     var name = this.lookTok(-2).data;
-                    name = !isGlobal && isVar ? false : name;
-                    name = !isGlobal && name && !name.match(/^this\./) ? false : name;
+                    
+                    if (isGlobal) {
+                        print ("GLOBAL: ")
+                        
+                        
+                        
+                    } else {
+                        // not global.
+                        if (isVar) {
+                            name = false;
+                        }
+                        if (name && !name.match(/^this\./)) {
+                            name = false;
+                        }
+                        if (name && name.match(/^this\./) ) { 
+                            // see if scope ends in prototype..
+                            print("SCOPE:" + JSON.stringify(scope));
+                            if (
+                                (scope.split('.').pop() == 'prototype') &&
+                                (name.split('.').length == 2)
+                            ){
+                                name = name.split('.').pop();
+                            } else {
+                                name = false;
+                            }
+                            
+                        }   
+                        
+                    }
+                    
+                     
                     //print(JSON.stringify(token,null,4));
                     this.walkObject(scope, name, token.props, jd);
                     continue;
@@ -268,7 +308,7 @@ ScopeNamer = XObject.define(
         
         walkFunctionDef : function (inscope, name, args, stmts, jsdocTok)
         {
-            this.debugCall("wallkFuncDef: " + inscope + '@' + this.look(0).line );
+            this.debugCall("wallkFuncDef: " + inscope + '#' + name + '@' + this.look(0).line );
             var scope = name.length ? (inscope + '.' + name) : inscope;
             if (name.length) { 
                 var symbol = new Symbol( scope , args || [] , "FUNCTION" ,  jsdocTok.jsdoc);
@@ -284,7 +324,7 @@ ScopeNamer = XObject.define(
         
         walkCall : function (inscope, assign, callname, items, jsdocTok)
         {
-            this.debugCall("wallkCall : " + inscope  +':' + assign + '@' + this.look(0).line + ' ' + callname );
+            this.debugCall("walkCall : " + inscope  +':' + assign + '@' + this.look(0).line + ' ' + callname );
             var scope = inscope + ( assign ? ('.' + assign) : '' );
             //scope = scope.replace(/\^_global\$\./, '');
             
@@ -299,7 +339,12 @@ ScopeNamer = XObject.define(
                 case 'XObject.extend':
                 case 'Roo.apply':
                     //print(JSON.stringify(items,null,4));
-                    scope = items[0][0].data;
+                    // SHOULD WE ADD SCOPE HERE???
+                    var topscope = scope.split('.').pop();
+                    
+                    scope = (topscope == items[0][0].data) ?
+                        items[0][0].data :
+                        scope + '.' + items[0][0].data;
                     // 2nd arg is a object def
                     if (items[1][0].data != '{') {
                         return;
@@ -364,7 +409,7 @@ ScopeNamer = XObject.define(
                 return;
             }
             print(typeof(items));
-            this.debugCall("wallkObject : " + scope + '@' + items[Object.keys(items)[0]].key.line);
+            this.debugCall("wallkObject : " + scope + '#' + name + '@' + items[Object.keys(items)[0]].key.line);
             for( var k in items) {
                 var key = items[k].key;
                 var val = items[k].val;
@@ -411,9 +456,16 @@ ScopeNamer = XObject.define(
             // if a symbol alias is documented more than once the last one with the user docs wins
             
             // dumpe some invalid symbols..
-            if (symbol.alias.split(/[#.]/).length > 2) {
+            var ptype_ar = symbol.alias.split(/#/);
+            if (ptype_ar.length > 2) {
+                // multiple #
+                return;
+            }
+            if (ptype_ar.length > 1 && ptype_ar[1].split(/\./).length > 1) {
+                // multiple . after #
                 return;
             }
+            
             ScopeNamer.prototype.debugCall("addSymbol : " + symbol.alias );       
             
             if (ScopeNamer.symbols.hasSymbol(symbol.alias)) {