jmq
jmq

Reputation: 10370

Intellij Insert File Template Header

When you create a new java class in Intellij a file header is automatically inserted (based on "File Templates" options). Is there a way to insert that same template into an existing java source file? I was hoping there was a way to use my template definition on existing code without doing a cut/paste all over the place. The template makes use of macro expansion and I hope to be able to keep that. There is a similar function in eclipse called "Generate Element Comment" that would handle this case. Does this exist within Intellij IDEA?

Any help would be much appreciated.

Upvotes: 10

Views: 28036

Answers (6)

BUY
BUY

Reputation: 736

File -> Settings -> Editor -> File and Code Templates -> Includes -> File Header

Write This:

/**
 * @author : ${USER}
 * @mailto : [email protected]
 * @created : ${DATE}, ${DAY_NAME_FULL}
**/

To see an header like this:

/**
 * @author : BUY
 * @mailto : [email protected]
 * @created : 21/08/2020, Friday
 **/
public class Foo{}

Upvotes: 9

Milan Paudyal
Milan Paudyal

Reputation: 561

go to Settings > File and Code Templates then include tab and select header and define you

/** * @author : Name * @since : ${DATE}, ${DAY_NAME_SHORT} **/

Upvotes: 6

Oleg Sokolov
Oleg Sokolov

Reputation: 1143

You can reach your aim using the Replacing all dialog.

Call the Replacing all dialog, in a top filed set a package word and in a bottom field set \/\*\nYour file header\n\*\/\n\npackage and press a Replace All button.

You can specify a set of files which should be upgraded by using a In Project / Module / Directory / Scope settings.

enter image description here

Upvotes: 1

Jameson
Jameson

Reputation: 107

I do this by Alfred Snippets

Add following config in alfred snippet, and when I insert !header, it automaticlly insert wished template.

enter image description here

Upvotes: -1

kinORnirvana
kinORnirvana

Reputation: 1705

Use Copyright header instead. Configure your Copyright profile as stated at jetbrains.com. Press Alt-Insert or Right mouse click -> select "Generate" -> "Copyright".

You can check what variables you can use in Copyright statement here.

Upvotes: 19

Mario Arias
Mario Arias

Reputation: 176

Maybe the best solution is to use a "Live Template" but you can´t reuse the File Template, so, you will need at last one copy/paste operation

Upvotes: 2

Related Questions