String manipulation in File and Code Templates

Answered

I am improving my IDE by introducing quite some File and Code Templates to make my live a bit easier.

We have a codebase where we do a lot of scheduled work. To implement these we have some structure in which we use schedlock to lock some database rows. I want to have my template to use the classname to get a kebab-cased schedlock name.

Example, if I generate file `FooBarScheduler`, I want it to generate a string that becomes `foo-bar-scheduler`. 

If I would add a Live Template, I would have been able because of `lowercaseAndDash(String)`.

How would i be able to achieve this?

0
1 comment

To answer my own question, I have got it working with the following:

 

#set($KEBAB_CASED_SCHEDULER_NAME = $SCHEDULER_NAME.replaceAll("([A-Z])", "-$1").toLowerCase().replaceAll("^-", ""))
1

Please sign in to leave a comment.