8

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.

bubble
  • 3,408
  • 5
  • 29
  • 51

2 Answers2

15

I am afraid I have a partial answer for you:

  1. If you go to -
  • C/C++ -> Editor: "Documentation tool comments" -> "Workspace default": Doxygen

        And type /** + enter this will fill in the comments with param & return tags automatically

        I have found no way to add other fields automatically though

  1. 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.

J-Dizzle
  • 4,861
  • 4
  • 40
  • 50
rmhartog
  • 2,293
  • 12
  • 19
1

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               |
|                                                                              |
+-----------------------------------------------------------------------------*/
GreenBærg
  • 115
  • 1
  • 9