import com.intellij.psi.util.QualifiedName; //导入方法依赖的package包/类
private static void addAutoImportFix(PyElement node, PsiReference reference, List actions) {
final PsiFile file = InjectedLanguageManager.getInstance(node.getProject()).getTopLevelFile(node);
if (!(file instanceof PyFile)) return;
AutoImportQuickFix importFix = PythonReferenceImporter.proposeImportFix(node, reference);
if (importFix != null) {
if (!suppressHintForAutoImport(node, importFix) && PyCodeInsightSettings.getInstance().SHOW_IMPORT_POPUP) {
final AutoImportHintAction autoImportHintAction = new AutoImportHintAction(importFix);
actions.add(autoImportHintAction);
}
else {
actions.add(importFix);
}
if (ScopeUtil.getScopeOwner(node) instanceof PyFunction) {
actions.add(importFix.forLocalImport());
}
}
else {
final String refName = (node instanceof PyQualifiedExpression) ? ((PyQualifiedExpression)node).getReferencedName() : node.getText();
if (refName == null) return;
final QualifiedName qname = QualifiedName.fromDottedString(refName);
final List components = qname.getComponents();
if (!components.isEmpty()) {
final String packageName = components.get(0);
final Module module = ModuleUtilCore.findModuleForPsiElement(node);
if (PyPIPackageUtil.INSTANCE.isInPyPI(packageName) && PythonSdkType.findPythonSdk(module) != null) {
actions.add(new PyPackageRequirementsInspection.InstallAndImportQuickFix(packageName, packageName, node));
}
else {
final String packageAlias = PyPackageAliasesProvider.commonImportAliases.get(packageName);
if (packageAlias != null && PyPIPackageUtil.INSTANCE.isInPyPI(packageName) && PythonSdkType.findPythonSdk(module) != null) {
actions.add(new PyPackageRequirementsInspection.InstallAndImportQuickFix(packageAlias, packageName, node));
}
}
}
}
}