Live templates - default value for $SELECTION$ if empty?

Hi,

I was adding a couple of live templates for logging purposes and found that I miss some features (or maybe they exist but I didn't found them)

I have created this live template:

     if(log.isDebugEnabled()) {
       log.debug($END$);
     }


And that works fine for new log statements, but what if I have existing a log.debug row and whant to surround it with the if-statement?

     log.debug("This already existed");

should be:

     if(log.isDebugEnabled()) {
       log.debug("This already existed");
     }


Is this possible to do withe ONE live template?

It would be good to have conditions on the $SELECTION$ so that if it's empty I could have a default value (in this case "log.debug($END$);" )
Is this possible?


thanks,
Lennart

1 comment
Comment actions Permalink

Hello Lennart,

There is no way to do this via live templates, but there's an inspection
that can do this for you automatically. It's called "Log statement not guarded
by log condition".

I was adding a couple of live templates for logging purposes and found
that I miss some features (or maybe they exist but I didn't found
them)

I have created this live template:

 if(log.isDebugEnabled()) {
> log.debug($END$);
> }
> ]]>

And that works fine for new log statements, but what if I have
existing a log.debug row and whant to surround it with the
if-statement?

 already existed");]]>

should be:

 if(log.isDebugEnabled()) {
> log.debug("This already existed");
> }]]>

Is this possible to do withe ONE live template?

It would be good to have conditions on the $SELECTION$ so that if it's
empty I could have a default value (in this case "log.debug($END$);" )

Is this possible?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.