--
You received this message because you are subscribed to the Google Groups "JSDoc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdoc-users...@googlegroups.com.
To post to this group, send email to jsdoc...@googlegroups.com.
Visit this group at http://groups.google.com/group/jsdoc-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Some differences I see that may or may not make a difference
- Module reference syntax (modules/ModuleA vs. module:ModuleA)
- No @module tag in your parent module doc
- No @extends tag in your child constructor doc
- @lends references the prototype
I will say that we spent a lot of hours trying different combinations until we found the right one. Please do update us when you've found a solution for your code style :)
This do what you want at all?
This is how the test code look like with your proposed solution:
ModuleA:
/**
* This is a utility class.
* @class MyClass
*/
var myClass = function() {}
define("modules/A", ["myClass"], function (myClass) {
/**
* My Superclass module
* @module modules/A
*/
var A = myClass(/** @lends module:modules/A.prototype */ {
/**
* Use this to make a module:modules/A
* @constructs
*/
constructor: function () {
/**
* Member of the Superclass
* @type {String}
*/
this.memberA = "test";
},
/**
* This is a common method also shared by the Subclass
*/
commonMethod: function () {
},
/**
* This method represents an interface to be implemented by the subclass
* @abstract
*/
overrideMethod: function () {
throw new Error("Must be subclassed");
}
});
});
ModuleB:
This do what you want at all?
Your example is similar to what I achieved, but problems remain:
- First of all, what I still do not understand, is that in the Superclass I have to write @lends module:modules/A.prototype while in the Subclass I have to write: /** @lends module:modules/B */. It just seems weird.
- Also, no "<static>" methods in the Superclass.
- But, (exclusive) Subclass methods ARE <static>.
- The "virtual" methods also shows as "virtual" in the Subclass
- If I omit the description for "commonMethod" and just define it in the Subclass, the description of the Superclass is inserted, which is fine. However, if I DO add a custom description for my overrided method, there are actually TWO descriptions of this method appear in my docs. Interestingly, this seems NOT to happen if I try this with members instead of methods.
- First of all, what I still do not understand, is that in the Superclass I have to write @lends module:modules/A.prototype while in the Subclass I have to write: /** @lends module:modules/B */. It just seems weird.
Yeh that seems like a bug to me too. Have you raised a ticket for this on the issue tracker yet?
- Also, no "<static>" methods in the Superclass.
On Superclass? I see no static methods in your example. There is no way for JSDoc to know what myClass() will do with your methods, whether it will make them static or instance. You told it you were sticking them on the prototype with the @lends tag and so that's how they are documented. If you want them to be documented as static you need to say so (try @memberof or @static).
(or maybe you meant "Subclass"? in which case, read on...)True and that seems correct to me, because in that case you are telling @lends you are sticking those methods directly onto the module object (not it's prototype) so they will be considered "static". Of course the reason you are doing that is the likely bug in your first point.
- But, (exclusive) Subclass methods ARE <static>.
Yep, two feature requests here: one, the word "virtual" should arguably be expressed as "abstract" in the output. It's called "virtual" for two reasons, one is that "abstract" is a reserved word in JS, two is that JS doesn't have abstract methods implemented in any available engine (so we may as well make up a word for a made up concept -- but I prefer "abstract" in the output).
- The "virtual" methods also shows as "virtual" in the Subclass
The second feature is that an abstract doc should lose it's abstract tag when it is in an @extended context. This might be complex to implement, so maybe a new explicit tag, like @implemented or @concrete when in the implementing doc would strip the abstract status.
- If I omit the description for "commonMethod" and just define it in the Subclass, the description of the Superclass is inserted, which is fine. However, if I DO add a custom description for my overrided method, there are actually TWO descriptions of this method appear in my docs. Interestingly, this seems NOT to happen if I try this with members instead of methods.
The reason you are seeing two is, again, due to the @lends (prototype) in Superclass combined with @lends (no prototype) in the subclass. It is perfectly possible to have two methods with the same name, one on the object, another on that object's prototype, and JSDoc supports this. You don't see the second (static) docs when you don't doc-comment the method because, well, there's no doc comment, and JSDoc won't document uncommented things.
The reason you see two when you do comment it is because it appears that you are commenting two different methods with the same name, one on the inherited prototype, and another directly on the Subclass itself (static).
- First of all, what I still do not understand, is that in the Superclass I have to write @lends module:modules/A.prototype while in the Subclass I have to write: /** @lends module:modules/B */. It just seems weird.
Yeh that seems like a bug to me too. Have you raised a ticket for this on the issue tracker yet?
Not yet, wanted to clarify first if this might be an actual bug.
- Also, no "<static>" methods in the Superclass.
On Superclass? I see no static methods in your example. There is no way for JSDoc to know what myClass() will do with your methods, whether it will make them static or instance. You told it you were sticking them on the prototype with the @lends tag and so that's how they are documented. If you want them to be documented as static you need to say so (try @memberof or @static).
Maybe I am getting something wrong, but since the methods of ModuleA are also on the prototype, they are static, right?
Also using @static does just nothing.
The only thing to get it right is to write: @lends module:modules/A (_without_ the ".prototype")
But then, the "overrideMethod" is simply not showing up in my Subclass, but it should!
(or maybe you meant "Subclass"? in which case, read on...)True and that seems correct to me, because in that case you are telling @lends you are sticking those methods directly onto the module object (not it's prototype) so they will be considered "static". Of course the reason you are doing that is the likely bug in your first point.
- But, (exclusive) Subclass methods ARE <static>.
Yes, I think it is correct to mark them as static. But still, the _inherited_ Superclass methods remain also static then, right?
Yep, two feature requests here: one, the word "virtual" should arguably be expressed as "abstract" in the output. It's called "virtual" for two reasons, one is that "abstract" is a reserved word in JS, two is that JS doesn't have abstract methods implemented in any available engine (so we may as well make up a word for a made up concept -- but I prefer "abstract" in the output).
- The "virtual" methods also shows as "virtual" in the Subclass
Well, I actually used @abstract - it's just the output that reads "virtual" - maybe change this also to "<abstract>", to avoid confusion?
The second feature is that an abstract doc should lose it's abstract tag when it is in an @extended context. This might be complex to implement, so maybe a new explicit tag, like @implemented or @concrete when in the implementing doc would strip the abstract status.
And it seems that there is already code that handles this - if I take Daniels example, the "<virtual>" designation does _not_ show up in the concrete subclass implementation which I would expect. It just seems not to work when using the module notation (instead of a @class like structure)
- If I omit the description for "commonMethod" and just define it in the Subclass, the description of the Superclass is inserted, which is fine. However, if I DO add a custom description for my overrided method, there are actually TWO descriptions of this method appear in my docs. Interestingly, this seems NOT to happen if I try this with members instead of methods.
The reason you are seeing two is, again, due to the @lends (prototype) in Superclass combined with @lends (no prototype) in the subclass. It is perfectly possible to have two methods with the same name, one on the object, another on that object's prototype, and JSDoc supports this. You don't see the second (static) docs when you don't doc-comment the method because, well, there's no doc comment, and JSDoc won't document uncommented things.
Well, if the undocumented method is documented on the Superclass, this doc is already used - which is fine. But: if I actually want to override the doc in the subclassed function, _two_ entries appear - which shouldn't be the case here imho. I also don't think you can have two methods with the same name on the same object, so this still seems wrong to me. Just try my latest example for seeing this.
The reason you see two when you do comment it is because it appears that you are commenting two different methods with the same name, one on the inherited prototype, and another directly on the Subclass itself (static).
Yes, and therefore I think @lends _without_ adding .prototype should be the right thing. But still, the problems I mentioned remain.
So the question is: what is the actual bug that causes this? Maybe we should narrow it down further before opening a ticket?
--
Maybe I am getting something wrong, but since the methods of ModuleA are also on the prototype, they are static, right?Yes. But opposite.
That's because Daniel is using @lends module:ModuleB.prototype and then documenting the concrete method with a new comment. The bug this issue identified already means the (virtual) comment from the Superclass is not inherited, thus you do not see the "<virtual>" designation.
You are not putting two methods with the same name on the same object: one is on the object the other is on the object's prototype. See my example above.
I think Jeff is already on top of this:A general statement, if I may: at least some of this issue is to do with the fact that JSDoc is a general-purpose tool, designed to handle VanillaJS, which doesn't (yet, commonly) have classes or abstracts or classical inheritance. So users' that are relying on a library to simulate those things are making some assumptions that JSDoc can't make. The only way forward, in my opinion, is to provide @tags to allow the user to express those assumptions. But again, I think Jeff is squarely on top of this with the @inheritdocs work, etc.
Also, Michaels example shows that this happens when you use @class, too. And since the Subclass B "knows" that it inherits from "A", the method "b" _should_ appear in the docs imho, wether it has additional docs (take them) or not (take them from the class it inherited from). Same thing goes for @virtual, since it also should be clear that the method defined in B cannot be virtual anymore.