How to autogenerate xml based function header comments (@param etc) in Eclipse. Is there an equivalent of "///" shortcut in Visual Studio.
-
2move cursor at starting of method and press `ALT+SHIFT+J` – Pratik Butani Sep 28 '13 at 06:29
4 Answers
In the line just before the method definition, type /**
and hit enter.
In the IDE, type /**
just before the method and hit enter.
Eclipse will autogenerate the Javadoc tags and the end */
type /** here and his enter, eclipse will generate the javadoc tags and the end */
public void setName(String name)
{
...
}

- 18,126
- 4
- 62
- 76
-
-
@MennoGouw it does not comment out all the code. Eclipse auto generates the `*/` also. And this generates the JavaDoc tags as well. (Faizan's answer is also correct, another way of doing exactly the same thing). I will update my answer to make it clear. – Nivas Jun 16 '14 at 12:53
-
It was working for me but today it stopped working. On pressing enter after /** the comment block appears but there is no `@param` and `@return` variables declared. Any workaround? – gonephishing Mar 22 '16 at 14:49
-
The contents and tags that are autogenerated on hitting `/**` come from "Code Templates" in preferences. – Nivas Mar 23 '16 at 12:29
You can do this by clicking ALT+Shift+J
inside the method/class. | It's not XML Based though, but you can generate JavaDoc by clicking Project->Generate JavaDoc...
in the menubar.

- 8,634
- 8
- 34
- 63
-
Its worth noting that the "/**" method will not work if there's already some form of comment before the method, but this one will. Admittedly, /** is easier to remember, so it's a tradeoff. – RHSeeger Oct 27 '10 at 14:11
-
@RHSeeger, yes. But as you said /** is easier to remember, and I have faced this issue only a very few times. – Nivas Oct 27 '10 at 14:19
-
1@Nivas: Oh, I agree. I use the /** method in a vast majority of cases. It's good to know the alt/shift/J method though for when you have comments right before a method... so you don't need to remove them just to autogenerate the javadoc. – RHSeeger Oct 27 '10 at 17:05
You can specify what is autogenerated in Eclipse by going to Window->Preferences
Under, Java -> Code Style -> Code Templates; is the list of what comments get put where. You can google for the syntax of how to insert the different param names and other constants so that you can generate whatever comment you wish, be it Javadoc or other.
As Nivas said, typing /** then hitting enter will auto insert a the comment.

- 13,757
- 13
- 66
- 84
http://jautodoc.sourceforge.net/
JAutodoc is 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.

- 1,005
- 1
- 9
- 16