Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically generate function header comments in eclipse-cdt?

Tags:

c++

c

eclipse-cdt

Is there a way I can automatically generate the function headers for a function in eclipse cdt ? I have seen related posts which ask to use Alt + Shift + J or type /** before function header and press Enter. However i am wondering if it is possible to get a predefined function header. I tried to define my format in

C/C++ > Code style > Code templates > Comments > Methods

but could not find a way to use it in code.

like image 954
bubble Avatar asked Jan 07 '13 17:01

bubble


2 Answers

I am afraid I have a partial answer for you:

  1. If you go to window -> preferences -> C/C++ -> Editor and select Doxygen under Documentation tool comments, typing /** + enter will fill in the comment with param and return tags automatically. I have found no way to add other fields automatically though.
  2. If you go to windows -> preferences -> C/C++ -> Editor -> Templates, you will be able to create templates that eclipse will be able to auto-complete, when typing their name.
    For example, you can create a template called 'author', set the context to 'doc comment' and set the tag you need as a pattern. For this example, I used @author ${user} (note the use of a variable). Now you can start typing 'aut', press ctrl+space for auto-complete, and your tag will be inserted.

I understand this may not be the answer you are looking for, but it might help. I too have struggled with the eclipse settings to automatically generate these, but you will become very fast at doing this with templates, and you have more control over the actual content.

like image 149
rmhartog Avatar answered Nov 04 '22 17:11

rmhartog


I have found a little workaround.

Create a template in perferences >> C/C++ >> Editor >> Templates Give unique Name (like comfun) use the Variables like i did (${...}

save template

now enter the unique name INSIDE the function declaration and hit ctrl+space (watch out that no text is marked), so eclipse can evaluate the Variables All you have to do is move the auto generated text above the function.

I hope that helps a bit.

/*-----------------------------------------------------------------------------+
|    F U N C T I O N   I N F O R M A T I O N                                   |
+------------------------------------------------------------------------------+
|  ToDo: check auto generated function comment                           |
|                                                                              |
|  Function Name:  ${enclosing_method}                                     |
|                                                                              |
|  Prototype at:   ${file_base}_tdf.h                                   |
|                                                                              |
|  Description:    add some useful content                                     |
|                                                                              |
|                                                                              |
|  Parameter:      ${enclosing_method_arguments}         |
|                                                                              |
|  Return Value:   ${return_type} OK               |
|                                                                              |
+-----------------------------------------------------------------------------*/
like image 26
GreenBærg Avatar answered Nov 04 '22 15:11

GreenBærg