views:

100

answers:

3

I am using Eclipse IDE for my Java Project.

I have one problem. I have the methods in my project which have the javadoc comments like as follows:

/**
 * Retruns the string representation of a input stream
 * @param in
 * @return
 * @throws IOException
 */
public static String getStringFromInputStream (InputStream in) throws IOException {
    StringBuffer out = new StringBuffer();
    byte[] b = new byte[4096];
    for (int n; (n = in.read(b)) != -1;) {
        out.append(new String(b, 0, n));
    }
    return out.toString();
}

Now I want to know that Is there any way by which whenever if I make changes in my method's signature, those changes reflect in the javadoc automatically.

+4  A: 

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.

JesperE
+1  A: 

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.

Csaba_H
A: 

Press Atl+Shift+R and change

Yatendra Goel
Only works with parameter names. Signature changes also include adding/removing parameters, changing the throws clause, etc.
Willi