I am trying to get into IntellIJ IDEA plugin development and running into a few problems, so naturally, this is my first post here. I hope at some point I'll be able to answer some questions, too!
On a high level, I am attempting to build a plugin that analyses your Java source code as you are writing it and suggests high-level refactorings based on "code smells".
So far, I have not come very far. I'm planning to perform most of my analysis on an AST of the java code and am therefore working with the PSITree.
To detect updates of the code I am currently using a PsiTreeChangeAdapter.
Naturally, I am getting a large number of events through and all seem fairly generic.
- Are there already ways to traverse the tree based on the events? Do I have to traverse the entire tree for a file for every change?
- Is there an easy way to look only at the code that actually changed? For instance, if a user adds to a method, is there a way to directly find that method and only look at the subtree corresponding to this method?
- Are there any more high-level APIs available for Java in particular that I am not aware of?
- Is traversing the PSITree to analyse the code the recommended method? Is there another representation that I should focus on?
- Is it thread-safe to traverse the tree, i.e. what happens if tree traversal has not finished but the user has changed the code again?
After my analysis, I would also like to perform some refactorings based on the findings. I found references to extensions that I could use. Is there any documentation available for what APIs are available for me to use?
Finally, the above questions probably make it rather obvious that I have not yet found a suitable example or documentation. Could you point me to any you know of, please?
Thank you so much in advance,