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.")?
5 comments

Hello Thomas,

((PsiLiteralExpression) findAttributeValue()).getValue()

I have an annotation:

@Doc(desc = "Foo.\n" +
>
> "Bar.");
>

I call
getModifierList().findAnnotation("com.mycompany.Doc").findAttributeVal
ue("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.")?

---
Original message URL:
http://devnet.jetbrains.net/message/5389586#5389586


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

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?

0

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.

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?


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

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 :)

0

Hi Thomas,

Community Edition is also replicated to github that provides http access - https://github.com/JetBrains/intellij-community

Denis

0

Please sign in to leave a comment.