45

I know that you can press shift+alt+j to insert an appropriate comment template for the current code block, but is there any way to let eclipse just go crazy and do a whole project like this?

Finbarr
  • 31,350
  • 13
  • 63
  • 94
  • Erm, any valid reason to actually do so? I know people who think auto-generated docs are better than none, but they don't actually contain more information ... it just makes it much harder to find the places that need documenting ... – Joey Mar 27 '10 at 16:45
  • 15
    Yes there is a valid reason to do this. It will save me having to manually press shift+alt+j hundreds of times as I go through all my code writing javadoc. – Finbarr Mar 27 '10 at 17:20
  • I hope you want to know to never use it accidentally ,) – eckes Apr 27 '17 at 01:37

4 Answers4

72

For a whole project, may be not, but you can at least:

  • go to the Package Explorer View
  • expand the class you want to generate comment on (open each method)
  • select all the opened elements in the class from that Package Explorer Tree
  • alt+shift+J and voilà: comments generated on the class, and every method

The only reason it is not practical for the all project is:

  • you need to open every class you want to generate comments on
  • once a first set of methods have been commented, you still need to repeat the process if you have written new methods.

That being said, another approach is described in the article "The Problem of Incomplete Javadocs" from March, 30th 2010, advocating for an extended Javadoc view.

The extended Javadoc View is essentially an aggregator of different information sources for a single code element like a class, method, field or parameter. It is designed as a replacement for the existing Eclipse Javadoc.

alt text

The interesting part comes with the other tabs in the view: Subclassing Directives and Subclassing Patterns.
These tabs contain mined information about how developers typically extended the selected code element.

  • Subclassing tab:

subclassing directives are generalizations of frequently made observations in example code like "Subclasses of Wizard always override its method addPages()" or "Reimplementors of Dialog.createContents() may call its super implementation".

http://code-recommenders.googlecode.com/svn/wiki/images/extdoc/tab-subclassing-directives-Wizard.png

http://code-recommenders.googlecode.com/svn/wiki/images/extdoc/tab-subclassing-directives-Wizard-addPages.png

  • Subclassing Patterns Tab

Subclassing patterns try to group observed extensions of a base class into typical extension patterns, i.e., they cluster subclasses by similarity to find patterns in data.

http://code-recommenders.googlecode.com/svn/wiki/images/extdoc/tab-subclassing-patterns-ViewerComparator.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Could you please point to the menu item for the shortcut Alt + Shift + J for us Mac people? – Nithesh Chandra Mar 04 '11 at 09:29
  • @Nithesh: Cmd-Shift-J on a Mac as mentioned in http://mobile.tutsplus.com/tutorials/android/javadoc/ – VonC Mar 04 '11 at 09:59
  • Note to self: the "nice answer" and "Enlightenment" badges coming with that 10th vote marked my 1000th badge on SO, the 24 August, 2012. – VonC Aug 28 '12 at 09:10
  • Menu item is: Source > Generate Element Comment – Derek Dec 16 '13 at 09:02
  • 1
    Alt + Shift + J doesn't work for me on windows. Please juste mention the menu – Maude Nov 30 '18 at 16:03
  • @Maude Strange, that should work. What version of Eclipse are you using? Something might have changed since 2010 (time of my old answer) – VonC Nov 30 '18 at 16:32
23

I was also looking for an auto javadoc tool for eclipse and found one called JAutodoc.

This tool generates comments pretty well and requires only minor changes manually in some places (if you require). In my opinion, this tool can save approximately 75% of the time spent in writing comments.

You may visit here for detailed instructions on downloading and integrating it with eclipse.

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
Arun
  • 231
  • 2
  • 2
  • 1
    Thanks @Arun. I have comments configured in Eclipse, but Alt+Shift+J puts an empty javadoc instead of using the configured one (Preferences > Java > Code Style > Code Templates). JAutodoc did just what I wanted. I now have JAutodoc on the required list :) – Indu Devanath Apr 11 '14 at 01:04
  • JAuto Doc generates better comments than the eclipse Alt+Shift+J – Sabyasachi Feb 23 '17 at 13:37
6

There's also this plugin, which I have yet to try, but looks promising: JAutoDoc

StormFoo
  • 1,129
  • 2
  • 10
  • 25
1

Adding a menu image because someone asked for it. @Maude This is on Eclipse IDE 2020-09 (4.17).

Note: Some users change their shortcut hotkeys to suit their workflow, so we should never dismiss someone and tell them outright to use shortcuts, or figure out why shortcuts don't work on their ends.

The context menu itself is contextualized, so it really depends on where you right click.

enter image description here

tom_mai78101
  • 2,383
  • 2
  • 32
  • 59