Proper way to pattern match the value of a TypeTree from a ValDef in Scala Macros?

北城余情 提交于 2019-12-11 07:13:46

问题


I need to read the fields of a case class and do different things depending on the field's type.

I thought I'd try with a macro, reading the ValDefs and pattern matching on the TypeTree of each, but that doesn't reveal what each TypeTree represents (e.g. Ints and Strings both appear as TypeTrees).

Is there an alternative to calling typeTree.toString and matching on the values of the Strings (e.g. "String" or "Int")?


回答1:


You can use TypeTree's tpe method to see the underlying type.



来源:https://stackoverflow.com/questions/23671379/proper-way-to-pattern-match-the-value-of-a-typetree-from-a-valdef-in-scala-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!