Commits

John Peberdy  committed 23504c7

Mixin detection when assigning class of a field. Fix 87646ac6e4b9

  • Participants
  • Parent commits 3ca1884

Comments (0)

Files changed (5)

File src/com/nexj/njsdoc/JSClass.java

         }
         return null;
     }
+    
+    /**
+     * @return The number of fields plus the number of methods
+     */
+    public int numMembers() {
+        int c = 0;
+        for (SlotIterator it = getIterator(null); it.hasNext(); c++) {
+            it.next();
+        }
+        return c;
+    }
 
     public DocumentedSlot getSlot() {
         return doc;

File src/com/nexj/njsdoc/SlotValue.java

             classification = Type.METHOD;
             this.jsClass = jsClass;
             break;
+        case FIELD:
+        case METHOD:
+            // Heuristic to detect mixins, and prefer being part of mixins
+            if (this.jsClass != null && jsClass != null && this.jsClass.numMembers() > jsClass.numMembers()) {
+                this.jsClass = jsClass;
+            }
+            break;
         default:
             break;
         }

File test/com/nexj/njsdoc/Test5.js

 	};
 })(HelloWorld.prototype);
 
+function MixinWorld() {
+	
+}
+
+/** This is a method in a mixin
+ * @ret {number} The result of a/0 */
+MixinWorld.prototype.myMixin = function(a, b, c) {
+	return a/0;
+};
+
+HelloWorld.prototype.myMixin = MixinWorld.prototype.myMixin;
 
 var q = new HelloWorld();

File test/com/nexj/njsdoc/Test5.md

 # Global Namespace
 ### Variables
 #### `q: HelloWorld`
-Defined at: Test5.js:89
+Defined at: Test5.js:100
 
 ## Constructor HiWorld
 Defined at: Test5.js:2
 
 Defined at: Test5.js:72
 
+#### `{number} HelloWorld.myMixin(a, b, c)`
+This is a method in a mixin
+
+* **`a`**: *`any `* 
+* **`b`**: *`any `* 
+* **`c`**: *`any `* 
+* **Returns** `number`  The result of a/0
+
+Defined at: Test5.js:94, Test5.js:98
+
+## Constructor MixinWorld
+Defined at: Test5.js:88
+
+### Methods
+#### `{number} MixinWorld.myMixin(a, b, c)`
+This is a method in a mixin
+
+* **`a`**: *`any `* 
+* **`b`**: *`any `* 
+* **`c`**: *`any `* 
+* **Returns** `number`  The result of a/0
+
+Defined at: Test5.js:94, Test5.js:98
+
 ## Namespace: HelloWorld
 Constructor for dummy class
 

File test/com/nexj/njsdoc/Test5.raw

              }
              <ObjectPrototype>: Function.prototype
           }
+          myMixin: method from MixinWorld @Test5.js:94, Test5.js:98 (Comment) {
+             prototype: field from MixinWorld {
+                <ObjectPrototype>: Object.prototype
+             }
+             <ObjectPrototype>: Function.prototype
+          }
           <ObjectPrototype>: ref(2)
        }
        <ObjectPrototype>: Function.prototype
        }
        <ObjectPrototype>: Object.prototype
     }
-    q: variable @Test5.js:89 (I) {
+    MixinWorld: constructor @Test5.js:88 (C) {
+       prototype: field from MixinWorld {
+          myMixin: ref(13 Comment)
+          <ObjectPrototype>: Object.prototype
+       }
+       <ObjectPrototype>: Function.prototype
+    }
+    q: variable @Test5.js:100 (I) {
        noProtoVar: variable @Test5.js:20 
        <ObjectPrototype>: ref(7)
     }