Best way to analyze part of code, with working references?



i am writing a plugin, where the user is selecting some code (within a method for example) and i run some analyzer on top of the selected code.

What iam currently doing is creating a codeblock from the selected text and then i run some walker over it (because the selected text could be over multiple expressions)

The problem i have is that references going outside this textblock are obv. not correctly resolved, so currently i try to search for the "right" references in the main psi file. this is slow and taking a long time to program, 

I wonder if its possible to take a psi file, and let the JavaRecursiveElementVisitor only run over a small portion (via offsets for example) of a main psi file

1 comment


If you know the offsets to handle, you can collect them and implement visiting methods to return if the visited element is not in the range. You can also collect elements that should be analyzed and run the visitor on them, not on the entire file.

Or I'm missing something?


Please sign in to leave a comment.