Scala ASTs & Annotations

瀏覽次數:65 次
跳到第一則未讀訊息

Matthias Langer

未讀,
2015年1月11日 凌晨4:09:012015/1/11
收件者:scala-i...@googlegroups.com
Hello everybody,

I'm already discussing this on scala-ide-dev, but I thought that it might be helpful to bring this issue to broader attention: I'm currently working on #1001793 (a minimal example can be found here), which is about classes used in expressions like "@AnAnnotation(classOf[Foo]) not being handled properly. The problem is, that for example "@AnAnnotation(classOf[Foo])" is represented by

Apply(
  Select(New(Ident(AnAnnotation)), termNames.CONSTRUCTOR), List(
    AssignOrNamedArg(
      Ident(TermName("value")), TypeApply(
        Ident(TermName("classOf")), List(Ident(TypeName("Foo")))
      )
    )
  )
)

The
"Ident(TypeName("Foo"))" has neither a tpe nor a symbol, and so it is not handled by the traverser in scala.tools.refactoring.analysis.CompilationUnitDependencies, that would otherwise use these properties to build a "fakeSelectTree". So my questions are:

1) Why are tpe and symbol not set in this case?
2) How can I obtain these properties?

Thank you very much,
Matthias

Eugene Burmako

未讀,
2015年1月11日 凌晨4:34:372015/1/11
收件者:<scala-internals@googlegroups.com>
Iirc typedAnnotation does some unconventional tree manipulation to transform a Tree that represents an annotation into an Annotation. 

I wouldn't be surprised if the typechecker doesn't attribute the original tree, because originals (originals of TypeTrees and originals of Annotations alike) typically receive subpar treatment - they aren't immediately used by anyone, so they are considered second-class (at least, that's what I inferred from working with the code).

In scalahost [1], I obtain the corresponding instance of Annotation by inspecting `memberDef.symbol.annotation` and then correlate the original tree and the annotation to fill in the blanks. That's quite a hack, but I don't know of a better strategy.


--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthias Langer

未讀,
2015年1月12日 下午5:21:312015/1/12
收件者:scala-i...@googlegroups.com
Thanks a lot for your comment; I'll look at this at the coming weekend!

Matthias
回覆所有人
回覆作者
轉寄
0 則新訊息