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

StackOverflow https://stackoverflow.com/questions/23671379

  •  23-07-2023
  •  | 
  •  

문제

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")?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top