简体   繁体   中英

How to set JavaDoc to update automatically when I change the method signature in Android Studio or IntelliJ IDEA

Is there a way to make JavaDoc update and add extra corresponding tags when I for example add return value to a method which was void before. This way JavaDoc will be updated as we change the code.

This related question asked 6 years ago for eclipse but no answer to that yet. As it says there too in the comments it's not about refactoring a name.

 /**
 * Some explanation about method.
 *
 * @return (I want this tag to be added automatically after I add return type "int" to method)
 */
private int ourMethod() {
    int price = quantity * 5;
    return price;
}

I found this also can be useful.

"Fix doc comment" is a simple useful way to automatically add JavaDoc for a method. Assign a shortcut in Keymap setting (alt+shift+0 for example) and hit it when the caret is inside a method, it also updates the current JavaDoc according to changes you've just made and moves the caret inside JavaDoc to make things easier.

As of version 2016.2, there is no feature in IntelliJ IDEA that would add a @return tag for a method when you change its return type.

For parameters, if you use the "Change signature" refactoring, it will add @param tags for new parameters, delete them for parameters you remove, and update them for parameters you rename. The Rename refactoring will also rename @param tags.

As far as I know there is no automatic method to add the JavaDoc by changing it's method. However, you can do it by start typing /** at the top of the method and press enter. The parameters as well as the return are inserted automaticly then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM