How to Create Custom Javadoc Live Templates in IntelliJ IDEA for Java
This guide explains step‑by‑step how to configure IntelliJ IDEA’s Live Templates to automatically generate Javadoc comments for Java methods, including creating a custom template group, defining variables, setting scope, and showcasing useful Java‑8 snippets, while also noting promotional offers for activation tools.
IntelliJ IDEA is renowned as a powerful IDE for Java development, and this article demonstrates how to enhance its productivity by configuring custom Live Templates that generate Javadoc comments automatically.
Step 1: Open Settings – Use Ctrl+Alt+S or navigate through File → Settings .
Step 2: Navigate to Live Templates – Expand Editor → Live Templates and click the + button to create a new template group, e.g., myTemplates .
Step 3: Add a New Live Template – Within the new group, click + → Live Template and define the abbreviation (e.g., mr ) and description.
Template Content – Use the following template body (wrapped in ... tags):
**
* $Description$
$params$
$
return
$
* @Author $user$
* @Date $date$ $time$
**/Variable Definitions – Configure variables such as:
Expression : choose default functions like user , date , time .
Default value : set to TODO if desired.
params and return : provide Groovy scripts to generate @param and @return tags automatically.
Example Groovy script for params :
groovyScript("def result=''; def params=\"${_1}\".replaceAll('[\\[|\\]|\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {result+='* @param ' + params[i] + ((i < params.size() - 1) ? ' \n ' : ' ')};return result", methodParameters())Example Groovy script for return :
groovyScript("def params=\"${_1}\"; if(params=='void'){return ' * @return ';} else {return ' * @return ' + params +' '}", methodReturnType())Set the template's applicable scope to Java files only.
Usage – Type the abbreviation (e.g., /m ) above a method name, press Enter , and IDEA expands the Javadoc template with the defined variables.
The article also shares a collection of useful Java‑8 snippets (e.g., .collect(Collectors.groupingBy(...)) , .collect(Collectors.joining(...)) , .collect(Collectors.toList()) , .collect(Collectors.toSet()) ) as additional Live Templates for rapid coding.
In conclusion, customizing Live Templates streamlines repetitive Javadoc creation, significantly boosting coding efficiency. The author also mentions promotional offers for obtaining IDEA activation codes and AI Assistant plugins, encouraging readers to follow the public account for further resources.
Top Architecture Tech Stack
Sharing Java and Python tech insights, with occasional practical development tool tips.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.