Is there an easy way to get class/field/method using specific annotations?
Answered
I have an annotation: @DeepLock(name = '')
I want to find all class/field/methods using it, and get the name value inside the annotation.
Please sign in to leave a comment.
Like the code above, I need to get class FatherController and method speakWhat()
Hi,
Check:
com.intellij.psi.search.searches.AnnotatedElementsSearch
com.intellij.psi.search.searches.AnnotatedMembersSearch
You should find the annotation PsiClass and pass it to the search method. Example:
You don't need this annotation to be a part of your project. It should be accessible in the project using the plugin.
Edit: Please do not delete posts after sending them 😉
Deleted message:
Thank you very much!❤️❤️❤️
I've complety solved the problem!
Karol Lewandowski
I met another problem that the searching result lost some results:
I have two class(One is FatherController).
FatherController.java
Another is TestController:
TestController.java
However, I use the code below:
The output is missing some results, where the annotation for TestController is totally missed.
Total deepLock number: 2
Then classes:1
Plus: I copy a same class (rename TestController to SonController). While TestController cannot be found, SonController can. How?
Hi,
It's unclear what the reason is.
Is the class that is not found in the project scope? Maybe indexes are broken/not up-to-date (try to clear them with File | Invalidate Caches... and see if the class is found after IDE restart)?