Jsdocx is a java tool for scanning Js code and generating API documentation automatically.
Jsdocx defines a standard set of annotations specification. This document describes all details of the specification.
Many JavaScript libraries to use the functional style API, this is not a good thing.
Jsdocx require the full object-oriented style of library design: that everything is class.
At this stage, Jsdocx has no plans to support the comments of the functions, you may consider the following measures before using jsdocx:
1) redesign object-oriented style API
2) comment functions with a virtual class
In addition, Jsdocx scanned the source code sequentially, requires all members comments of a class is continuous, otherwise it will identify the wrong class members.
Jsdocx support JavaScript's multi-line comment style. Jsdocx annotation start with "@", similar to Javadoc:
/** * @{tagName} {comment} */Also directly write description on the annotation of a class or member:
/** * {Description} * @class MyClass */ MyClass = function(){}
Jsdocx Annotation's format is: The "@tagName" at the beginning, followed by zero or more whitespace-separated text fragments.
@tagName{whitespace[text fragments]}*
Jsdocx Annotation Attributes:
tagName: the tag name of the annotation markTarget: the mark target is:File, Class, Method or Field isMultiLine: single line or multi line syntax: describe the syntax format with BNF
markTarget: File isMultiLine: Y syntax: @project <projectName> [description] sample: @project JSDK JavaScript Development Kit
markTarget: File isMultiLine: N syntax: @copyright <copyrightText> sample: @copyright Copyright (c) 2004-2011, Dragonfly.org. All rights reserved.
markTarget: File isMultiLine: N syntax: @license <licenseName> sample: @license LGPLv3
markTarget: File isMultiLine: N syntax: @requires <resourcePath> sample: @requires /library/blackbirdjs-1.0/blackbird.js @requires /library/blackbirdjs-1.0/blackbird.css
markTarget: File isMultiLine: N syntax: @version <versionNumber> sample: @version 1.0.0
markTarget: File isMultiLine: N syntax: @author <authorName> sample: @author Feng.chun
markTarget: File isMultiLine: N syntax: @date <codingDate> • The format is: yyyy-mm-dd sample: @date 1977-04-15
markTarget: File isMultiLine: N syntax: @since <versionNumber> sample: @since 1.0.0
markTarget: Class isMultiLine: Y syntax: @struct <structName> <structSchema> • Mark a json struct class without source code • The struct schema see: http://json-schema.org/ sample: @struct sanguo.Knight$Config { "description": "the arguments of sanguo.Knight" ,"type":"object" ,"properties":{ "side":{"type":"string","required":true} ,"level":{"type":"string","required":false} } }
markTarget: Class, Method, Field isMultiLine: N syntax: @see <className{#memberName}> sample: @see js.Lang#random
markTarget: Class, Method, Field isMultiLine: Y syntax: @deprecated [version] [reason] • If a class is deprecated, then its every method or field is deprecated. sample: @deprecated 1.2 i don't like
markTarget: Class, Method, Field isMultiLine: N syntax: @final • Mark a final class or method or field • If a class is final, then its every method or field is final sample: @final
markTarget: Class, Method, Field isMultiLine: N syntax: @static • Mark a static class or method or field • If a class is static, then its every method or field is static sample: @static
markTarget: Class, Method, Field isMultiLine: N syntax: @public • The default is public when not marked sample: @public
markTarget: Class, Method, Field isMultiLine: N syntax: @protected • A protected class be only called by same package or same file • A protected field or method be only called by class self or subclasses sample: @protected
markTarget: Class, Method, Field isMultiLine: N syntax: @private • A private class be only called by same file • A private field or method be only called by class self sample: @private
markTarget: Class isMultiLine: N syntax: @native <nativeObjectName> • Mark a javascript native object sample: @native String
markTarget: Class isMultiLine: N syntax: @class <className> sample: @class sanguo.Engine
markTarget: Class isMultiLine: N syntax: @extends <className> sample: @extends sanguo.d2.Sprite
markTarget: Class isMultiLine: N syntax: @mix <otherClassName> • Mix otherClassName's prototype into the class sample: @mix sanguo.MoveProvider
markTarget: Class, Method isMultiLine: N syntax: @abstract • An abstract class has a abstract method at least • An abstract method is a empty method sample: @abstract
markTarget: Class isMultiLine: Y syntax: @event <eventName> [eventSchema] • The event schema see: http://json-schema.org/ sample: @event moved { "description": "fires after a sprite movement" ,"type":"arguments" ,"properties":{ "this":{"type":"sanguo.d2.Sprite","required":true} ,"x":{"type":"int","required":true} ,"y":{"type":"int","required":true} } }
markTarget: Method isMultiLine: N syntax: @constructor • Mark the class's constructor function sample: @constructor
markTarget: Method isMultiLine: N syntax: @method <methodName> sample: @method
markTarget: Method isMultiLine: N syntax: @param <type{"|"type}> <paramName[:optional]> [description] • Mark a parameter of the method, allows many types • Native types are: Object,Array,Number,Int,Float,String,Date,Boolean,Error,Function,HTMLElement sample: @param {String} name the name of Yomi @param {Date|String} birthday:optional the birthday of Yomi
markTarget: Method isMultiLine: N syntax: @return <type{"|"type}> [description] • Native types are: Void,Object,Array,Number,Int,Float,String,Date,Boolean,Error,Function,HTMLElement sample: @return {Date|String} the birthday of Yomi
markTarget: Method isMultiLine: N syntax: @throws <errorType> [description] sample: @throws {TypeError} when the arguments invalid @throws {ReadError} when the reading failure
markTarget: Method isMultiLine: N syntax: @override • Mark the method override a superclass's same name method sample: @override
markTarget: Field isMultiLine: N syntax: @field <type{"|"type}> <fieldName> • Mark a field of the class, allows many types • Native types are: Object,Array,Number,Int,Float,String,Date,Boolean,Error,Function,HTMLElement sample: @field {Int|String} code
markTarget: Field isMultiLine: N syntax: @field <type{"|"type}> <fieldName> • Mark a final static field of the class, allows many types • Native types are: Object,Array,Number,Int,Float,String,Date,Boolean,Error,Function,HTMLElement sample: @constant {String} JSDOCX_VERSION
java -cp org.dragonfly.jsdocx-<version>.jar org.dragonfly.jsdocx.JsdocCreator -Souredir=<js source's directory>
-Charset=<charset>: the generating html document's charset -Souredir=<directoryPath>: the javascript source's directory -Docdir=<directoryPath>: the generating html document's directory -Clean: clean the html document's directory before generating
JsdocConfig config = new JsdocConfig(); config.setSourceDir("the javascript source's directory"); new JsdocCreator(config).generate();
java -cp org.dragonfly.jsdocx-<version>.jar org.dragonfly.jsdocx.example.SanguoExample