void (@NotNull ImportCandidateHolder item) { final Project project = myTarget.getProject(); final PyElementGenerator gen = PyElementGenerator.getInstance(project); final PsiFileSystemItem filesystemAnchor = ObjectUtils.chooseNotNull(as(item.getImportable(), PsiFileSystemItem.class), item.getFile()); if (filesystemAnchor == null) { return; } AddImportHelper.ImportPriority priority = AddImportHelper.getImportPriority(myTarget, filesystemAnchor); PsiFile file = myTarget.getContainingFile(); InjectedLanguageManager manager = InjectedLanguageManager.getInstance(project); if (manager.isInjectedFragment(file)) { file = manager.getTopLevelFile(myTarget); } // A root-level module or package cannot be imported with a "from" import. if (PyUtil.isRoot(item.getFile())) { if (myImportLocally) { AddImportHelper.addLocalImportStatement(myTarget, item.getImportableName(), item.getAsName()); } else { AddImportHelper.addImportStatement(file, item.getImportableName(), item.getAsName(), priority, myTarget, myInsertBefore); } } else { final String qualifiedName = Objects.toString(item.getPath(), ""); if (myUseQualifiedImport) { String nameToImport = qualifiedName; if (item.getImportable() instanceof PsiFileSystemItem) { nameToImport += "." + item.getImportableName(); } if (myImportLocally) { AddImportHelper.addLocalImportStatement(myTarget, nameToImport, item.getAsName()); } else { AddImportHelper.addImportStatement(file, nameToImport, item.getAsName(), priority, myTarget, myInsertBefore); } if (item.getAsName() == null) { myTarget.replace(gen.createExpressionFromText(LanguageLevel.forElement(myTarget), qualifiedName + "." + myName)); } } else { if (myImportLocally) { AddImportHelper.addLocalFromImportStatement(myTarget, qualifiedName, item.getImportableName(), item.getAsName()); } else { // "Update" scenario takes place inside injected fragments, for normal AST addToExistingImport() will be used instead AddImportHelper.addOrUpdateFromImportStatement( file, qualifiedName, item.getImportableName(), item.getAsName(), priority, myTarget, myInsertBefore); } } } }