Get field for annotation

Hi there,

I'm currently working on an IntelliJ inspection that registers errors on certain annotations (placed at fields in a class). When this annotation is used on a field that has the wrong type, I mark the annotation as ' in error'. So far, this all works great.

However, I'm currently working on a quick-fix for my 'error'. The quick-fix should change the type of the field to the correct value. What I cannot find though is how to get a reference to this field when my problem description element is the PsiAnnotation which I marked.

Can someone tell me how I can get a reference to this field?

Thanks!
Martijn

2 comments

Hello Martijn,

PsiTreeUtil.getParentOfType(annotation, PsiField.class)

I'm currently working on an IntelliJ inspection that registers errors
on certain annotations (placed at fields in a class). When this
annotation is used on a field that has the wrong type, I mark the
annotation as ' in error'. So far, this all works great.

However, I'm currently working on a quick-fix for my 'error'. The
quick-fix should change the type of the field to the correct value.
What I cannot find though is how to get a reference to this field when
my problem description element is the PsiAnnotation which I marked.

Can someone tell me how I can get a reference to this field?

Thanks!
Martijn
---
Original message URL:
http://devnet.jetbrains.net/message/5273223#5273223


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


0

That's it! Works like a charm!

Thanks Dmitry!

0

Please sign in to leave a comment.