1

I am looking at live templates in IntelliJ IDEA and I wanted to know whether there is a way to log.debug() a variable quickly.

Let's say I want:

var myValue = 10;
log.debug("myValue=" + myValue);

I have log.debug("" + $STRING$); in the live template, but this will force me to include the variable name and text manually. Does IntelliJ have the ability to log a variable that directly precedes my cursor? Or through some other action?

I looked at this too.

riddle_me_this
  • 8,575
  • 10
  • 55
  • 80

1 Answers1

1

Use the soutv Java template as an example:

System.out.println("$EXPR_COPY$ = " + $EXPR$);

Where $EXPR$ is defined as variableOfType("") with "expr" default value and $EXPR_COPY$ is defined as escapeString(EXPR).

Documentation for variableOfType() states:

variableOfType() Returns all variables that may be assigned to the type passed as the parameter. For example, variableOfType("double"), variableOfType("java.util.Vector"), or variableOfType(methodReturnType()).

If you pass an empty string "" as the parameter, the function suggests all variables regardless of their types.

So, all you need to do is to make the similar template but use log.debug instead of System.out.println.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904