void (PsiFile file, final HashSet<String> seenNames) { file.accept(new PyRecursiveElementVisitor() { @Override public void visitPyFunction(@NotNull PyFunction node) { super.visitPyFunction(node); processLeafsNames(node, seenNames); } @Override public void visitPyClass(@NotNull PyClass node) { super.visitPyClass(node); processLeafsNames(node, seenNames); } @Override public void visitPyTargetExpression(@NotNull PyTargetExpression node) { super.visitPyTargetExpression(node); if (PsiTreeUtil.getParentOfType(node, ScopeOwner.class) instanceof PyFile) { processLeafsNames(node, seenNames); } } }); }