Reputation: 35
Since I want to generate Scala code from an annotated Scala class, I need to get the values from annotations of the class.
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 presentation compiler doesn't give me a value for tags
. I'm accessing 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 value of tags
?
Upvotes: 2
Views: 669
Reputation: 1894
The same question was recently asked on the scala-language mailing list. Here's the link to the thread.
Short answer: this is currently not possible. Implementing it requires a major amount of work, unfortunately. The reason is that the Scala compiler would need to have a complete Java parser. Currently, it can only parse declarations in Java source code, it skips all the "righthand sides" (method bodies, field definitions). See the thread.
Upvotes: 1