Child pages
  • JSDoc Annotations

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
When

...

The Script Editor in the Servoy Developer IDE supports annotating JavaScript code using JSDoc. Documenting the code is a good practise, as it makes it easier to understand the code after a while or if another programmer needs to have a look at it.

Within Servoy, there is  

The JSDoc syntax supported by the Servoy Developer IDE is derived from the JSDoc Toolkit and Google Closure Compiler's support for JavaScript annotation, plus some custom Servoy extensions.

The JSDoc syntax consists of a set of JSDoc tags. Some of these tags require a Type Expression as one of the parameters.

JSDoc:

/**

*

*

*/

Auto generated tempaltes

Control-Shift-J

Code Completion

JSDoc Tags

Tag

Syntax & Examples

Comments

@AllowToRunInFind

@AllowToRunInFind

Custom Servoy JSDoc tag to annotate a function that it can be run if the Form on which the function is ran is in FindMode

@author

@author {userName}

Tag indicating the author of the code

@constructor

@constructor

 

@deprecated

@deprecated

Tag indicating that the function or variable is obsolete or has been replaced and should be used anymore

@example

@example

Tag allowing to provide some sample code how to use the function or variable

@param

@param {Type} name parameterDescription

Tag to describe function parameters

@private

@private

Annotates a variable or function as accessible only from within the scope1 in which it is declared

@protected

@protected

Annotates a variable or function as accessible from within the scope1 in which it is declared and all scopes that extend this scope

@return

@return {Type}

 

@returns

@returns {Type}

alias for @return

@see

@see seeDescription

 

@since

@since versionDescription

 

@SuppressWarnings

@SuppressWarnings (warning)

Custom Servoy JSDoc tag to suppress builder markers of a certain type within a function

@throws

@throws {Type}

 

@type

@type {Type}

 

@version

@version versionDescription

 

1 A scope can be either a Form or the globals scope. Only Form can be extended, thus the @protected tag is not relevant for annotating variables and functions within the globals scope

Type Expressions

Type Expressions are used to describe the type and/or structure of data in the following cases:

 

 

 

function parameters

/**
 * @param {String} value Just some string value
 */
function demo(value)
{...}

 

function return type

/**
 * @param {String} value Just some string value
 * @return x:Number, y:Number  */
function demo(value) {
   ...
   return {x: 10, y: 20}
}

 

variables

/**
 * @type {XML}
 */
var html = <html>
   <head>
   </head>
   <body>
      Hello World!
   </body>
</html>

 

 

 

 

A Type Expression is to always be surrounded by curly braces: {typeExpression}. Note that when using the Object Type expression variation that start and stops with curly braces as well, this results in double opening and closing braces.

Expression name

Syntax example

Comments

Named type

{String}
{Boolean}
{Number}
{XML}
{XMLList}
{RuntimeForm}
{RuntimeLabel}
{JSButton}
{JSForm}

 

AnyType

*

 

OR Type

{String|Number}

 

REST Type

{...String}

 

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="64e94789-5161-4c0f-9e9d-7936d8201f41"><ac:plain-text-body><![CDATA[

Array Type

{String[]} 
]]></ac:plain-text-body></ac:structured-macro>
{Array<String>} 
{Array<Byte>}

 

Object Type

{Object<String>} 
{Object<Array<String>>} 
{name:String, age:Number}} 

 

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="4cd9ba22-ef85-4520-8f5d-6ab8e565187b"><ac:plain-text-body><![CDATA[

Object Type with optional properties

{ {sDocID:String, [sTemplateID]:String}}
]]></ac:plain-text-body></ac:structured-macro>
{ {sDocID:String, sTemplateID:String=}}

 

JSFoundSet type

{JSFoundset<db:/udm/contacts>} 
{JSFoundset<{column1:String, column2:Number}>}

 

JSRecord type

{JSRecord<db:/udm/contacts>} 
{JSRecord<{column1:String, column2:Number}>}

 

JSDataSet type

{JSDataSet<{name:String, age:Number}>}

 

RuntimeForm Type

{RuntimeForm<superFormName>}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Adding whatever tag you like

Code completion

JSDoc Templates

Tip: Check out the JSDoc plugin for Servoy Developer on ServoyForge

Old 5.x style of annotating:

JSRecord:servername.tablename

JSFoundset :servername.tablename

 writing &nbsp;Servoy Developer IDE

The Script Editor in the Servoy Developer IDE supports annotating JavaScript code using JSDoc. Documenting the code is a good practise, as it makes it easier to understand the code after a while or if another programmer needs to have a look at it.

Within Servoy, there is &nbsp;

