void (@NotNull final PsiElement element, @NotNull final HashSet<String> seenNames) { final int endOffset = element.getTextRange().getEndOffset(); // collect leafs (spell checker inspection works with leafs) final List<PsiElement> leafs = new ArrayList<>(); if (element.getChildren().length == 0) { // if no children - it is a leaf! leafs.add(element); } else { // else collect leafs under given element PsiElement currentLeaf = PsiTreeUtil.firstChild(element); while (currentLeaf != null && currentLeaf.getTextRange().getEndOffset() <= endOffset) { leafs.add(currentLeaf); currentLeaf = PsiTreeUtil.nextLeaf(currentLeaf); } } for (PsiElement leaf : leafs) { processLeafsNames(leaf, seenNames); } }