Configuring Class and Method Javadoc Templates in IntelliJ IDEA
This guide explains how to set up IntelliJ IDEA templates to automatically generate class and method Javadoc comments, including adding author and date placeholders, creating live templates for @param and @return annotations, and customizing variable expressions with Groovy scripts.
Open Settings → Editor → File and Code Templates , select the Class tab and insert the author/date block shown in the screenshot; after saving, new Java classes will include this comment automatically. To make the same work for interfaces, edit the Interface tab similarly.
For method comments, go to Settings → Editor → Live Templates , create a new template group (e.g., userDefine ) and add a new live template with the abbreviation * . Set the Template text to the Javadoc skeleton without the leading /* , ensuring the asterisk is at the start of each line.
Define the applicable contexts as Java so the template applies to all Java files. Then click Edit variables to assign expressions to the placeholders: use built‑in IDEA functions for date and time , and provide custom Groovy scripts for param and return handling.
groovyScript("def result = '';def params = \"${_1}\".replaceAll('[\\[|\\]|\\s]', '').split(',').toList(); for(i = 0; i < params.size(); i++) {if(params[i] != '')result+='* @param ' + params[i] + (i < params.size() - 1 ? '\r\n ' : '')}; return result == '' ? null : '\r\n ' + result", methodParameters()) groovyScript("return \"${_1}\" == 'void' ? null : '\r\n * @return ' + \"${_1}\"", methodReturnType())After confirming the template and variable settings, click OK to save; new methods will now automatically include @param and @return tags based on their signatures.
The article concludes with a Q&A section that clarifies why the abbreviation must be * , why the first line of the template starts with an asterisk, and how the custom scripts avoid generating empty @param lines for methods without parameters.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
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.