score:1

Accepted answer

press atl+shift+r and change

score:1

as i have commented the scenario, in which refactor won't work

all answer refer to refactor option. but what if i added a new param or deleted a param from method signature. in that case, how to update the javadoc?

there is a workaround i found, but yes it's still not a automated process and is not good for large number of changes.

the workaround is to,
1. remove the javadoc comment and make it plain comment i.e. update the /**' and change it to just/*'.
2. now once again just above the method signature/declaration enter /** and press enter. it would re-populate the updated params and return info. now just move the description lines from the older comment to the new.
3. you can use alt + up/down arrows for achieving this.
4. done delete the old javadoc comment after it's copied in correct place.

score:2

just press alt+shift+j on the method name and delete the extra lines:

before:

/**
 * copies all the details from the passed template into the passed new
 * header.
 *
 * @param pnewheader
 */
private void docopy(int pnewheader, int ptemplate) {

after:

/**
 * copies all the details from the passed template into the passed new
 * header.
 *
 * @param pnewheader   << delete
 */                    << delete
/**                    << delete
 * @param pnewheader
 * @param ptemplate
 */
private void docopy(int pnewheader, int ptemplate) {

score:3

refactoring with the "update references" option is not sufficient. you need to ensure that "process javadoc comments" is checked in window->preferences, java->compiler->javadoc. tweak the preference page like you prefer and it will work fine.

score:4

i don't know about any way to automatically sync the javadoc header, but if you rename a parameter using ctrl-1 + rename in file, the javadoc header is appropriately renamed.

score:12

eclipse provides fairly good options to ensure the correctness of javadoc besides the rename refactor jespere mentioned:

  • the change method signature refactor operation also modifies javadoc (add/remove necessary tags). you should use this one or rename to modify code which are already in use.
  • if you activate add javadoc tags on preferences/java/editor/typing page then eclipse generates the correct javadoc stub after typing /** + enter before a method.

you can also set compiler options to check javadoc missing tags on preferences/java/compiler/javadoc. in this case you get warnings from the compiler on missing/extra tags and you have quickfix (ctrl+1) for fixing them. it is a good option to ensure the correctness of existing javadocs in the long run.


Related Query

More Query from same tag