Javadoc templates
Sergey Timofiychuk edited this page Dec 25, 2015
·
22 revisions
Javadoc templates are based on freemarker template engine. So, use freemarker docs as template guides.
The following variables are available in any template:
-
name
- Name of element splitted by character type in camel case. For example if classname: SomeClass -name
variable in template will have the "Some class" value. -
partName
- Name of element splitted by character type in camel case without first item in split array. This can be usefull for the getter/setter methods. In this case for the method namegetSomeText
thepartName
variable will have "Some text" value. -
splitNames
- Array of strings split element name by character type in camel case. -
element
- this is an element of code for javadoc. This is a part of intellij idea API. For example for Class level javadoc here will bePsiClass
, for method or constructor -PsiMethod
, for field -PsiField
.
Additionally for method level javadocs the following variables are available:
-
fieldName
- usefull for getter/setter methods. It contains field name for generated method. -
isNotVoid
- type boolean. Shows whether method is void or not. -
return
- this variable contains string of return type splitted like it was inname
variable. -
paramNames
- this variable contains strings map of parameter names splitted like it was inname
variable (key of map is name of parameter, value is splitted value of parameter name). -
exceptionNames
- this variable contains strings map of exception types splitted like it was inname
variable (key of map is name of exception, value is splitted value of exception type).
Additionally for field level javadocs the following variables are available:
-
typeName
- name of the class where fields is located.
Other variables:
- You can use all built in variables that are available in freemarker library (2.3.23 version): http://freemarker.incubator.apache.org/docs/ref_builtins.html
So, all these variables can be used in templates.
For example:
Class level template can looks like:
/**\n * The type ${name}.\n * \n * Created on ${.now?string["MM.dd.yyyy"]} \n */
Or simple template for some methods:
/**\n * ${name}.\n <#list element.parameterList.parameters as parameter> * @param ${parameter.name} the ${paramNames[parameter.name]}\n </#list> *\n * @return the ${return}\n */
For even more examples you can look templates in settings of your IDE.