The JSDoc syntax supported by the Servoy Developer IDE is derived from the&nbsp;[JSDoc Toolkit|http://code.google.com/p/jsdoc-toolkit/] and [Google Closure Compiler's support for JavaScript annotation|http://code.google.com/closure/compiler/docs/js-for-compiler.html], plus some custom Servoy extensions.

The JSDoc syntax consists of a set of JSDoc tags. Some of these tags require a Type Expression as one of the parameters.

JSDoc:

/*\*

\*

\*

\*/

Auto generated tempaltes

Control-Shift-J

Code Completion

h3. JSDoc Tags

|| Tag || Syntax & Examples || Context || Comments ||
| @AllowToRunInFind | @AllowToRunInFind | function | Custom Servoy JSDoc tag to annotate a function that it can be run if the Form on which the function is ran is in FindMode |
| @author | @author \{userName\} | function, variable\\ | Tag indicating the author of the code |
| @constructor | @constructor | function\\ | ... |
| @deprecated | @deprecated | function, variable\\ | Tag indicating that the function or variable is obsolete or has been replaced and should be used anymore |
| @example | @example | function\\ | Tag allowing to provide some sample code how to use the function or variable |
| @param | @param \{Type} name parameterDescription | function\\ | Tag to describe function parameters |
| @private | @private | function, variable\\ | Annotates a variable or function as accessible only from within the scope{^}1^ in which it is declared |
| @protected | @protected | function, variable\\ | Annotates a variable or&nbsp;function as accessible from within the scope{^}1^ in which it is declared and all scopes that extend this scope |
| @return | @return \{Type} | function\\ | Annotates the type of the returned value |
| @returns | @returns \{Type} | function\\ | alias for @return |
| @see | @see seeDescription | function, variable\\ | Tag to provide pointers to other parts of the code that are related |
| @since | @since versionDescription | function, variable\\ | Tag to provide information about in which version of the code the variable or function was introduced |
| @SuppressWarnings | @SuppressWarnings (warning) | function\\ | Custom Servoy JSDoc tag to suppress builder markers of a certain type within a function |
| @throws | @throws \{Type} | function\\ | Tag to describe the type of Exceptions that can be raised when the function is called\\ |
| @type | @type \{Type} | variable, inline variable\\ | Tag to specify the type of the value that a variable can hold  |
| @version | @version versionDescription | function, variable\\ | Tag to provide information about the version of the code |

^1^ A scope can be either a Form or the globals scope. Only Form can be extended, thus the @protected tag is not relevant for annotating variables and functions within the globals scope


h3. Type Expressions

Type Expressions are used to describe the type and/or structure of data in the following cases:
|| Use case || Tag || Example ||
| function parameters \\ | @param | /*\* \\
&nbsp;\* @param \{String} value Just some string value \\
&nbsp;*/ \\
function demo(value) \\
\{...} |
| function return type \\ | @return\\
 @returns | /*\* \\
&nbsp;\* @param \{String} value Just some string value \\
&nbsp;\* @return \{\{x:Number, y:Number}} &nbsp;*/ \\
function demo(value)&nbsp;\{ \\
&nbsp; &nbsp;... \\
&nbsp; &nbsp;return \{x: 10, y: 20} \\
} |
| variables \\ | @type | /*\* \\
&nbsp;\* @type \{XML} \\
&nbsp;*/ \\
var html = <html> \\
&nbsp; &nbsp;<head> \\
&nbsp; &nbsp;</head> \\
&nbsp; &nbsp;<body> \\
&nbsp; &nbsp; &nbsp; Hello World\! \\
&nbsp; &nbsp;</body> \\
</html> |
A Type Expression is to always be surrounded by curly braces: \{typeExpression}. Note that when using the Object Type expression variation that start and stops with curly braces as well, this results in double opening and closing braces.
|| Expression name || Syntax example || Comments ||
| Named type | \{String} \\
\{Boolean} \\
\{Number} \\
\{XML} \\
\{XMLList} \\
\{RuntimeForm} \\
\{RuntimeLabel} \\
\{JSButton} \\
\{JSForm} | |
| AnyType | \* | |
| OR Type | \{String\|Number} | |
| REST Type | \{...String} | |
| Array Type | \{String\[\]}&nbsp; \\
\{Array<String>}&nbsp; \\
\{Array<Byte>} | |
| Object Type | \{Object<String>}&nbsp; \\
\{Object<Array<String>>}&nbsp; \\
\{name:String, age:Number}}&nbsp; \\ | |
| Object Type with optional properties | \{ \{sDocID:String, \[sTemplateID\]:String}} \\
\{ \{sDocID:String, sTemplateID:String=}} | |
| JSFoundSet type | \{JSFoundset<db:/udm/contacts>}{^}1^&nbsp; \\
\{JSFoundset<\{column1:String, column2:Number}>} | |
| JSRecord type | \{JSRecord<db:/udm/contacts>}{^}1\^ \\
\{JSRecord<\{column1:String, column2:Number}>} | |
| JSDataSet type | \{JSDataSet<\{name:String, age:Number}>} | |
| RuntimeForm Type | \{RuntimeForm<superFormName>} | |
\^1\^ the value in between <..> is the datasource notation that is built up of the database server and tablename: db:/{serverName}/{tableName}


Adding whatever tag you like

Code completion

JSDoc Templates

Tip: Check out the [JSDoc plugin for Servoy Developer|https://www.servoyforge.net/projects/jsdoc] on [ServoyForge|https://www.servoyforge.net/]

Old 5.x style of annotating:

JSRecord:servername.tablename

JSFoundset :servername.tablename

Form:formname