intellij-idea - 在intellij模板中区分int和double
问题描述
我在 IntelliJ 中定义了一个自定义 toString 模板。IntelliJ 提供了一个基于 Velocity 脚本语言的模板系统。好东西 !
但我现在正面临一个特殊的问题。我需要区分int
字段和double
字段。本质上是生成类似(简化)的东西:
public String toString() {
String output = "";
output += "myIntField:" + Util.intDescription(myIntField);
output += "myDblField:" + Util.doubleDescription(myDblField);
return output;
}
对于Integer
它工作正常的类型,但我似乎无法让它为 original 工作int
。
#if ($member.typeQualifiedName == "java.lang.Integer")
...
#end
#if ($member.typeName == "Integer")
...
#end
我可以使用类似$member.primitive
and的方法构建结构,$member.numeric
但它们都没有区分double
and int
。
IntelliJ的文档给我的印象是我陷入了死胡同。
PS:当然可以解决,通过改变java代码/api,可以简化toString()
方法所需的格式。但这对我来说真的是最后的手段。
解决方案
#elseif ( $member.type == 'double' )
output += "myDoubleField:" + Util.doubleDescription(myDoubleField);
#elseif ( $member.type == 'int' )
output += "myIntField:" + Util.intDescription(myIntField);
无论出于何种原因,我都无法访问 $member.isDouble 属性。它没有列在IntelliJ 的文档、VTL 参考或VTL 用户指南中,.type 也没有。
我首先打印出 $member,它列出了这个对象的所有属性。我不确定为什么它列出了 isDouble。
推荐阅读
- docker - 替换文件时Docker绑定挂载不起作用
- javascript - 在 Edge 浏览器中,如何执行 window.open() 并且不在新窗口或标签中保持会话?
- rdflib - 有没有办法将 rdflib 序列化程序配置为使用特定的 UTC 日期格式?
- python - Scrapy ModuleNotFoundError:没有名为“import”的模块
- android - Android:订阅版本的促销代码
- python - Pandas groupby 组之间的操作
- sharding - 当我们在运行时增加分片时,Kinesis 如何保证消息的顺序?
- python - 如何找到最接近质心的“x”数量的元素
- azure-devops - 如何在 Azure DevOps 中跨项目引用用户?
- python - 错误:UndefinedVariableError:未定义名称“injured_persons”