Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically add Copyright to new Java files in IntelliJ 12

I have registered a Copyright profile in preferences and set it as the default. I also have a scope registered for that profile set to "All". I can add it to a file by doing "cmd+N (generate) -> Copyright".

I don't want to have to do this manually for every new class I create. how can I have this automatically added to all new classes from now on?

like image 373
Paul Robinson Avatar asked Dec 09 '12 10:12

Paul Robinson


People also ask

How do I add copyright to all files in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Editor | Copyright. From the Default project copyright list, select the profile you want to use as the default profile. Apply the changes and close the dialog. After that you can add the copyright to the necessary files.

How do I set default comments in IntelliJ?

Add a new commentType /** before a declaration and press Enter . The IDE auto-completes the doc comment for you. For information on how to disable this feature, refer to Disable automatic comments.

How do I add author details in IntelliJ?

Go to Settings -> Editor -> Live Templates , click the Plus Icon Button (on the right). In the "Abbreviation" field, enter the string that should activate the template (e.g. @a ), and in the "Template Text" area enter the string to complete (e.g. @author - My Name ).


2 Answers

You have to set the Default Project Copyright for your project.

Go to File | Settings | Editor | Copyright, after you have made a new Copyright Profile, you must select it from the drop-down list as the Default project copyright.

You have to set this for every project, but once it is set, it should automatically be inserted at the top of every new file created in that project.

like image 114
NickD Avatar answered Sep 19 '22 16:09

NickD


Copyright is not added automatically to the new files, you can use the Update Copyright action on the project root node in the Project View to add/update it for all the files at once or you can enable Update Copyright option in the Commit Project dialog to be sure that files shared via VCS always have the most recent copyright.

UPDATE: I've verified that copyright is added automatically for me, however it may be hard to notice that it was actually added as by default it appears at the very top of the file and is collapsed, editor also doesn't scroll to the top and remains where it was. If you scroll editor up and unfold the top comment, you should be able to see the automatically added copyright. You can also change the Location in files setting per file type to see that it's added when the new file is created.

Here is the screencast showing that it works.

like image 22
CrazyCoder Avatar answered Sep 23 '22 16:09

CrazyCoder