在Intellij中自动完成@author

rkc*_*cpi 81 javadoc intellij-idea

我正在从Eclipse迁移到Intellij Idea.我无法弄清楚的一件事是@authorJavaDoc标签的自动完成.@a在Eclipse中键入时,有两个提议:

@author - author name
@author
Run Code Online (Sandbox Code Playgroud)

我如何在Intellij中实现第一个提案(甚至可能吗?)?如果可能,如何更改为作者姓名占位符插入的内容的模板?

lev*_*tor 207

还有一个选项,不完全是你问的,但可能有用:

转到Settings- > Editor- > File and code templates- > Includes选项卡(右侧).新文件有一个模板标题,您可以在此处使用用户名:

/**
 * @author myname
 */
Run Code Online (Sandbox Code Playgroud)

对于系统用户名:

/**
 * @author ${USER}
 */
Run Code Online (Sandbox Code Playgroud)

屏幕截图来自Intellij 2016.02

  • IDEA 15:文件>设置>您的步骤. (7认同)

Len*_*art 66

您可以通过实时模板解决这个问题.转到设置 - >实时模板,单击"添加" - 按钮(右侧的绿色加号).

在"缩写"字段中,输入应激活模板的字符串(例如@a),并在"模板文本"区域中输入要完成的字符串(例如@author - My Name).将"适用的上下文"设置为Java(仅限注释)并设置完成的键(在右侧).

我测试了它并且工作正常,但是IntelliJ似乎更喜欢inbuild模板,所以"@a + Tab"只完成"作者".Space但是,将完成键设置为有效.

要更改通过文件模板自动插入的用户名(例如,在创建类时),可以通过添加来更改

-Duser.name=Your name

IntelliJ/bin目录中的idea.exe.vmoptionsidea64.exe.vmoptions(取决于您的版本).

在此输入图像描述


Tar*_*ekB 14

选中启用实时模板并将光标留在所需的位置,然后单击应用然后确定

在此处输入图片说明


Sud*_*ary 10

对于 Intellij IDEA Community 2019.1,您需要执行以下步骤:

File -> New -> Edit File Templates.. -> Class -> /* Created by ${USER} on ${DATE} */

在此处输入图片说明


Ale*_*sco 5

这里只是回答一些问题:

您还可以添加采用以下值的预定义变量:

${PACKAGE_NAME}      Name of the package in which the new file is created
${USER}              Current user system login name
${DATE}              Current system date
${TIME}              Current system time
${YEAR}              Current year
${MONTH}             Current month
${MONTH_NAME_SHORT}  First 3 letters of the current month name. Example: Jan, Feb, etc.
${MONTH_NAME_FULL}   Full name of the current month. Example: January, February, etc.
${DAY}               Current day of the month
${DAY_NAME_SHORT}    First 3 letters of the current day name. Example: Mon, Tue, etc.
${DAY_NAME_FULL}     Full name of the current day. Example: Monday, Tuesday, etc.
${HOUR}              Current hour
${MINUTE}            Current minute
${PROJECT_NAME}      Name of the current project
Run Code Online (Sandbox Code Playgroud)