Live Template - hold variable with number that autoincrements

Answered

Hello,

Is there any way for Live Template to use something like a static integer value, that would be incremented each time it is called? Or in other words, an expression that would dynamically assign an incremented numerical value, based on the last value it was called from it. The way around would be to scan the current class file, use something like Regex to find certain String patterns, and return an increment of the biggest value.
I'm doing a lot of manual debugging recently with printing debug lines into the logs and want to simplify it. I like to use a format like this:

'STZAN1 class: Foo, method: bar; 2020-12-28'
'STZAN2 class: Foo, method: bar; 2020-12-28'

Which are: my initials, number of debug line created in class, class name, method name, current date.

I'm struggling to create something for a number of debug line bit, I do not want to use line(). In terms of code, I would imagine something like that:

static int counter = 0;
static int getCounter(){ return counter++; } // that would be called

I work in Java and Apex.

1 comment
Comment actions Permalink

You could create a custom function (Macro) and refer to it in your live-template. The Macro itself can then programmatically provide any kind of (increasing) value. See https://jetbrains.org/intellij/sdk/docs/tutorials/live_templates/new_macros.html

0

Please sign in to leave a comment.