【问题标题】:Finding type signatures of all non-synthetic methods/functions in Scala在 Scala 中查找所有非综合方法/函数的类型签名
【发布时间】:2015-02-03 04:27:57
【问题描述】:

我正在尝试找到一种方法来获取 Scala 编译器的符号表 (?) 并将所有类型信息转储到特定 SBT 项目中的方法/函数中。我目前的方向是编译器插件,在typer 阶段之后立即连接到它。

四处闲逛,我正在查看根镜像并检查它的 info.decls 字段,类似于:

def newPhase(prev: Phase): Phase =
  new StdPhase(prev) {
    def apply(unit: CompilationUnit): Unit = {
      val decls = global.RootClass.info.decls
      val scalaz = decls.find(_.toString contains "scalaz")
      println(scalaz.get.info.decls.filter(x => !x.hasMeaninglessName))

它会转储很多东西,但是.. 我仍然会得到很多奇怪的输出,比如class anonfun$reduceUnordered$1 extends ;

想知道我是否朝着正确的方向前进,如果是这样,我应该更多地关注只是获取项目中方法的类型签名吗?

【问题讨论】:

    标签: scala scala-macros scalac scala-compiler scala-reflect


    【解决方案1】:

    你肯定走对了方向。您可以在https://github.com/CANVE/extractor 中看到完整的解决方案。正如您所展示的,某些符号是“合成的”,例如在源代码中使用了匿名函数的情况。因此,您可能希望从提取的任何“数据转储”中抽象出多少这些符号,取决于您希望完成的具体任务。

    【讨论】:

      猜你喜欢
      • 2013-02-04
      • 1970-01-01
      • 2014-12-03
      • 2021-05-12
      • 1970-01-01
      • 2013-03-14
      • 2011-07-22
      • 2021-03-11
      • 2023-03-20
      相关资源
      最近更新 更多