Reputation: 5338
IntelliJ IDEA has a convenient feature which can maintain copyright comments in your code, via the Update Copyright action.
Yet, the documentation is scarce and barely covers one single use-case.
The question is, what is the exact signature (and behaviour) of the ${originalComment.match()}
function? Looking at the Velocity template language documentation, there's no standard match()
function.
Looking at the only example provided by JetBrains:
$originalComment.match("Copyright \(c\) (\d+)", 1, "-")
1
) is probably the number of the RE capturing group to extract, and"-"
) is the suffix to be appended to the extracted RE group value.Yet, after some testing, the behaviour of the function seems counter-intuitive.
My own use case:
Copyright (c) 2024-2024
as their copyright statement.Copyright (c) 1970
should get updated to Copyright (c) 1970-2024
.Copyright (c) 1970-1971
→ Copyright (c) 1970-2024
.Copyright (c) 2024
→ Copyright (c) 2024-2024
.Copyright (c) 2024-2024
should remain intact on update.What my Velocity template should look like?
The closest I could get to the solution is
Copyright (c) My Company ${originalComment.match("Copyright \([Cc]\) .+ (\d{4})(?:\-\d{4})?", 1, "-")}${today.year}.
— but, obviously, it doesn't work for new code (Item 1 is not covered) and, strangely, Item 4 doesn't work, either (despite I'm not using any ignore values).
Upvotes: 1
Views: 178
Reputation: 127
For my personal use case I keep an original Copyright year in the code and do not update it to the current year.
#set( $oldYear = $originalComment.match("Copyright \(c\) (\d{4})", 1, ""))
Copyright (c) #if($oldYear)$oldYear#{else}$today.year#end
For your use cases you can define as many catching variables and use them in exact scenarios.
Upvotes: 0