Tracking annotations

Answered

Hello, friends!

I have custom library that provides some annotation. The question is what do I have to implement (or extend?) to track if this annotation was added on field/method/etc dynamically?

My latest idea was to implement VirtualFileManagerListener, but I'm not sure..

Please guide me in the right direction. Thanks in advance :)

6 comments
Comment actions Permalink

Please define "track". There are various utility methods to find all methods/fields/... using a specific given annotation, see com.intellij.codeInsight.AnnotationUtil as starting point.

0
Comment actions Permalink

Thanks for responding, Yann. Yes, there are utility methods to find annotated methods or fields. Such processing I do in my custom postStartupActivity. But user can add annotation on field or method while he's working on his project. What I want is "to catch" the moment when my annotation appears on some field to process it properly.

0
Comment actions Permalink

This is not trivial to implement (correctly). Why do you need this information right at this moment? What kind of activity/functionality do you build around this annotation's presence?

0
Comment actions Permalink

Oh. I see.

I'm trying to create plugin for my groovy library. Library generates getter method with Optional as a return type by annotation using Groovy and AST transformations. Idea can't "understand" that method not exists for no, but it will be generated.

I understand that there is a source code of the Lombok plugin. But working from scratch is perhaps more valuable..

0
Comment actions Permalink

It sounds like com.intellij.psi.augment.PsiAugmentProvider extension point would be your choice, where you can add additional virtual ("fake") elements to be resolved/treated as regular code. See https://plugins.jetbrains.com/intellij-platform-explorer?extensions=com.intellij.lang.psiAugmentProvider for usages in plugins.

 

1
Comment actions Permalink

Thanks a lot. I think this is exactly what I need :)

0

Please sign in to leave a comment.