void () { @Language("JAVA") String text = """ class LQF { int f; public void me() { //<caret> } }"""; configureByText(JavaFileType.INSTANCE, text); List<PsiElement> visitedElements = Collections.synchronizedList(new ArrayList<>()); class MyVisitor extends PsiElementVisitor { @Override public void visitElement(@NotNull PsiElement element) { visitedElements.add(element); } } LocalInspectionTool tool = new MyFegnaInspection() { @NotNull @Override public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new MyVisitor(); } }; disposeOnTearDown(() -> disableInspectionTool(tool.getShortName())); enableInspectionTool(tool); assertEmpty(highlightErrors()); List<PsiElement> allPsi = CollectHighlightsUtil.getElementsInRange(myFile, 0, myFile.getTextLength()); assertEquals(new HashSet<>(allPsi), new HashSet<>(visitedElements)); // inside code block modification visitedElements.clear(); backspace(); backspace(); assertEmpty(highlightErrors()); PsiMethod method = ((PsiJavaFile)myFile).getClasses()[0].getMethods()[0]; List<PsiElement> methodAndParents = CollectHighlightsUtil.getElementsInRange(myFile, method.getTextRange().getStartOffset(), method.getTextRange().getEndOffset(), true); assertEquals(new HashSet<>(methodAndParents), new HashSet<>(visitedElements)); }