How to get annotation values ​​from a Scala presentation compiler?

Since I want to generate Scala code from an annotated Scala class, I need to get values ​​from class annotations.

public @interface TestAnnotation { public String name(); public String description(); public String[] tags() default { "Test" }; } 
 @TestAnnotation(name = "TestName", description = "TestDescription") class MyClass 

My problem is that the Scala view compiler does not give me a value for tags . I access the values ​​with the following code:

 import tools.nsc.interactive.Global._ val ast = ... val ans = ast.symbol.annotations // which returns me a List of AnnotationInfo ans.head.assocs // returns: List((name, "TestName"), (description, "TestDescription")) 

So how can I get the default tags ?

+2
scala
source share
1 answer

This question has recently been asked on the scala-language mailing list. Here is a link to the stream.

Short answer: this is currently not possible. The implementation of this, unfortunately, requires a lot of work. The reason is that the Scala compiler must have a full Java parser. Currently, it can only analyze declarations in the Java source code; it skips all the "right sides" (method bodies, field definitions). See Section.

+1
source share

All Articles