zzxwill
zzxwill

Reputation: 536

How to edit comment template and add type or function comment in JetBrains IntelliJ IDEA?

In JetBrains IntelliJ IDEA, I would like to edit comment which is like

/**
 * Created by IntelliJ IDEA.<br/>
 * User: ${USER}<br/>
 * Date: ${DATE}<br/>
 * Time: ${TIME}<br/>
 * To change this template use File | Settings | File Templates.
 */

and generate comment for a type like

public class MyUsernamePasswordAuthenticationFilter extends UsernamePasswordAuthenticationFilter

or a function like

protected  void checkUsbKeyID(UserObj user,String usbKeyID)

Upvotes: 35

Views: 25279

Answers (2)

davnicwil
davnicwil

Reputation: 30957

To change the specific template for Classes, edit the Class template.

Example menu locations (should be broadly similar on other platforms/versions)

IntelliJ 2016, Mac

Preferences > Editor > File and Code Templates > Files tab > Class item

IntelliJ 14.x, Mac

Preferences > Editor > File and Code Templates > Templates tab > Class item

It looks like this

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}

The link to the sub-template which generates the comments is #parse("File Header.java") on the second line.

You can remove that and put a custom comment template for Classes inline here.

or

You can edit the File Header template under the includes tab, which is also used by other things, and edit that

Upvotes: 13

chalimartines
chalimartines

Reputation: 5653

Type comments you can edit in menu File -> Settings -> File Templates. Then you look to tab Includes and edit entry File Header

enter image description here

Method comments isn't possible to edit, I think.

Upvotes: 55

Related Questions