213

Is there a way to generate Javadoc comments in Eclipse? If so, what is it?

Community
  • 1
  • 1
antony.trupe
  • 10,640
  • 10
  • 57
  • 84

5 Answers5

366

For me the /**<NEWLINE> or Shift-Alt-J (or --J on a Mac) approach works best.

I dislike seeing Javadoc comments in source code that have been auto-generated and have not been updated with real content. As far as I am concerned, such javadocs are nothing more than a waste of screen space.

IMO, it is much much better to generate the Javadoc comment skeletons one by one as you are about to fill in the details.

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 17
    To save space, fold it! – Pascal Thivent Nov 22 '09 at 01:18
  • 29
    @Pascal - I'd prefer to delete it/them, or not generate it/them in the first place. IMO, generated javadoc comments add zero value ... unless you count a bogus boost to the comment-to-code ratio as "value". – Stephen C Nov 22 '09 at 02:54
  • 5
    important note: If using shift-alt-j, don't forget to place the cursor first in the method you want to document otherwise your comment will be added at the top of the file for the class. – thedrs Oct 13 '16 at 07:38
87

Shift-Alt-J is a useful keyboard shortcut in Eclipse for creating Javadoc comment templates.

Invoking the shortcut on a class, method or field declaration will create a Javadoc template:

public int doAction(int i) {
    return i;
}

Pressing Shift-Alt-J on the method declaration gives:

/**
 * @param i
 * @return
 */
public int doAction(int i) {
    return i;
}
coobird
  • 159,216
  • 35
  • 211
  • 226
39

JAutoDoc:

an Eclipse Plugin for automatically adding Javadoc and file headers to your source code. It optionally generates initial comments from element name by using Velocity templates for Javadoc and file headers...

gnat
  • 6,213
  • 108
  • 53
  • 73
antony.trupe
  • 10,640
  • 10
  • 57
  • 84
27

You mean menu Project -> Generate Javadoc ?

Mirek Pluta
  • 7,883
  • 1
  • 32
  • 23
  • That menu item isn't in any of the perspectives I use. – antony.trupe Nov 21 '09 at 23:53
  • It's on my Eclipse, and the only extra things I've installed are Google Web Toolkit and FindBugs. (This is Ganymede, not Europa. Maybe you need to upgrade?) – Paul Tomblin Nov 21 '09 at 23:56
  • I only have the gwt perspective, eclipse v 3.5.1 – antony.trupe Nov 21 '09 at 23:58
  • 2
    Maybe you need to install Eclipse for Java Developers or Eclipse for J2EE developers. – Jherico Nov 22 '09 at 00:00
  • What happens if you go to Preferences->Java->Code Templates and click "restore defaults"? Because I have code templates for comments that includes all the javadoc stuff. – Paul Tomblin Nov 22 '09 at 00:01
  • it appears all the templates are present. I clicked "restore defaults" to be sure nothing crazy is going on. I just don't have that menu option. My hunch is I have a subset of the "usual" features of eclipse. – antony.trupe Nov 22 '09 at 00:05
  • 2
    Anyway, this is not what the OP is looking for. The question (which is a bit misleading) is not about generating the javadoc but adding javadoc "comments" in the code. – Pascal Thivent Nov 22 '09 at 00:35
23

At a place where you want javadoc, type in /**<NEWLINE> and it will create the template.

bmargulies
  • 97,814
  • 39
  • 186
  • 310