void (@NotNull final PsiElement element, final String @NotNull ... namesToSkip) { PsiFile containingFile = element.getContainingFile(); if (containingFile instanceof PyFile) { Set<FutureFeature> fromFutureImports = collectFromFutureImports((PyFile)containingFile); element.putCopyableUserData(ENCODED_FROM_FUTURE_IMPORTS, fromFutureImports); } element.accept(new PyRecursiveElementVisitor() { @Override public void visitPyReferenceExpression(@NotNull PyReferenceExpression node) { super.visitPyReferenceExpression(node); if (PsiTreeUtil.getParentOfType(node, PyImportStatementBase.class) != null) { return; } final PyImportedNameDefiner importElement = getImportElement(node); if (importElement != null && PsiTreeUtil.isAncestor(element, importElement, false)) { return; } if (!ArrayUtil.contains(node.getText(), namesToSkip)) { //Do not remember name if it should be skipped rememberReference(node, element); } } @Override public void visitComment(@NotNull PsiComment comment) { super.visitComment(comment); if (comment instanceof PsiLanguageInjectionHost) { rememberInjectionReferences((PsiLanguageInjectionHost)comment, element, namesToSkip); } } @Override public void visitPyStringLiteralExpression(@NotNull PyStringLiteralExpression expression) { super.visitPyStringLiteralExpression(expression); rememberInjectionReferences(expression, element, namesToSkip); } }); }