Generate Precise Java Javadoc with AI in One Shortcut
This article explains how an IntelliJ plugin uses large‑language‑model AI to read your Java method body and automatically produce accurate Javadoc comments, eliminating the need for manual documentation and overcoming the limitations of simple name‑translation tools.
After creating a naming‑assistant plugin, the author tackled another pain point: writing code comments. Existing comment generators merely translate method names, producing vague documentation that adds little value, especially when method names are poorly chosen.
AI‑Powered Comment Generation
The new plugin adds an "AI Smart Comment" feature. Place the cursor anywhere inside a method body, press Alt+M, and after a brief pause the plugin inserts a Javadoc comment that reflects the actual logic of the method.
Position the cursor inside the target method (no selection required).
Press the shortcut Alt+M (customizable).
Wait one to two seconds for the AI to analyze the code and generate the comment.
Example
Original method:
public List<String> process(List<User> userList) {
List<String> result = new ArrayList<>();
for (User user : userList) {
if (user.isActive() && user.getAge() > 18) {
result.add(user.getEmail());
}
}
return result;
}After pressing Alt+M:
/**
* 从用户列表中筛选出状态为活跃且年龄大于18岁的用户,并返回他们的邮箱地址列表。
*
* @param userList 用户对象列表
* @return 符合条件的用户的邮箱地址列表
*/
public List<String> process(List<User> userList) {
// ... 方法体 ...
}The AI understood the filtering and aggregation logic, generating a meaningful description regardless of the method name.
Configuration Modes
Simple mode : Generates standard Javadoc with brief @param and @return explanations.
Detailed mode : Produces comprehensive Javadoc, suitable for libraries or critical APIs.
Model Selection and API Key
The plugin supports multiple Zhipu AI models; performance varies by model. Users can apply for their own API key on the Zhipu Open Platform, or use the author’s key (slower).
Usage Tips
Once installed, the shortcut quickly becomes muscle memory. Update to the latest version to access the feature, and install the plugin from the IntelliJ Marketplace by searching for "Easy Naming" (the original naming tool, now enhanced).
By automating comment creation, developers can save time and mental effort, allowing them to focus more on core development tasks.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.
