Now, in case of really long test files, traversing the whole PSI file at each edit, to check each assertion can be expensive, so what I have in mind is to:
- check the location of the caret in the current editor,
- if it is located at a string literal, it probably means that the last edit happened on (or around) a string literal. If it wasn't a string literal edited, LocalInspectionTool#buildVisitor() would return an empty visitor. This aims to lessen the number of times the PSI file structure is traversed, because the logic would run only when the edit potentially happened at a location we care about.
The questions I have:
- Is it a good approach to involve caret position checking during an inspection execution in general, and also given that file editors are available from EDT with IW lock only (see com.intellij.openapi.application.impl.ApplicationImpl#assertIsDispatchThread())?
- Regardless it's a good approach or not, do you think it would provide an at least somewhat significant performance gain?
- Do you see any alternate ways/methods with what such an inspection could be optimized?
Or maybe I'm just overthinking it?! :)