Custom Rule: Checking package visible variable/method usage

I’ve read the UnusedPrivateMethodCheck source code and I want to extend this class. Instead of checking only private method, what I want to do is checking package visible method as well.

So my strategy is:

  1. Visit compilationUnitTree and list up all package visible method and store it in list.
  2. Re-visit the all compilation file and check if method is called.

My questions:

  1. How can we revisit compilation unit?
  2. How to pass the list on step #1 when we revisit the compilation unit?
  3. What library can I use to check my implementation?

Hello @sopiana,

Unfortunately, what you try to achieve is not possible with the current semantic engine of SonarJava. Each file is visited only once, and CompiliationUnitTrees are not stored from one file to another. Consequently, from one symbol there is no reference to another file.

Now, if you try to store the CompilationUnitTree in the implementation of your rule, there is a huge chance to explode in term of memory.