Intellij Insert File Template Header

纵然是瞬间 提交于 2021-01-21 07:58:11

问题


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.


回答1:


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




回答2:


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.




回答3:


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

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




回答4:


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.




回答5:


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

Write This:

/**
 * @author : ${USER}
 * @created : ${DATE}, ${DAY_NAME_FULL}
**/

To see an header like this:

/**
 * @author : BUY
 * @created : 21/08/2020, Friday
 **/
public class Foo{}



回答6:


I do this by Alfred Snippets

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



来源:https://stackoverflow.com/questions/4778543/intellij-insert-file-template-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!