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, "-")
- the 1st argument is the regular expression per se,
- the 2nd one (
1) is probably the number of the RE capturing group to extract, and - the last one (
"-") 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:
- New files should have
Copyright (c) 2024-2024as their copyright statement. Copyright (c) 1970should get updated toCopyright (c) 1970-2024.Copyright (c) 1970-1971→Copyright (c) 1970-2024.Copyright (c) 2024→Copyright (c) 2024-2024.Copyright (c) 2024-2024should 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).