Get annotation attribute value as Java string
I have an annotation:
@Doc(desc = "Foo.\n" +
"Bar.");
I call
getModifierList().findAnnotation("com.mycompany.Doc").findAttributeValue("desc").getText() but it returns everything literally including the quotes (i.e. ""Foo.\n" + "Bar.""). How do I get the content of desc as a Java string (e.g. "Foo.\nBar.")?
Please sign in to leave a comment.
Hello Thomas,
((PsiLiteralExpression) findAttributeValue()).getValue()
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Wow that's cool, thanks Dmitry!
Anyway that doesn't work for arrays (e.g. @Doc(except = {"foo", "bar"})). How do I get such value?
Hello Thomas,
Have you actually made any attempt to figure the answer by yourself? It's
not hard at all. Hint: look at other classes that implement PsiAnnotationMemberValue.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hi Dmitry, I can't pull the source (http://www.jetbrains.org/pages/viewpage.action?pageId=983225), maybe company firewall, and I depend on Google to look for documentation. Basically I'm doing detective work when developing the plugin :)
Hi Thomas,
Community Edition is also replicated to github that provides http access - https://github.com/JetBrains/intellij-community
Denis