intellij-ideawebstormvelocitycopyright-display

IntelliJ - Update Copyright Year


I have a copyright profile defined in IntelliJ as Copyright ${today.year}, All Rights Reserved. This works great on new files, however on existing files I would like to update the existing year to a range or update the end-date of an existing range to ${today.year}.

IntelliJ supports using Velocity in copyright templates. Is there a way to leverage Velocity to do this? From what I can tell, Velocity allows for if-statements yet I am unsure how to get the previous years as variables.

Examples:

New document: Copyright 2018

Copyright 2017 to Copyright 2017-2018

Copyright 2015-2017 to Copyright 2015-2018

Reference:

IntelliJ supported variables

Velocity User Guide


Solution

  • It is possible now. More information in the JetBrains documentation.


    Add this to your Copyright matcher:

    Copyright $originalComment.match("Copyright (\d+)", 1, "-")$today.year
    

    This does exactly this:

    New document: Copyright 2022

    Copyright 2017 to Copyright 2017-2022

    Copyright 2015-2022 to Copyright 2015-2022