在 Intellij 中为 Apache Velocity 宏参数启用隐式上下文变量解析

Enabling Implicit Context Variables Resolution for Apache Velocity macro parameters within Intellij

我发现 Intellij 隐式上下文变量在创建 Apache Velocity 模板时非常有用。

例如:

#* @vtlvariable name="order" type="com.mycompany.vo.PlacedOrderVO" *#
#* @vtlvariable name="formatHelper" type="com.mycompany.FormatHelper" *#
#* @vtlvariable name="i18n" type="com.mycompany.I18nWriter" *#

但是,我想不出为宏变量提供上下文的方法。有谁知道方法吗?

问题最初在这里提出: https://blog.jetbrains.com/idea/2009/08/enabling-implicit-context-variables-resolution-in-template-files/

Intellij 建议创建像普通速度变量一样的文件级定义,但是编辑器不会将接触变量应用于宏变量,我仍然在宏中收到黄色警告。

我也会考虑抑制我在宏中收到的少数警告,但 Intellij 不提供宏中语句级抑制的选项,仅在文件范围内提供。

谢谢。

我不知道几年前您问这个功能是如何工作的,但目前(IntelliJ IDEA 2020.3.1)它似乎在工作。

#* @vtlvariable name="list" type="java.util.List" *#
#macro( disabled $list ) #if($list.isEmpty()) disabled #end #end