如何在 IntelliJ Idea 实时模板中完成字符串内的变量名称?

How to complete variable names inside a string in IntelliJ Idea live templates?

从 Eclipse 迁移是轻而易举的事。我使用的最常见的模板之一是记录上次使用的变量的值。

例如

String foo="bar";

日志选项卡>

->

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

我尝试使用:

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

同时使用 complete()completeSmart() 作为变量类型,但它们都失败了,即没有提供任何理智的自动完成建议。

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

简而言之:LOGGER.debug("$VAR_COPY$: {}", $VAR$);并定义第一个 VAR:variableOfType(Type),默认 "expr" 和下一个 $VAR_COPY$ escapeString(VAR),如果定义为真则跳过。用想法 15 测试。

成功了

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

2) 在 EXPR_COPY

之前移动 EXPR

3) 将 EXPR 类型设置为 completeSmart()

4) 将 EXPR_COPY 设置为 escapeString(EXPR)