void (UsageInfo @NotNull [] usages) { final List<String> newParameters = collectNewParameterNames(); assert ApplicationManager.getApplication().isWriteAccessAllowed(); final PyFile targetFile = PyClassRefactoringUtil.getOrCreateFile(myDestinationPath, myProject); if (targetFile.findTopLevelFunction(myFunction.getName()) != null) { throw new IncorrectOperationException( PyBundle.message("refactoring.move.error.destination.file.contains.function", myFunction.getName())); } if (importsRequired(usages, targetFile)) { PyMoveRefactoringUtil.checkValidImportableFile(targetFile, targetFile.getVirtualFile()); } final PsiElement position = PyMoveRefactoringUtil.findLowestPossibleTopLevelInsertionPosition(Arrays.asList(usages), targetFile); // We should update usages before we generate and insert new function, because we have to update its usages inside // (e.g. recursive calls) it first updateUsages(newParameters, usages); final PyFunction newFunction = insertFunction(createNewFunction(newParameters), targetFile, position); myFunction.delete(); updateImports(newFunction, usages); }