PsiFile () { PsiFile existingImportFile = null; // if there's a matching existing import, this is the file it imports PsiFile file = myNode.getContainingFile(); if (file instanceof PyFile pyFile) { for (PyImportElement importElement : pyFile.getImportTargets()) { existingImportFile = addImportViaElement(existingImportFile, importElement, importElement.resolve()); } existingImportFile = addCandidatesViaFromImports(existingImportFile, pyFile); } return existingImportFile; }