0

Migrating from Eclipse where doing this was a breeze. One of the most common templates I used was logging the value of last used variable.

E.g.

String foo="bar";

log tab>

->

String foo="bar";
log.debug("foo:{}",foo);

I tried using:

log.debug("$var$:{}",$var);

with both complete() and completeSmart() as variable types, but they both failed miserably, i.e. did not provide any sane autocomplete suggestions.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Seppo420
  • 2,041
  • 2
  • 18
  • 37

2 Answers2

1

See: How to use variable value in live templates in Intellij IDEA?

In short: LOGGER.debug("$VAR_COPY$: {}", $VAR$); and define first VAR: variableOfType(Type), default "expr" and next $VAR_COPY$ escapeString(VAR) and skip if defined true. Tested with Idea 15.

Community
  • 1
  • 1
tfriman
  • 71
  • 1
  • 4
0

This did the trick

1) log.debug("$EXPR_COPY$:{}",$EXPR$);

2) moving EXPR before EXPR_COPY

3) setting EXPR type as completeSmart()

4) setting EXPR_COPY as escapeString(EXPR)

Seppo420
  • 2,041
  • 2
  • 18
  • 37