Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add comment block to methods in Eclipse?

Is there an easy of adding a comment block (Javadoc style) to every method in an Eclipse project and possibly classes so I can fill in them later?

like image 570
Kalimah Avatar asked Sep 11 '11 14:09

Kalimah


3 Answers

As suggested you can do it method-per-method (Source -> Generate element comment) or ALT+SHIFT+J but I find it a very bad idea. Comments are only useful when they give an additional information. When you feel more information is needed add it.

Having comments on setters like "sets the value" or worse automatically generated comments it not useful at all.

like image 107
Matteo Avatar answered Oct 29 '22 03:10

Matteo


To add a comment over the method select getUser or take the cursor before getUser and press ALT + SHIFT + J It will add the comment on top of your method

/*
* @param
* @return User
*/
public User getUser();
like image 21
David Avatar answered Oct 29 '22 03:10

David


Under

Window | Preferences | Java | Code Style | Code Templates

you will find 2 features:

  • Automatically add comments for new methods or types
  • Comments | Methods | Edit...

You can edit the generated comment block by use of eclipse variables or your static Javadoc text.

like image 39
r2d2 Avatar answered Oct 29 '22 02:10

r2d2