private void doIt(final ImportCandidateHolder item) { PyImportElement src = item.getImportElement(); if (src != null) { addToExistingImport(src); } else { // no existing import, add it then use it addImportStatement(item); } }
/** * Alters either target (by qualifying a name) or source (by explicitly importing the name). * * @return true if action succeeded */ public boolean execute() { // check if the tree is sane PsiDocumentManager.getInstance(myTarget.getProject()).commitAllDocuments(); if (!myTarget.isValid()) return false; if ((myTarget instanceof PyQualifiedExpression) && ((((PyQualifiedExpression) myTarget).isQualified()))) return false; // we cannot be qualified for (ImportCandidateHolder item : mySources) { if (!item.getImportable().isValid()) return false; if (!item.getFile().isValid()) return false; if (item.getImportElement() != null && !item.getImportElement().isValid()) return false; } if (mySources.isEmpty()) { return false; } // act if (mySources.size() > 1) { selectSourceAndDo(); } else doWriteAction(mySources.get(0)); return true; }