7

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.

4

2 回答 2

14

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.

于 2013-01-15T19:02:15.743 回答
1

我找到了一些解决方法。

在首选项 >> C/C++ >> 编辑器 >> 模板中创建一个模板 给出唯一名称(如 comfun)像我一样使用变量(${...}

保存模板

现在在函数声明中输入唯一名称并点击 ctrl+space(注意没有标记任何文本),因此 eclipse 可以评估变量您所要做的就是将自动生成的文本移动到函数上方。

我希望这会有所帮助。

/*-----------------------------------------------------------------------------+
|    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               |
|                                                                              |
+-----------------------------------------------------------------------------*/
于 2017-02-02T16:18:20.097 回答